@akasecurity/ai-tc-claude-code 0.9.10 → 0.9.11
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/package.json +5 -5
- package/scripts/apply-suppressions.js +622 -430
- package/scripts/backfill.js +732 -504
- package/scripts/filescan.js +726 -496
- package/scripts/firstrun.js +772 -516
- package/scripts/history-sync.js +611 -418
- package/scripts/intro.js +240 -90
- package/scripts/message-display.js +604 -412
- package/scripts/onboard.js +601 -408
- package/scripts/post-model-switch.js +258 -110
- package/scripts/post-tool-use.js +880 -493
- package/scripts/pre-model-switch.js +691 -469
- package/scripts/pre-tool-use.js +728 -498
- package/scripts/query.js +845 -526
- package/scripts/reconcile.js +716 -494
- package/scripts/remediate.js +728 -498
- package/scripts/scan-worker.js +153 -58
- package/scripts/session-start.js +783 -558
- package/scripts/start-light.js +238 -88
- package/scripts/statusline.js +697 -475
- package/scripts/stop.js +490 -121
- package/scripts/sync.js +722 -494
- package/scripts/user-prompt-submit.js +725 -495
|
@@ -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 join14 } from "path";
|
|
497
497
|
|
|
498
498
|
// ../../packages/persistence/src/attached-derived.ts
|
|
499
499
|
import { rmSync } from "fs";
|
|
@@ -20741,13 +20741,11 @@ var FindingGroup = external_exports.object({
|
|
|
20741
20741
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20742
20742
|
instances: external_exports.array(FindingInstance),
|
|
20743
20743
|
// Derived from instances' statuses with open-dominates precedence (see
|
|
20744
|
-
//
|
|
20744
|
+
// foldGroupStatus). Undefined only when no instance carries a status.
|
|
20745
20745
|
status: FindingStatus.optional(),
|
|
20746
|
-
// The distinct people across the WHOLE group, not just the
|
|
20747
|
-
//
|
|
20748
|
-
//
|
|
20749
|
-
// instance carries a user, or when the store supplied whole-group folds
|
|
20750
|
-
// without one.
|
|
20746
|
+
// The distinct people across the WHOLE group, not just the instances
|
|
20747
|
+
// carried here. Undefined when no instance carries a user, or when the
|
|
20748
|
+
// store supplied whole-group folds without one.
|
|
20751
20749
|
users: external_exports.array(FindingUser).optional()
|
|
20752
20750
|
}).meta({ id: "FindingGroup" });
|
|
20753
20751
|
var FindingStats = external_exports.object({
|
|
@@ -20776,21 +20774,31 @@ var FindingFacets = external_exports.object({
|
|
|
20776
20774
|
// counted under no value.
|
|
20777
20775
|
status: external_exports.array(FindingFacetItem),
|
|
20778
20776
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20779
|
-
// reads, which can filter by it; the
|
|
20777
|
+
// reads, which can filter by it; the type-level read omits the dimension
|
|
20780
20778
|
// because a group spans tools.
|
|
20781
20779
|
tool: external_exports.array(FindingFacetItem).optional()
|
|
20782
20780
|
}).meta({ id: "FindingFacets" });
|
|
20783
|
-
var
|
|
20784
|
-
|
|
20781
|
+
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20782
|
+
id: "FindingTypeSummary"
|
|
20783
|
+
});
|
|
20784
|
+
var DEFAULT_FINDING_TYPES_LIMIT = 50;
|
|
20785
|
+
var MAX_FINDING_TYPES_LIMIT = 100;
|
|
20786
|
+
var ListFindingTypesQuery = external_exports.object({
|
|
20785
20787
|
// NOTE: severity filters by Severity (critical/high/medium/low), not by
|
|
20786
|
-
// FindingAction.
|
|
20788
|
+
// FindingAction. It narrows TYPES: a type's severity is the one its newest
|
|
20789
|
+
// firing version carries, and this list pages types.
|
|
20790
|
+
//
|
|
20791
|
+
// That is NOT a claim the findings of a type share it. A rule can hold several
|
|
20792
|
+
// definition versions at different severities, so a type kept by this filter
|
|
20793
|
+
// can hold findings that individually do not match — see totals.findings on
|
|
20794
|
+
// ListFindingTypesResponse, which counts them all.
|
|
20787
20795
|
severity: external_exports.array(Severity).optional(),
|
|
20788
20796
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20789
20797
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20790
20798
|
action: external_exports.array(FindingAction).optional(),
|
|
20791
|
-
// Matches a
|
|
20792
|
-
// individual
|
|
20793
|
-
//
|
|
20799
|
+
// Matches a type's DERIVED status (see FindingGroup.status), not its
|
|
20800
|
+
// individual findings' — so a filtered row's status always reads one of the
|
|
20801
|
+
// requested values.
|
|
20794
20802
|
status: external_exports.array(FindingStatus).optional(),
|
|
20795
20803
|
q: external_exports.string().optional(),
|
|
20796
20804
|
// Scope to findings whose event carries this session id (the Activity page's
|
|
@@ -20800,23 +20808,37 @@ var ListGroupedFindingsQuery = external_exports.object({
|
|
|
20800
20808
|
// from a time-scoped page (Activity's range) can carry that scope. Absent
|
|
20801
20809
|
// means all time — this list has no default window.
|
|
20802
20810
|
from: external_exports.iso.datetime().optional(),
|
|
20803
|
-
// A
|
|
20804
|
-
//
|
|
20805
|
-
//
|
|
20806
|
-
//
|
|
20807
|
-
//
|
|
20811
|
+
// A RULE id that must appear in the page even when the cursor has already
|
|
20812
|
+
// advanced past its sort position. This is what keeps the selected type
|
|
20813
|
+
// visible in the list once it paginates: the target is appended out of sort
|
|
20814
|
+
// order rather than scanned forward for. Never affects totals, facets or the
|
|
20815
|
+
// cursor. Unlike the grouped read this replaces, it names a rule only — an
|
|
20816
|
+
// instance id is resolved by `findingInstance`, which is a primary-key seek
|
|
20817
|
+
// and so is not bounded by what any page happens to hold.
|
|
20808
20818
|
includeId: external_exports.string().optional(),
|
|
20809
|
-
|
|
20810
|
-
limit: external_exports.coerce.number().int().min(1).max(100).optional(),
|
|
20819
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
|
|
20811
20820
|
cursor: external_exports.string().optional()
|
|
20812
20821
|
});
|
|
20813
|
-
var
|
|
20822
|
+
var ListFindingTypesResponse = external_exports.object({
|
|
20814
20823
|
totals: external_exports.object({
|
|
20824
|
+
// Findings belonging to the matching TYPES — not findings that each match
|
|
20825
|
+
// the filters. The filters here select types, so a type that survives
|
|
20826
|
+
// contributes its whole instanceCount.
|
|
20827
|
+
//
|
|
20828
|
+
// `status` is the one exception, narrowed per finding via
|
|
20829
|
+
// countInstancesByStatus. `severity`, `provider` and `action` are not, so
|
|
20830
|
+
// this can exceed what the instance read reports for the same filters: a
|
|
20831
|
+
// rule whose severity moved between versions is kept on its newest and
|
|
20832
|
+
// still counts its older findings. Narrowing the other three needs
|
|
20833
|
+
// per-dimension counts the aggregate does not carry today.
|
|
20815
20834
|
findings: external_exports.number().int().nonnegative(),
|
|
20816
|
-
|
|
20835
|
+
// Counts TYPES, which is the unit this read pages. The instance read's
|
|
20836
|
+
// own totals count findings; the two deliberately answer different
|
|
20837
|
+
// questions and are never summed.
|
|
20838
|
+
types: external_exports.number().int().nonnegative()
|
|
20817
20839
|
}),
|
|
20818
20840
|
facets: FindingFacets,
|
|
20819
|
-
items: external_exports.array(
|
|
20841
|
+
items: external_exports.array(FindingTypeSummary),
|
|
20820
20842
|
nextCursor: external_exports.string().nullable(),
|
|
20821
20843
|
// Present only on session-scoped queries (`sessionId` set): per ruleId, how
|
|
20822
20844
|
// many times that rule fired in the session's persisted transcript. Findings
|
|
@@ -20824,7 +20846,7 @@ var ListGroupedFindingsResponse = external_exports.object({
|
|
|
20824
20846
|
// every firing, so the two numbers legitimately differ — this map lets a
|
|
20825
20847
|
// session-scoped view show both.
|
|
20826
20848
|
sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
|
|
20827
|
-
}).meta({ id: "
|
|
20849
|
+
}).meta({ id: "ListFindingTypesResponse" });
|
|
20828
20850
|
var ApplyFindingActionRequest = external_exports.object({
|
|
20829
20851
|
// 'quarantined' is system-assigned (see FindingAction) — clients may not set
|
|
20830
20852
|
// it, so it is excluded from the request contract. The mapping helper
|
|
@@ -20854,12 +20876,13 @@ var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
|
20854
20876
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
20855
20877
|
var ListFindingInstancesQuery = external_exports.object({
|
|
20856
20878
|
severity: external_exports.array(Severity).optional(),
|
|
20857
|
-
// Rule ids, the same vocabulary the
|
|
20879
|
+
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
20880
|
+
// ONE of them is how the master/detail view scopes its right-hand panel.
|
|
20858
20881
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20859
20882
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20860
20883
|
action: external_exports.array(FindingAction).optional(),
|
|
20861
20884
|
// Matches each instance's OWN derived status (deriveFindingStatus), unlike
|
|
20862
|
-
// the
|
|
20885
|
+
// the types query's type-level fold.
|
|
20863
20886
|
status: external_exports.array(FindingStatus).optional(),
|
|
20864
20887
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20865
20888
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
@@ -20876,37 +20899,47 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20876
20899
|
});
|
|
20877
20900
|
var ListFindingInstancesResponse = external_exports.object({
|
|
20878
20901
|
// Instances matching the filters across the whole scope, not just this
|
|
20879
|
-
// page — cursor-independent, like the
|
|
20902
|
+
// page — cursor-independent, like the types list's totals.
|
|
20880
20903
|
totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
|
|
20881
|
-
// Counts in INSTANCES here, where the
|
|
20904
|
+
// Counts in INSTANCES here, where the types response counts types. Each
|
|
20882
20905
|
// dimension still excludes its own filter.
|
|
20883
20906
|
facets: FindingFacets,
|
|
20884
20907
|
items: external_exports.array(FindingInstanceDetail),
|
|
20885
20908
|
nextCursor: external_exports.string().nullable()
|
|
20886
20909
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20887
|
-
var
|
|
20888
|
-
//
|
|
20889
|
-
//
|
|
20890
|
-
|
|
20891
|
-
|
|
20892
|
-
|
|
20893
|
-
|
|
20894
|
-
// Folded from the instances' derived statuses with the same
|
|
20895
|
-
// open-dominates precedence a group uses.
|
|
20896
|
-
status: FindingStatus.optional(),
|
|
20897
|
-
// Distinct rules seen at this location, capped — the row shows them as
|
|
20898
|
-
// chips, and the count is what conveys scale.
|
|
20899
|
-
ruleIds: external_exports.array(external_exports.string())
|
|
20900
|
-
}).meta({ id: "FindingLocationFile" });
|
|
20901
|
-
var FindingLocationRepo = external_exports.object({
|
|
20910
|
+
var FindingLocationSummary = external_exports.object({
|
|
20911
|
+
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20912
|
+
// because a location's identity is two values and a URL param carries one:
|
|
20913
|
+
// `?loc=` names a location the way `?rule=` names a type. Only ever compared
|
|
20914
|
+
// for EQUALITY — the page's selection check, this read's `includeId`, the
|
|
20915
|
+
// client's page dedupe — never decoded, and never a sort key.
|
|
20916
|
+
id: external_exports.string(),
|
|
20902
20917
|
/** Empty when the instances carried no repo attribute. */
|
|
20903
20918
|
repo: external_exports.string(),
|
|
20919
|
+
// Empty when the instances carried no file path (a prompt, or a tool call
|
|
20920
|
+
// with no file attribution). Both halves empty is a real location — usually
|
|
20921
|
+
// the largest one in a store — and is selectable like any other.
|
|
20922
|
+
file: external_exports.string(),
|
|
20904
20923
|
instanceCount: external_exports.number().int().nonnegative(),
|
|
20924
|
+
// The WORST severity present, not the first row's. It is this list's primary
|
|
20925
|
+
// sort key, so it is also what explains why a row is where it is, and it is
|
|
20926
|
+
// how a reader decides what to open without opening everything.
|
|
20905
20927
|
maxSeverity: Severity,
|
|
20906
20928
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20929
|
+
// Folded from the instances' derived statuses with the same open-dominates
|
|
20930
|
+
// precedence a group uses, so it answers "is anything left to do here" and
|
|
20931
|
+
// not much more: a location holding 1 open among 40 resolved reads like one
|
|
20932
|
+
// holding 40 open. That loss is accepted — the panel beside this list
|
|
20933
|
+
// carries each finding's own status, and instanceCount sits next to the
|
|
20934
|
+
// badge.
|
|
20907
20935
|
status: FindingStatus.optional(),
|
|
20908
|
-
|
|
20909
|
-
|
|
20936
|
+
// Every distinct rule seen at this location, UNCAPPED — so the length is a
|
|
20937
|
+
// tally rather than a sample and a row can say how many there are. Bounded
|
|
20938
|
+
// by the ruleset, not by the store. The view bounds what it DISPLAYS.
|
|
20939
|
+
ruleIds: external_exports.array(external_exports.string())
|
|
20940
|
+
}).meta({ id: "FindingLocationSummary" });
|
|
20941
|
+
var DEFAULT_FINDING_LOCATIONS_LIMIT = 50;
|
|
20942
|
+
var MAX_FINDING_LOCATIONS_LIMIT = 100;
|
|
20910
20943
|
var ListFindingLocationsQuery = external_exports.object({
|
|
20911
20944
|
severity: external_exports.array(Severity).optional(),
|
|
20912
20945
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
@@ -20919,18 +20952,42 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20919
20952
|
q: external_exports.string().optional(),
|
|
20920
20953
|
sessionId: external_exports.string().optional(),
|
|
20921
20954
|
from: external_exports.iso.datetime().optional(),
|
|
20922
|
-
|
|
20955
|
+
// A LOCATION id (see FindingLocationSummary.id) that must appear in the page
|
|
20956
|
+
// even when the cursor has already advanced past its sort position — the
|
|
20957
|
+
// counterpart of ListFindingTypesQuery.includeId, and needed far more often
|
|
20958
|
+
// here. Selecting a row pushes the URL, which re-renders the server and resets
|
|
20959
|
+
// the client's page cache to page 0; with distinct (repo, file) pairs running
|
|
20960
|
+
// into the thousands, a selection sitting off page 0 is the ordinary case
|
|
20961
|
+
// rather than a deep-link corner. Never affects totals, facets or the cursor.
|
|
20962
|
+
includeId: external_exports.string().optional(),
|
|
20963
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
|
|
20964
|
+
cursor: external_exports.string().optional()
|
|
20923
20965
|
});
|
|
20924
20966
|
var ListFindingLocationsResponse = external_exports.object({
|
|
20925
20967
|
totals: external_exports.object({
|
|
20968
|
+
// Findings matching the filters across the whole scope. Unlike the types
|
|
20969
|
+
// read's same-named field this needs no caveat: the filters here narrow
|
|
20970
|
+
// per finding, so this is the sum of every row's instanceCount.
|
|
20926
20971
|
findings: external_exports.number().int().nonnegative(),
|
|
20927
|
-
|
|
20928
|
-
|
|
20972
|
+
// Counts LOCATIONS, the unit this read pages — the number the paginator
|
|
20973
|
+
// states. The facets beside it count FINDINGS (see below); a surface
|
|
20974
|
+
// showing both says which is which.
|
|
20975
|
+
locations: external_exports.number().int().nonnegative()
|
|
20929
20976
|
}),
|
|
20930
|
-
|
|
20931
|
-
|
|
20932
|
-
|
|
20933
|
-
|
|
20977
|
+
// Counts in FINDINGS, where the types response counts types, each dimension
|
|
20978
|
+
// still excluding its own filter. Deliberately not locations: counting those
|
|
20979
|
+
// needs a set of location keys per dimension per value — memory tracking the
|
|
20980
|
+
// store times the vocabulary, in a read whose scan promises flat memory —
|
|
20981
|
+
// and the cheap per-location version is not an approximation but WRONG. A
|
|
20982
|
+
// location holding {claudecode, block} and {codex, warn} would survive
|
|
20983
|
+
// provider=claudecode AND action=warn, under which no single finding
|
|
20984
|
+
// matches, so the facet would contradict the instanceCount this whole view
|
|
20985
|
+
// rests on. Findings also keep the toolbar in the same unit as the page
|
|
20986
|
+
// tally and the panel it sits above.
|
|
20987
|
+
facets: FindingFacets,
|
|
20988
|
+
/** Sorted by max severity, then most recent, then (repo, file). */
|
|
20989
|
+
items: external_exports.array(FindingLocationSummary),
|
|
20990
|
+
nextCursor: external_exports.string().nullable()
|
|
20934
20991
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
20935
20992
|
|
|
20936
20993
|
// ../../packages/schema/src/zod/meta.ts
|
|
@@ -22098,6 +22155,14 @@ var ControlPlaneErrorBody = external_exports.object({
|
|
|
22098
22155
|
message: external_exports.string().optional()
|
|
22099
22156
|
}).optional()
|
|
22100
22157
|
});
|
|
22158
|
+
var RemoteFailureKind = external_exports.enum([
|
|
22159
|
+
"unauthorized",
|
|
22160
|
+
"forbidden",
|
|
22161
|
+
"route-absent",
|
|
22162
|
+
"invalid-request",
|
|
22163
|
+
"rejected",
|
|
22164
|
+
"unreachable"
|
|
22165
|
+
]);
|
|
22101
22166
|
var AttachDeviceRequest = external_exports.object({
|
|
22102
22167
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22103
22168
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22791,139 +22856,62 @@ function deriveFindingStatus(row) {
|
|
|
22791
22856
|
if (row.latestResolutionStatus === "dismissed") return "dismissed";
|
|
22792
22857
|
return "open";
|
|
22793
22858
|
}
|
|
22794
|
-
function distinctUsers(instances) {
|
|
22795
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22796
|
-
const users = [];
|
|
22797
|
-
for (const i of instances) {
|
|
22798
|
-
if (i.user === void 0 || seen.has(i.user.id)) continue;
|
|
22799
|
-
seen.add(i.user.id);
|
|
22800
|
-
users.push(i.user);
|
|
22801
|
-
}
|
|
22802
|
-
return users;
|
|
22803
|
-
}
|
|
22804
22859
|
function sortUsers(users) {
|
|
22805
22860
|
return [...users].sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
22806
22861
|
}
|
|
22807
|
-
function
|
|
22808
|
-
const overrides = opts.overrides;
|
|
22862
|
+
function buildFindingTypes(aggregates, opts = {}) {
|
|
22809
22863
|
const packNames = opts.packNames;
|
|
22810
|
-
const
|
|
22811
|
-
const
|
|
22812
|
-
|
|
22813
|
-
const
|
|
22814
|
-
|
|
22815
|
-
else byRuleId.set(row.ruleId, [row]);
|
|
22816
|
-
}
|
|
22817
|
-
const groups = [];
|
|
22818
|
-
for (const [ruleId, ruleRows] of byRuleId) {
|
|
22819
|
-
const instances = ruleRows.map((r) => {
|
|
22820
|
-
const effectiveDbAction = overrides?.get(r.id) ?? r.actionTaken;
|
|
22821
|
-
return {
|
|
22822
|
-
id: r.id,
|
|
22823
|
-
provider: toApiProvider(r.sourceTool),
|
|
22824
|
-
repo: r.repo,
|
|
22825
|
-
file: r.file,
|
|
22826
|
-
...r.toolName === void 0 ? {} : { toolName: r.toolName },
|
|
22827
|
-
...r.eventId === void 0 ? {} : { eventId: r.eventId },
|
|
22828
|
-
...r.sessionId === void 0 ? {} : { sessionId: r.sessionId },
|
|
22829
|
-
...r.user === void 0 ? {} : { user: r.user },
|
|
22830
|
-
action: toApiAction(effectiveDbAction),
|
|
22831
|
-
detectedAt: r.occurredAt,
|
|
22832
|
-
confidence: r.confidence,
|
|
22833
|
-
status: r.status
|
|
22834
|
-
};
|
|
22835
|
-
});
|
|
22836
|
-
const agg = aggregates?.get(ruleId);
|
|
22837
|
-
const users = agg ? sortUsers(agg.users ?? []) : distinctUsers(instances);
|
|
22838
|
-
const latestDetectedAt = agg?.latestDetectedAt ?? ruleRows.reduce(
|
|
22839
|
-
(max, r) => r.occurredAt > max ? r.occurredAt : max,
|
|
22840
|
-
ruleRows[0]?.occurredAt ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
22841
|
-
);
|
|
22842
|
-
const seenProviders = /* @__PURE__ */ new Set();
|
|
22843
|
-
const providers = (agg ? [...new Set(agg.sourceTools.map(toApiProvider))].sort() : instances.map((i) => i.provider)).filter((p) => {
|
|
22844
|
-
if (seenProviders.has(p)) return false;
|
|
22845
|
-
seenProviders.add(p);
|
|
22846
|
-
return true;
|
|
22847
|
-
});
|
|
22848
|
-
const actionSet = new Set(
|
|
22849
|
-
agg ? agg.actionsTaken.map(toApiAction) : instances.map((i) => i.action)
|
|
22850
|
-
);
|
|
22864
|
+
const types = [];
|
|
22865
|
+
for (const [ruleId, agg] of aggregates) {
|
|
22866
|
+
const users = sortUsers(agg.users ?? []);
|
|
22867
|
+
const providers = [...new Set(agg.sourceTools.map(toApiProvider))].sort();
|
|
22868
|
+
const actionSet = new Set(agg.actionsTaken.map(toApiAction));
|
|
22851
22869
|
const aggregateAction = actionSet.size === 1 ? [...actionSet][0] ?? null : null;
|
|
22852
|
-
const
|
|
22853
|
-
const
|
|
22854
|
-
id: ruleId,
|
|
22855
|
-
name: packNames?.get(ruleId) ?? null
|
|
22856
|
-
};
|
|
22857
|
-
const apiCategory = toApiCategory(ruleRows[0]?.category ?? "custom");
|
|
22858
|
-
const policy = { id: `category:${apiCategory}`, name: apiCategory };
|
|
22859
|
-
const match = {
|
|
22860
|
-
maskedValue: ruleRows[0]?.maskedMatch ?? "",
|
|
22861
|
-
contextPrefix: ""
|
|
22862
|
-
// empty (pending privacy review)
|
|
22863
|
-
};
|
|
22864
|
-
const status = foldGroupStatus(
|
|
22865
|
-
agg ? agg.statusInputs.map(deriveFindingStatus) : instances.map((i) => i.status)
|
|
22866
|
-
);
|
|
22867
|
-
const group = {
|
|
22870
|
+
const apiCategory = toApiCategory(agg.category ?? "custom");
|
|
22871
|
+
const type = {
|
|
22868
22872
|
id: ruleId,
|
|
22869
22873
|
category: apiCategory,
|
|
22870
22874
|
subtype: ruleId,
|
|
22871
22875
|
// human label comes with pack metadata later
|
|
22872
|
-
severity,
|
|
22873
|
-
|
|
22874
|
-
|
|
22875
|
-
|
|
22876
|
-
instanceCount: agg?.instanceCount ?? instances.length,
|
|
22876
|
+
severity: agg.severity ?? "low",
|
|
22877
|
+
detection: { id: ruleId, name: packNames?.get(ruleId) ?? null },
|
|
22878
|
+
policy: { id: `category:${apiCategory}`, name: apiCategory },
|
|
22879
|
+
instanceCount: agg.instanceCount,
|
|
22877
22880
|
providers,
|
|
22878
22881
|
aggregateAction,
|
|
22879
|
-
latestDetectedAt,
|
|
22880
|
-
|
|
22881
|
-
status,
|
|
22882
|
+
latestDetectedAt: agg.latestDetectedAt,
|
|
22883
|
+
status: foldGroupStatus(agg.statusInputs.map(deriveFindingStatus)),
|
|
22882
22884
|
...users.length > 0 ? { users } : {}
|
|
22883
22885
|
};
|
|
22884
|
-
|
|
22885
|
-
|
|
22886
|
-
|
|
22887
|
-
haystackCache.set(group, buildHaystack(group, agg.searchText));
|
|
22888
|
-
}
|
|
22886
|
+
actionsCache.set(type, [...actionSet]);
|
|
22887
|
+
if (agg.searchText !== void 0) {
|
|
22888
|
+
haystackCache.set(type, buildHaystack(type, agg.searchText));
|
|
22889
22889
|
}
|
|
22890
|
-
|
|
22890
|
+
types.push(type);
|
|
22891
22891
|
}
|
|
22892
|
-
return
|
|
22892
|
+
return types;
|
|
22893
22893
|
}
|
|
22894
22894
|
var haystackCache = /* @__PURE__ */ new WeakMap();
|
|
22895
|
-
function buildHaystack(
|
|
22895
|
+
function buildHaystack(t, extra) {
|
|
22896
22896
|
return [
|
|
22897
|
-
|
|
22898
|
-
|
|
22899
|
-
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
...g.instances.map((i) => i.repo),
|
|
22903
|
-
...g.instances.map((i) => i.file),
|
|
22904
|
-
...g.instances.map((i) => i.toolName ? `via ${i.toolName}` : ""),
|
|
22905
|
-
...g.instances.map((i) => i.id),
|
|
22906
|
-
// The people: the whole group's list when the store folded one, plus the
|
|
22907
|
-
// preview's own — the two overlap, and a haystack does not mind.
|
|
22908
|
-
...(g.users ?? []).map((u) => u.name),
|
|
22909
|
-
...g.instances.map((i) => i.user?.name ?? ""),
|
|
22897
|
+
t.subtype,
|
|
22898
|
+
t.category,
|
|
22899
|
+
t.policy.name,
|
|
22900
|
+
t.id,
|
|
22901
|
+
...(t.users ?? []).map((u) => u.name),
|
|
22910
22902
|
...extra === void 0 ? [] : [extra]
|
|
22911
22903
|
].join(" ").toLowerCase();
|
|
22912
22904
|
}
|
|
22913
|
-
function
|
|
22914
|
-
const cached2 = haystackCache.get(
|
|
22905
|
+
function typeHaystack(t) {
|
|
22906
|
+
const cached2 = haystackCache.get(t);
|
|
22915
22907
|
if (cached2 !== void 0) return cached2;
|
|
22916
|
-
const haystack = buildHaystack(
|
|
22917
|
-
haystackCache.set(
|
|
22908
|
+
const haystack = buildHaystack(t);
|
|
22909
|
+
haystackCache.set(t, haystack);
|
|
22918
22910
|
return haystack;
|
|
22919
22911
|
}
|
|
22920
22912
|
var actionsCache = /* @__PURE__ */ new WeakMap();
|
|
22921
|
-
function
|
|
22922
|
-
|
|
22923
|
-
if (cached2 !== void 0) return cached2;
|
|
22924
|
-
const actions = [...new Set(g.instances.map((i) => i.action))];
|
|
22925
|
-
actionsCache.set(g, actions);
|
|
22926
|
-
return actions;
|
|
22913
|
+
function typeActions(t) {
|
|
22914
|
+
return actionsCache.get(t) ?? [];
|
|
22927
22915
|
}
|
|
22928
22916
|
function countInstancesByStatus(statusInputs, statuses) {
|
|
22929
22917
|
const statusSet = new Set(statuses);
|
|
@@ -22934,8 +22922,8 @@ function countInstancesByStatus(statusInputs, statuses) {
|
|
|
22934
22922
|
}
|
|
22935
22923
|
return sum;
|
|
22936
22924
|
}
|
|
22937
|
-
function applyFindingFilters(
|
|
22938
|
-
let filtered =
|
|
22925
|
+
function applyFindingFilters(types, opts) {
|
|
22926
|
+
let filtered = types;
|
|
22939
22927
|
if (opts.severity && opts.severity.length > 0) {
|
|
22940
22928
|
const sevSet = new Set(opts.severity);
|
|
22941
22929
|
filtered = filtered.filter((g) => sevSet.has(g.severity));
|
|
@@ -22946,7 +22934,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22946
22934
|
}
|
|
22947
22935
|
if (opts.actions && opts.actions.length > 0) {
|
|
22948
22936
|
const actionSet = new Set(opts.actions);
|
|
22949
|
-
filtered = filtered.filter((
|
|
22937
|
+
filtered = filtered.filter((t) => typeActions(t).some((a) => actionSet.has(a)));
|
|
22950
22938
|
}
|
|
22951
22939
|
if (opts.subtype && opts.subtype.length > 0) {
|
|
22952
22940
|
const subtypeSet = new Set(opts.subtype);
|
|
@@ -22958,7 +22946,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22958
22946
|
}
|
|
22959
22947
|
if (opts.q) {
|
|
22960
22948
|
const q = opts.q.toLowerCase();
|
|
22961
|
-
filtered = filtered.filter((
|
|
22949
|
+
filtered = filtered.filter((t) => typeHaystack(t).includes(q));
|
|
22962
22950
|
}
|
|
22963
22951
|
return filtered;
|
|
22964
22952
|
}
|
|
@@ -22973,11 +22961,11 @@ function compareFindingGroupOrder(a, b) {
|
|
|
22973
22961
|
if (recencyDiff !== 0) return recencyDiff;
|
|
22974
22962
|
return a.id.localeCompare(b.id);
|
|
22975
22963
|
}
|
|
22976
|
-
function
|
|
22977
|
-
return [...
|
|
22964
|
+
function sortFindingTypes(types) {
|
|
22965
|
+
return [...types].sort(compareFindingGroupOrder);
|
|
22978
22966
|
}
|
|
22979
|
-
function computeFindingFacets(
|
|
22980
|
-
const forSeverity = applyFindingFilters(
|
|
22967
|
+
function computeFindingFacets(allTypes, opts) {
|
|
22968
|
+
const forSeverity = applyFindingFilters(allTypes, {
|
|
22981
22969
|
providers: opts.providers,
|
|
22982
22970
|
actions: opts.actions,
|
|
22983
22971
|
statuses: opts.statuses,
|
|
@@ -22988,7 +22976,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22988
22976
|
for (const g of forSeverity) {
|
|
22989
22977
|
severityMap.set(g.severity, (severityMap.get(g.severity) ?? 0) + 1);
|
|
22990
22978
|
}
|
|
22991
|
-
const forProvider = applyFindingFilters(
|
|
22979
|
+
const forProvider = applyFindingFilters(allTypes, {
|
|
22992
22980
|
actions: opts.actions,
|
|
22993
22981
|
statuses: opts.statuses,
|
|
22994
22982
|
q: opts.q,
|
|
@@ -22999,7 +22987,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22999
22987
|
for (const g of forProvider) {
|
|
23000
22988
|
for (const p of g.providers) providerMap.set(p, (providerMap.get(p) ?? 0) + 1);
|
|
23001
22989
|
}
|
|
23002
|
-
const forAction = applyFindingFilters(
|
|
22990
|
+
const forAction = applyFindingFilters(allTypes, {
|
|
23003
22991
|
providers: opts.providers,
|
|
23004
22992
|
statuses: opts.statuses,
|
|
23005
22993
|
q: opts.q,
|
|
@@ -23008,9 +22996,9 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23008
22996
|
});
|
|
23009
22997
|
const actionMap = /* @__PURE__ */ new Map();
|
|
23010
22998
|
for (const g of forAction) {
|
|
23011
|
-
for (const a of
|
|
22999
|
+
for (const a of typeActions(g)) actionMap.set(a, (actionMap.get(a) ?? 0) + 1);
|
|
23012
23000
|
}
|
|
23013
|
-
const forSubtype = applyFindingFilters(
|
|
23001
|
+
const forSubtype = applyFindingFilters(allTypes, {
|
|
23014
23002
|
providers: opts.providers,
|
|
23015
23003
|
actions: opts.actions,
|
|
23016
23004
|
statuses: opts.statuses,
|
|
@@ -23019,7 +23007,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23019
23007
|
});
|
|
23020
23008
|
const subtypeMap = /* @__PURE__ */ new Map();
|
|
23021
23009
|
for (const g of forSubtype) subtypeMap.set(g.subtype, (subtypeMap.get(g.subtype) ?? 0) + 1);
|
|
23022
|
-
const forStatus = applyFindingFilters(
|
|
23010
|
+
const forStatus = applyFindingFilters(allTypes, {
|
|
23023
23011
|
providers: opts.providers,
|
|
23024
23012
|
actions: opts.actions,
|
|
23025
23013
|
q: opts.q,
|
|
@@ -23067,10 +23055,20 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23067
23055
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23068
23056
|
case "tools":
|
|
23069
23057
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23058
|
+
// An EMPTY value is a real filter here, not an absent one. The location
|
|
23059
|
+
// list buckets a finding whose event recorded no repo — or no file — under
|
|
23060
|
+
// the empty string, and selecting that bucket has to narrow the panel to
|
|
23061
|
+
// exactly it. Only `undefined` means "no filter"; a caller that wants every
|
|
23062
|
+
// row omits the key, which every call site already does.
|
|
23063
|
+
//
|
|
23064
|
+
// Reading '' as unset is what this replaced, and it failed in the one place
|
|
23065
|
+
// it mattered: the no-repo/no-file bucket is often the largest in a real
|
|
23066
|
+
// store, and its panel dropped both predicates and returned the WHOLE scope
|
|
23067
|
+
// — a row reading 3 findings beside a panel listing every finding there is.
|
|
23070
23068
|
case "repo":
|
|
23071
|
-
return opts.repo === void 0 ||
|
|
23069
|
+
return opts.repo === void 0 || row.repo === opts.repo;
|
|
23072
23070
|
case "file":
|
|
23073
|
-
return opts.file === void 0 ||
|
|
23071
|
+
return opts.file === void 0 || row.file === opts.file;
|
|
23074
23072
|
case "q":
|
|
23075
23073
|
return !opts.q || rowHaystack(row).includes(opts.q.toLowerCase());
|
|
23076
23074
|
}
|
|
@@ -23184,6 +23182,23 @@ function addToLocation(acc, row) {
|
|
|
23184
23182
|
acc.statuses.push(row.status);
|
|
23185
23183
|
acc.ruleIds.add(row.ruleId);
|
|
23186
23184
|
}
|
|
23185
|
+
function compareLocationOrder(a, b) {
|
|
23186
|
+
const rankA = SEVERITY_ORDER2[a.maxSeverity] ?? -1;
|
|
23187
|
+
const rankB = SEVERITY_ORDER2[b.maxSeverity] ?? -1;
|
|
23188
|
+
if (rankA !== rankB) return rankA - rankB;
|
|
23189
|
+
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23190
|
+
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23191
|
+
}
|
|
23192
|
+
if (a.repo !== b.repo) return a.repo < b.repo ? -1 : 1;
|
|
23193
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
23194
|
+
return 0;
|
|
23195
|
+
}
|
|
23196
|
+
function encodeLocationId(repo, file2) {
|
|
23197
|
+
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
23198
|
+
}
|
|
23199
|
+
function encodePart(value) {
|
|
23200
|
+
return encodeURIComponent(value.replace(/[\uD800-\uDFFF]/gu, "\uFFFD"));
|
|
23201
|
+
}
|
|
23187
23202
|
|
|
23188
23203
|
// ../../packages/schema/src/zod/installed-pack.ts
|
|
23189
23204
|
var InstalledPack = external_exports.object({
|
|
@@ -23698,11 +23713,11 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23698
23713
|
// covers the current payload and must be re-granted.
|
|
23699
23714
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23700
23715
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23701
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23702
|
-
// that covers
|
|
23703
|
-
// carry prompt/reply text in `content
|
|
23704
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23705
|
-
// payload no longer counts.
|
|
23716
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23717
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23718
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23719
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23720
|
+
// or an older payload no longer counts.
|
|
23706
23721
|
historySyncConsent: HistorySyncConsent.optional()
|
|
23707
23722
|
});
|
|
23708
23723
|
function defaultWorkspaceSettings() {
|
|
@@ -23833,6 +23848,9 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23833
23848
|
"dataSharesInPlace",
|
|
23834
23849
|
"redactFallback"
|
|
23835
23850
|
]).meta({ id: "ManagedSettingKey" });
|
|
23851
|
+
function isManagedSettingKey(value) {
|
|
23852
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
23853
|
+
}
|
|
23836
23854
|
var ManagedSettingsValues = external_exports.object({
|
|
23837
23855
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
23838
23856
|
controlPlane: external_exports.object({
|
|
@@ -23857,7 +23875,27 @@ var ManagedSettings = external_exports.object({
|
|
|
23857
23875
|
// Which of those the user may not change. A key here with no matching value
|
|
23858
23876
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23859
23877
|
// the user may still override. The two are separable on purpose.
|
|
23860
|
-
|
|
23878
|
+
//
|
|
23879
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
23880
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
23881
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
23882
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
23883
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
23884
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23885
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
23886
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23887
|
+
}).transform(({ lockedFields, ...rest }) => {
|
|
23888
|
+
const known = [];
|
|
23889
|
+
const unknown2 = [];
|
|
23890
|
+
for (const name of lockedFields) {
|
|
23891
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
23892
|
+
else unknown2.push(name);
|
|
23893
|
+
}
|
|
23894
|
+
return {
|
|
23895
|
+
...rest,
|
|
23896
|
+
lockedFields: known,
|
|
23897
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
23898
|
+
};
|
|
23861
23899
|
}).meta({ id: "ManagedSettings" });
|
|
23862
23900
|
|
|
23863
23901
|
// ../../packages/schema/src/zod/project-files.ts
|
|
@@ -23981,7 +24019,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23981
24019
|
timestamp: external_exports.iso.date(),
|
|
23982
24020
|
critical: external_exports.number().int().nonnegative(),
|
|
23983
24021
|
high: external_exports.number().int().nonnegative(),
|
|
23984
|
-
medium: external_exports.number().int().nonnegative()
|
|
24022
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24023
|
+
// Optional and additive, so a producer written against the earlier
|
|
24024
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24025
|
+
// absent case itself — the chart point requires a number.
|
|
24026
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23985
24027
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23986
24028
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23987
24029
|
range: TimeRange,
|
|
@@ -24007,6 +24049,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24007
24049
|
findingKey: external_exports.string(),
|
|
24008
24050
|
ruleId: external_exports.string(),
|
|
24009
24051
|
severity: Severity,
|
|
24052
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24053
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24054
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24055
|
+
repo: external_exports.string().optional(),
|
|
24010
24056
|
path: external_exports.string(),
|
|
24011
24057
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24012
24058
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -25489,7 +25535,8 @@ var SqliteActivityRepository = class {
|
|
|
25489
25535
|
SELECT 1 FROM audit_events d
|
|
25490
25536
|
WHERE d.root_session_id = audit_events.id
|
|
25491
25537
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25492
|
-
OR json_extract(d.attributes, '$.detail')
|
|
25538
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
25539
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25493
25540
|
);
|
|
25494
25541
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25495
25542
|
}
|
|
@@ -26827,23 +26874,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26827
26874
|
)`;
|
|
26828
26875
|
|
|
26829
26876
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26830
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26831
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26832
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26833
|
-
function compareLocationOrder(a, b) {
|
|
26834
|
-
return compareFindingGroupOrder(
|
|
26835
|
-
{
|
|
26836
|
-
severity: a.maxSeverity,
|
|
26837
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26838
|
-
id: ""
|
|
26839
|
-
},
|
|
26840
|
-
{
|
|
26841
|
-
severity: b.maxSeverity,
|
|
26842
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26843
|
-
id: ""
|
|
26844
|
-
}
|
|
26845
|
-
);
|
|
26846
|
-
}
|
|
26847
26877
|
var CONCAT_SEP = ",";
|
|
26848
26878
|
var TUPLE_SEP = "|";
|
|
26849
26879
|
function splitConcat(value) {
|
|
@@ -26895,13 +26925,48 @@ function decodeGroupCursor(cursor) {
|
|
|
26895
26925
|
return null;
|
|
26896
26926
|
}
|
|
26897
26927
|
function firstAfter(sorted, cursor) {
|
|
26898
|
-
const index = sorted.findIndex((
|
|
26928
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26899
26929
|
return index === -1 ? sorted.length : index;
|
|
26900
26930
|
}
|
|
26901
26931
|
function findDeepLinked(sorted, page, id) {
|
|
26902
|
-
if (page.some((
|
|
26903
|
-
return sorted.find((
|
|
26932
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
26933
|
+
return sorted.find((t) => t.id === id);
|
|
26934
|
+
}
|
|
26935
|
+
function encodeLocationCursor(location) {
|
|
26936
|
+
const payload = {
|
|
26937
|
+
sev: location.maxSeverity,
|
|
26938
|
+
t: location.latestDetectedAt,
|
|
26939
|
+
r: location.repo,
|
|
26940
|
+
f: location.file
|
|
26941
|
+
};
|
|
26942
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
26904
26943
|
}
|
|
26944
|
+
function decodeLocationCursor(cursor) {
|
|
26945
|
+
const parsed = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
26946
|
+
if (parsed !== void 0 && typeof parsed.sev === "string" && typeof parsed.t === "string" && typeof parsed.r === "string" && typeof parsed.f === "string") {
|
|
26947
|
+
return { maxSeverity: parsed.sev, latestDetectedAt: parsed.t, repo: parsed.r, file: parsed.f };
|
|
26948
|
+
}
|
|
26949
|
+
return null;
|
|
26950
|
+
}
|
|
26951
|
+
function firstLocationAfter(sorted, cursor) {
|
|
26952
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
26953
|
+
return index === -1 ? sorted.length : index;
|
|
26954
|
+
}
|
|
26955
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
26956
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
26957
|
+
return sorted.find((l) => l.id === id);
|
|
26958
|
+
}
|
|
26959
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
26960
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
26961
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
26962
|
+
e.started_at AS occurred_at,
|
|
26963
|
+
e.source_tool AS source_tool,
|
|
26964
|
+
e.repo AS repo,
|
|
26965
|
+
e.file_path AS file,
|
|
26966
|
+
e.tool_name AS tool_name,
|
|
26967
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
26968
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
26969
|
+
${latestResolutionStatusSql("f")} AS latest_status`;
|
|
26905
26970
|
var DAY_MS3 = 864e5;
|
|
26906
26971
|
var SqliteFindingsRepository = class {
|
|
26907
26972
|
constructor(db) {
|
|
@@ -27022,30 +27087,26 @@ var SqliteFindingsRepository = class {
|
|
|
27022
27087
|
);
|
|
27023
27088
|
}
|
|
27024
27089
|
/**
|
|
27025
|
-
*
|
|
27026
|
-
*
|
|
27027
|
-
*
|
|
27028
|
-
*
|
|
27029
|
-
*
|
|
27030
|
-
*
|
|
27031
|
-
*
|
|
27032
|
-
*
|
|
27033
|
-
*
|
|
27034
|
-
*
|
|
27035
|
-
*
|
|
27036
|
-
*
|
|
27090
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
27091
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
27092
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
27093
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
27094
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
27095
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
27096
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
27097
|
+
* derived status was requested.
|
|
27098
|
+
*
|
|
27099
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
27100
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
27101
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
27102
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
27103
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
27037
27104
|
*
|
|
27038
|
-
* Two reads, neither of which materializes a row per finding:
|
|
27039
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
27040
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
27041
|
-
* latest, search text);
|
|
27042
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
27043
|
-
* populate `instances` for the table's expanded rows.
|
|
27044
27105
|
* The aggregates carry raw DB values and are translated by the same
|
|
27045
|
-
* @akasecurity/schema mappers
|
|
27046
|
-
* rule is ever restated in SQL.
|
|
27106
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
27107
|
+
* status rule is ever restated in SQL.
|
|
27047
27108
|
*/
|
|
27048
|
-
|
|
27109
|
+
listFindingTypes(query) {
|
|
27049
27110
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
27050
27111
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
27051
27112
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -27058,12 +27119,7 @@ var SqliteFindingsRepository = class {
|
|
|
27058
27119
|
predicate,
|
|
27059
27120
|
params: sessionParams
|
|
27060
27121
|
});
|
|
27061
|
-
const
|
|
27062
|
-
sessionId: query.sessionId,
|
|
27063
|
-
from: query.from
|
|
27064
|
-
});
|
|
27065
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27066
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
27122
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27067
27123
|
const filterOpts = {
|
|
27068
27124
|
severity: query.severity,
|
|
27069
27125
|
providers: query.provider,
|
|
@@ -27072,30 +27128,25 @@ var SqliteFindingsRepository = class {
|
|
|
27072
27128
|
subtype: query.subtype,
|
|
27073
27129
|
q: query.q
|
|
27074
27130
|
};
|
|
27075
|
-
const facets = computeFindingFacets(
|
|
27076
|
-
const sorted =
|
|
27131
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
27132
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27077
27133
|
const statusFilter = query.status ?? [];
|
|
27078
27134
|
const totals = {
|
|
27079
|
-
findings: sorted.reduce((acc,
|
|
27080
|
-
if (statusFilter.length === 0) return acc +
|
|
27081
|
-
const agg = aggregates.get(
|
|
27082
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
27135
|
+
findings: sorted.reduce((acc, t) => {
|
|
27136
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
27137
|
+
const agg = aggregates.get(t.id);
|
|
27138
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27083
27139
|
}, 0),
|
|
27084
|
-
|
|
27140
|
+
types: sorted.length
|
|
27085
27141
|
};
|
|
27086
|
-
const limit = query.limit ??
|
|
27142
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27087
27143
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27088
27144
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27089
27145
|
const page = sorted.slice(start, start + limit);
|
|
27090
27146
|
const lastOnPage = page.at(-1);
|
|
27091
27147
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27092
27148
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27093
|
-
const
|
|
27094
|
-
const narrow = (g) => statusSet ? {
|
|
27095
|
-
...g,
|
|
27096
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27097
|
-
} : g;
|
|
27098
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
27149
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27099
27150
|
return Promise.resolve({
|
|
27100
27151
|
totals,
|
|
27101
27152
|
facets,
|
|
@@ -27106,7 +27157,7 @@ var SqliteFindingsRepository = class {
|
|
|
27106
27157
|
}
|
|
27107
27158
|
/**
|
|
27108
27159
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27109
|
-
*
|
|
27160
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27110
27161
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27111
27162
|
*
|
|
27112
27163
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27200,13 +27251,25 @@ var SqliteFindingsRepository = class {
|
|
|
27200
27251
|
});
|
|
27201
27252
|
}
|
|
27202
27253
|
/**
|
|
27203
|
-
* The same findings folded by
|
|
27254
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27204
27255
|
*
|
|
27205
27256
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27206
|
-
* the local store relates a finding to
|
|
27207
|
-
*
|
|
27208
|
-
* empty-string bucket, which
|
|
27209
|
-
*
|
|
27257
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
27258
|
+
* by instead. A repo or file the event did not record folds into the
|
|
27259
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
27260
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
27261
|
+
*
|
|
27262
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
27263
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
27264
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
27265
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
27266
|
+
* place.
|
|
27267
|
+
*
|
|
27268
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
27269
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
27270
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
27271
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
27272
|
+
* its fields.
|
|
27210
27273
|
*/
|
|
27211
27274
|
listFindingLocations(query) {
|
|
27212
27275
|
const opts = {
|
|
@@ -27218,13 +27281,16 @@ var SqliteFindingsRepository = class {
|
|
|
27218
27281
|
tools: query.tool,
|
|
27219
27282
|
q: query.q
|
|
27220
27283
|
};
|
|
27221
|
-
const limit = query.limit ??
|
|
27284
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
27285
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27222
27286
|
const byRepo = /* @__PURE__ */ new Map();
|
|
27287
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27223
27288
|
let total = 0;
|
|
27224
27289
|
for (const row of this.scanFindingRows({
|
|
27225
27290
|
sessionId: query.sessionId,
|
|
27226
27291
|
from: query.from
|
|
27227
27292
|
})) {
|
|
27293
|
+
accumulator.add(row);
|
|
27228
27294
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27229
27295
|
total += 1;
|
|
27230
27296
|
let files = byRepo.get(row.repo);
|
|
@@ -27239,103 +27305,35 @@ var SqliteFindingsRepository = class {
|
|
|
27239
27305
|
}
|
|
27240
27306
|
addToLocation(acc, row);
|
|
27241
27307
|
}
|
|
27242
|
-
|
|
27243
|
-
const
|
|
27244
|
-
|
|
27245
|
-
|
|
27246
|
-
|
|
27247
|
-
|
|
27248
|
-
|
|
27249
|
-
|
|
27250
|
-
|
|
27251
|
-
|
|
27252
|
-
|
|
27253
|
-
|
|
27254
|
-
|
|
27255
|
-
|
|
27256
|
-
|
|
27257
|
-
|
|
27258
|
-
|
|
27259
|
-
|
|
27260
|
-
|
|
27261
|
-
|
|
27262
|
-
|
|
27263
|
-
|
|
27264
|
-
);
|
|
27265
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27266
|
-
const folded = foldGroupStatus(statuses);
|
|
27267
|
-
return {
|
|
27268
|
-
repo,
|
|
27269
|
-
instanceCount: rollup.instanceCount,
|
|
27270
|
-
maxSeverity: rollup.maxSeverity,
|
|
27271
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27272
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27273
|
-
files: fileRows
|
|
27274
|
-
};
|
|
27275
|
-
});
|
|
27276
|
-
repos.sort(compareLocationOrder);
|
|
27308
|
+
const sorted = [];
|
|
27309
|
+
for (const [repo, files] of byRepo) {
|
|
27310
|
+
for (const [file2, acc] of files) {
|
|
27311
|
+
const status = foldGroupStatus(acc.statuses);
|
|
27312
|
+
sorted.push({
|
|
27313
|
+
id: encodeLocationId(repo, file2),
|
|
27314
|
+
repo,
|
|
27315
|
+
file: file2,
|
|
27316
|
+
instanceCount: acc.instanceCount,
|
|
27317
|
+
maxSeverity: acc.maxSeverity,
|
|
27318
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
27319
|
+
...status === void 0 ? {} : { status },
|
|
27320
|
+
ruleIds: [...acc.ruleIds]
|
|
27321
|
+
});
|
|
27322
|
+
}
|
|
27323
|
+
}
|
|
27324
|
+
sorted.sort(compareLocationOrder);
|
|
27325
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
27326
|
+
const page = sorted.slice(start, start + limit);
|
|
27327
|
+
const lastOnPage = page.at(-1);
|
|
27328
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
27329
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27277
27330
|
return Promise.resolve({
|
|
27278
|
-
totals: { findings: total,
|
|
27279
|
-
|
|
27280
|
-
|
|
27331
|
+
totals: { findings: total, locations: sorted.length },
|
|
27332
|
+
facets: accumulator.facets(),
|
|
27333
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
27334
|
+
nextCursor
|
|
27281
27335
|
});
|
|
27282
27336
|
}
|
|
27283
|
-
/**
|
|
27284
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27285
|
-
*
|
|
27286
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27287
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27288
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27289
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27290
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27291
|
-
* store while the answer does not.
|
|
27292
|
-
*
|
|
27293
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27294
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27295
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27296
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27297
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27298
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27299
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27300
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27301
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27302
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27303
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27304
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27305
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27306
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27307
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27308
|
-
* sort of the scope, which is still that floor.
|
|
27309
|
-
*
|
|
27310
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27311
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27312
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27313
|
-
* built from.
|
|
27314
|
-
*/
|
|
27315
|
-
previewRows(aggregates, scope) {
|
|
27316
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27317
|
-
let remaining = 0;
|
|
27318
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27319
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27320
|
-
wanted.set(ruleId, n);
|
|
27321
|
-
remaining += n;
|
|
27322
|
-
}
|
|
27323
|
-
const rows = [];
|
|
27324
|
-
if (remaining === 0) return rows;
|
|
27325
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27326
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27327
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27328
|
-
const want = wanted.get(r.rule_id);
|
|
27329
|
-
if (want === void 0) continue;
|
|
27330
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27331
|
-
if (have >= want) continue;
|
|
27332
|
-
taken.set(r.rule_id, have + 1);
|
|
27333
|
-
rows.push(r);
|
|
27334
|
-
remaining -= 1;
|
|
27335
|
-
if (remaining === 0) break;
|
|
27336
|
-
}
|
|
27337
|
-
return rows;
|
|
27338
|
-
}
|
|
27339
27337
|
/**
|
|
27340
27338
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27341
27339
|
*
|
|
@@ -27362,6 +27360,33 @@ var SqliteFindingsRepository = class {
|
|
|
27362
27360
|
yield toFlatFindingRow(r);
|
|
27363
27361
|
}
|
|
27364
27362
|
}
|
|
27363
|
+
/**
|
|
27364
|
+
* One finding by its own id, or null when no such row exists.
|
|
27365
|
+
*
|
|
27366
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
27367
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
27368
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
27369
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
27370
|
+
* older than anything a first page holds.
|
|
27371
|
+
*
|
|
27372
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
27373
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
27374
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
27375
|
+
* worse than showing it.
|
|
27376
|
+
*
|
|
27377
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
27378
|
+
* type should the list select?" and "what does the drawer show?".
|
|
27379
|
+
*/
|
|
27380
|
+
findingInstance(id) {
|
|
27381
|
+
const row = this.db.prepare(
|
|
27382
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27383
|
+
FROM inspection_findings f
|
|
27384
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
27385
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27386
|
+
WHERE f.id = ?`
|
|
27387
|
+
).get(id);
|
|
27388
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
27389
|
+
}
|
|
27365
27390
|
/**
|
|
27366
27391
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27367
27392
|
* joined to its event and definition, newest first.
|
|
@@ -27395,17 +27420,7 @@ var SqliteFindingsRepository = class {
|
|
|
27395
27420
|
conditions.push("e.started_at >= ?");
|
|
27396
27421
|
params.push(isoToEpochMillis(scope.from));
|
|
27397
27422
|
}
|
|
27398
|
-
const sql = `SELECT
|
|
27399
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27400
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27401
|
-
e.started_at AS occurred_at,
|
|
27402
|
-
e.source_tool AS source_tool,
|
|
27403
|
-
e.repo AS repo,
|
|
27404
|
-
e.file_path AS file,
|
|
27405
|
-
e.tool_name AS tool_name,
|
|
27406
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27407
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27408
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
27423
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27409
27424
|
FROM audit_events e
|
|
27410
27425
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27411
27426
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27419,6 +27434,26 @@ var SqliteFindingsRepository = class {
|
|
|
27419
27434
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27420
27435
|
const rows = this.db.prepare(
|
|
27421
27436
|
`SELECT rule_id,
|
|
27437
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
27438
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
27439
|
+
-- in an aggregate query, every bare column takes its value from
|
|
27440
|
+
-- the row that produced the extremum. So these are the severity
|
|
27441
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
27442
|
+
-- is what the row-based build they replaced read off its first
|
|
27443
|
+
-- (newest-first) row.
|
|
27444
|
+
--
|
|
27445
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
27446
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
27447
|
+
-- mints a new row), so a rule whose severity moved between
|
|
27448
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
27449
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
27450
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
27451
|
+
-- filter, the facet counts and the primary sort key.
|
|
27452
|
+
--
|
|
27453
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
27454
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
27455
|
+
severity,
|
|
27456
|
+
category,
|
|
27422
27457
|
sum(tuple_count) AS instance_count,
|
|
27423
27458
|
max(latest_at) AS latest_at,
|
|
27424
27459
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27429,6 +27464,14 @@ var SqliteFindingsRepository = class {
|
|
|
27429
27464
|
group_concat(tool_names) AS tool_names
|
|
27430
27465
|
FROM (
|
|
27431
27466
|
SELECT d.rule_id AS rule_id,
|
|
27467
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
27468
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
27469
|
+
-- these are grouped on below and resolved to the newest
|
|
27470
|
+
-- firing version by the outer query's bare-column select.
|
|
27471
|
+
-- They ride the aggregate because the type build has no rows
|
|
27472
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
27473
|
+
d.severity AS severity,
|
|
27474
|
+
d.category AS category,
|
|
27432
27475
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27433
27476
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27434
27477
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27443,7 +27486,7 @@ var SqliteFindingsRepository = class {
|
|
|
27443
27486
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27444
27487
|
ON latest.finding_key = f.finding_key
|
|
27445
27488
|
${scope.predicate}
|
|
27446
|
-
GROUP BY d.rule_id, status_tuple
|
|
27489
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27447
27490
|
)
|
|
27448
27491
|
GROUP BY rule_id`
|
|
27449
27492
|
).all(scope.params);
|
|
@@ -27452,6 +27495,8 @@ var SqliteFindingsRepository = class {
|
|
|
27452
27495
|
r.rule_id,
|
|
27453
27496
|
{
|
|
27454
27497
|
instanceCount: r.instance_count,
|
|
27498
|
+
severity: r.severity,
|
|
27499
|
+
category: r.category,
|
|
27455
27500
|
sourceTools: splitConcat(r.source_tools),
|
|
27456
27501
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27457
27502
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27468,7 +27513,7 @@ var SqliteFindingsRepository = class {
|
|
|
27468
27513
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27469
27514
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27470
27515
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27471
|
-
// Left undefined (not '') when unfetched, so
|
|
27516
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27472
27517
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27473
27518
|
// and skip priming a haystack nothing will read.
|
|
27474
27519
|
...withSearchText ? {
|
|
@@ -27620,6 +27665,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
27620
27665
|
this.markOwedStmt = db.prepare(
|
|
27621
27666
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27622
27667
|
);
|
|
27668
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27669
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
27670
|
+
WHERE synced_at IS NULL
|
|
27671
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27672
|
+
AND started_at < :before`
|
|
27673
|
+
);
|
|
27623
27674
|
this.stampStmt = db.prepare(
|
|
27624
27675
|
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27625
27676
|
);
|
|
@@ -27668,7 +27719,9 @@ var SqliteHistorySyncRepository = class {
|
|
|
27668
27719
|
);
|
|
27669
27720
|
this.disownCapturesStmt = db.prepare(
|
|
27670
27721
|
`UPDATE audit_events SET outbox_owed = NULL
|
|
27671
|
-
WHERE outbox_owed IS NOT NULL
|
|
27722
|
+
WHERE outbox_owed IS NOT NULL
|
|
27723
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27724
|
+
AND started_at < :attachedAt`
|
|
27672
27725
|
);
|
|
27673
27726
|
this.rearmStmt = db.prepare(
|
|
27674
27727
|
`UPDATE audit_events SET synced_at = NULL
|
|
@@ -27744,6 +27797,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27744
27797
|
freezeBoundaryStmt;
|
|
27745
27798
|
captureRowsStmt;
|
|
27746
27799
|
markOwedStmt;
|
|
27800
|
+
markCaptureBacklogOwedStmt;
|
|
27747
27801
|
captureSkipCountStmt;
|
|
27748
27802
|
disownCapturesStmt;
|
|
27749
27803
|
partitionStmt;
|
|
@@ -27807,6 +27861,23 @@ var SqliteHistorySyncRepository = class {
|
|
|
27807
27861
|
markCaptureOwed(id) {
|
|
27808
27862
|
this.markOwedStmt.run({ id });
|
|
27809
27863
|
}
|
|
27864
|
+
/**
|
|
27865
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
27866
|
+
*
|
|
27867
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
27868
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27869
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
27870
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27871
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27872
|
+
* later re-attach or key rotation might widen it to.
|
|
27873
|
+
*
|
|
27874
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27875
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27876
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27877
|
+
*/
|
|
27878
|
+
markCaptureBacklogOwed(before) {
|
|
27879
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27880
|
+
}
|
|
27810
27881
|
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27811
27882
|
markSynced(ids, atMs) {
|
|
27812
27883
|
this.stampAll(ids, atMs);
|
|
@@ -27923,15 +27994,42 @@ var SqliteHistorySyncRepository = class {
|
|
|
27923
27994
|
*
|
|
27924
27995
|
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
27925
27996
|
* machine has just left are undelivered as far as the new one is concerned.
|
|
27926
|
-
* All
|
|
27927
|
-
* attributed to the wrong deployment,
|
|
27997
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
27998
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
27999
|
+
* a disown with no re-mark to follow it.
|
|
27928
28000
|
*
|
|
27929
28001
|
* The boundary is written HERE and only here, which is what freezes it: a
|
|
27930
28002
|
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
27931
28003
|
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
27932
28004
|
* the live path has since delivered.
|
|
28005
|
+
*
|
|
28006
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
28007
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
28008
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
28009
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
28010
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
28011
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
28012
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
28013
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
28014
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
28015
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
28016
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
28017
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
28018
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
28019
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
28020
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
28021
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
28022
|
+
*
|
|
28023
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
28024
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
28025
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
28026
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
28027
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
28028
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
28029
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
28030
|
+
* transaction above.
|
|
27933
28031
|
*/
|
|
27934
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
28032
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
27935
28033
|
this.ensureRowStmt.run();
|
|
27936
28034
|
withTransaction(
|
|
27937
28035
|
this.db,
|
|
@@ -27939,7 +28037,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27939
28037
|
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
27940
28038
|
this.rearmStmt.run();
|
|
27941
28039
|
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
27942
|
-
this.disownCapturesStmt.run();
|
|
28040
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
28041
|
+
}
|
|
28042
|
+
if (backfillCapturesBefore !== void 0) {
|
|
28043
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
27943
28044
|
}
|
|
27944
28045
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
27945
28046
|
},
|
|
@@ -28215,7 +28316,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28215
28316
|
}
|
|
28216
28317
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28217
28318
|
}
|
|
28218
|
-
|
|
28319
|
+
var testOnlyManagedPaths = null;
|
|
28320
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28219
28321
|
for (const path of paths) {
|
|
28220
28322
|
let text;
|
|
28221
28323
|
try {
|
|
@@ -30695,7 +30797,7 @@ function toUtcDateString(ms) {
|
|
|
30695
30797
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30696
30798
|
}
|
|
30697
30799
|
function isTimeseriesSeverity(s) {
|
|
30698
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
30800
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30699
30801
|
}
|
|
30700
30802
|
var SqliteSecurityRepository = class {
|
|
30701
30803
|
constructor(db, now = () => Date.now()) {
|
|
@@ -30824,12 +30926,16 @@ var SqliteSecurityRepository = class {
|
|
|
30824
30926
|
const now = this.now();
|
|
30825
30927
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
30826
30928
|
const rows = this.findingsInRange(windowStart, now);
|
|
30827
|
-
const points = Array.from(
|
|
30828
|
-
|
|
30829
|
-
|
|
30830
|
-
|
|
30831
|
-
|
|
30832
|
-
|
|
30929
|
+
const points = Array.from(
|
|
30930
|
+
{ length: numBuckets },
|
|
30931
|
+
(_, i) => ({
|
|
30932
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
30933
|
+
critical: 0,
|
|
30934
|
+
high: 0,
|
|
30935
|
+
medium: 0,
|
|
30936
|
+
low: 0
|
|
30937
|
+
})
|
|
30938
|
+
);
|
|
30833
30939
|
for (const r of rows) {
|
|
30834
30940
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
30835
30941
|
const bucket = points[idx];
|
|
@@ -31047,6 +31153,7 @@ var SqliteSecurityRepository = class {
|
|
|
31047
31153
|
`SELECT f.finding_key AS finding_key,
|
|
31048
31154
|
d.rule_id AS rule_id,
|
|
31049
31155
|
d.severity AS severity,
|
|
31156
|
+
e.repo AS repo,
|
|
31050
31157
|
e.file_path AS path,
|
|
31051
31158
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31052
31159
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31066,6 +31173,7 @@ var SqliteSecurityRepository = class {
|
|
|
31066
31173
|
const items = rows.map((r) => ({
|
|
31067
31174
|
findingKey: r.finding_key,
|
|
31068
31175
|
ruleId: r.rule_id,
|
|
31176
|
+
repo: r.repo ?? "",
|
|
31069
31177
|
severity: r.severity,
|
|
31070
31178
|
path: r.path ?? "",
|
|
31071
31179
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31075,13 +31183,66 @@ var SqliteSecurityRepository = class {
|
|
|
31075
31183
|
}));
|
|
31076
31184
|
return Promise.resolve({ items });
|
|
31077
31185
|
}
|
|
31186
|
+
/**
|
|
31187
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31188
|
+
*
|
|
31189
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31190
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31191
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31192
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31193
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31194
|
+
*
|
|
31195
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31196
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31197
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31198
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31199
|
+
* The two answer different questions and only this one has to match a link.
|
|
31200
|
+
*
|
|
31201
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31202
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31203
|
+
*/
|
|
31204
|
+
recommendationInputs() {
|
|
31205
|
+
const rows = allRows(
|
|
31206
|
+
this.db.prepare(
|
|
31207
|
+
`SELECT d.rule_id AS rule_id,
|
|
31208
|
+
d.category AS category,
|
|
31209
|
+
d.severity AS severity,
|
|
31210
|
+
COUNT(*) AS count
|
|
31211
|
+
FROM inspection_findings f
|
|
31212
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31213
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31214
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31215
|
+
ON latest.finding_key = f.finding_key
|
|
31216
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31217
|
+
AND e.event_type = 'code_change'
|
|
31218
|
+
AND (
|
|
31219
|
+
f.finding_key IS NULL
|
|
31220
|
+
OR latest.status IS NULL
|
|
31221
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31222
|
+
)
|
|
31223
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31224
|
+
)
|
|
31225
|
+
);
|
|
31226
|
+
return Promise.resolve(
|
|
31227
|
+
rows.map((r) => ({
|
|
31228
|
+
ruleId: r.rule_id,
|
|
31229
|
+
category: r.category,
|
|
31230
|
+
severity: r.severity,
|
|
31231
|
+
count: r.count
|
|
31232
|
+
}))
|
|
31233
|
+
);
|
|
31234
|
+
}
|
|
31078
31235
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31079
31236
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31080
31237
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31081
31238
|
findingsInRange(fromMs, toMs) {
|
|
31082
31239
|
const rows = allRows(
|
|
31083
31240
|
this.db.prepare(
|
|
31084
|
-
`
|
|
31241
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31242
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31243
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31244
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31245
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31085
31246
|
FROM inspection_findings f
|
|
31086
31247
|
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31087
31248
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -31094,7 +31255,9 @@ var SqliteSecurityRepository = class {
|
|
|
31094
31255
|
return rows.map((r) => ({
|
|
31095
31256
|
occurredAt: r.occurred_at,
|
|
31096
31257
|
severity: r.severity,
|
|
31097
|
-
actionTaken: r.action_taken
|
|
31258
|
+
actionTaken: r.action_taken,
|
|
31259
|
+
ruleId: r.rule_id,
|
|
31260
|
+
category: r.category
|
|
31098
31261
|
}));
|
|
31099
31262
|
}
|
|
31100
31263
|
};
|
|
@@ -32264,6 +32427,9 @@ function openLocalDatabase(dir) {
|
|
|
32264
32427
|
};
|
|
32265
32428
|
}
|
|
32266
32429
|
|
|
32430
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32431
|
+
import { createHash as createHash3 } from "crypto";
|
|
32432
|
+
|
|
32267
32433
|
// ../../packages/persistence/src/exception-policy.ts
|
|
32268
32434
|
var UserGrantPolicyProvider = class {
|
|
32269
32435
|
#exceptions;
|
|
@@ -32285,7 +32451,7 @@ var UserGrantPolicyProvider = class {
|
|
|
32285
32451
|
};
|
|
32286
32452
|
|
|
32287
32453
|
// ../../packages/persistence/src/finding-key.ts
|
|
32288
|
-
import { createHash as
|
|
32454
|
+
import { createHash as createHash4 } from "crypto";
|
|
32289
32455
|
|
|
32290
32456
|
// ../../packages/persistence/src/fingerprint.ts
|
|
32291
32457
|
import { createHmac, randomBytes } from "crypto";
|
|
@@ -32410,14 +32576,18 @@ function fingerprintValue(key, raw) {
|
|
|
32410
32576
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
32411
32577
|
}
|
|
32412
32578
|
|
|
32413
|
-
// ../../packages/persistence/src/history-
|
|
32579
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
32414
32580
|
import { existsSync as existsSync4 } from "fs";
|
|
32415
32581
|
import { join as join9 } from "path";
|
|
32582
|
+
|
|
32583
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
32584
|
+
import { existsSync as existsSync5 } from "fs";
|
|
32585
|
+
import { join as join10 } from "path";
|
|
32416
32586
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32417
32587
|
|
|
32418
32588
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32419
|
-
import { existsSync as
|
|
32420
|
-
import { dirname as dirname3, join as
|
|
32589
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32590
|
+
import { dirname as dirname3, join as join11, resolve } from "path";
|
|
32421
32591
|
|
|
32422
32592
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32423
32593
|
import {
|
|
@@ -32531,7 +32701,7 @@ function formatPointer(category, keyVersion, pointerId, tag) {
|
|
|
32531
32701
|
import { execFileSync } from "child_process";
|
|
32532
32702
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32533
32703
|
import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
32534
|
-
import { join as
|
|
32704
|
+
import { join as join12 } from "path";
|
|
32535
32705
|
var VAULT_OCCUPANT_REASON = {
|
|
32536
32706
|
symlink: "the path is a symlink; remove it so a keyring can be created",
|
|
32537
32707
|
gone: "the path was occupied but holds no keyring (removed while it was being created)",
|
|
@@ -32630,7 +32800,7 @@ function claimRotationLock(lock, owner) {
|
|
|
32630
32800
|
throw asError(err);
|
|
32631
32801
|
}
|
|
32632
32802
|
try {
|
|
32633
|
-
writeFileSync3(
|
|
32803
|
+
writeFileSync3(join12(lock, LOCK_OWNER_FILE), `${owner}
|
|
32634
32804
|
`, { mode: DATA_FILE_MODE });
|
|
32635
32805
|
return true;
|
|
32636
32806
|
} catch (err) {
|
|
@@ -32639,7 +32809,7 @@ function claimRotationLock(lock, owner) {
|
|
|
32639
32809
|
}
|
|
32640
32810
|
}
|
|
32641
32811
|
function acquireRotationLock(keysDir2) {
|
|
32642
|
-
const lock =
|
|
32812
|
+
const lock = join12(keysDir2, `${VAULT_KEY_FILENAME}.lock`);
|
|
32643
32813
|
const owner = randomBytes2(16).toString("hex");
|
|
32644
32814
|
if (claimRotationLock(lock, owner)) return { lock, owner };
|
|
32645
32815
|
let held;
|
|
@@ -32666,7 +32836,7 @@ function acquireRotationLock(keysDir2) {
|
|
|
32666
32836
|
}
|
|
32667
32837
|
function releaseRotationLock(lease) {
|
|
32668
32838
|
try {
|
|
32669
|
-
if (readFileSync7(
|
|
32839
|
+
if (readFileSync7(join12(lease.lock, LOCK_OWNER_FILE), "utf8").trim() !== lease.owner) return;
|
|
32670
32840
|
} catch {
|
|
32671
32841
|
return;
|
|
32672
32842
|
}
|
|
@@ -32687,7 +32857,7 @@ var FileKeyProvider = class {
|
|
|
32687
32857
|
this.#keysDir = keysDir2;
|
|
32688
32858
|
}
|
|
32689
32859
|
get filePath() {
|
|
32690
|
-
return
|
|
32860
|
+
return join12(this.#keysDir, VAULT_KEY_FILENAME);
|
|
32691
32861
|
}
|
|
32692
32862
|
loadOrCreate() {
|
|
32693
32863
|
return asAsync(() => {
|
|
@@ -33352,8 +33522,8 @@ var SecretVault = class {
|
|
|
33352
33522
|
};
|
|
33353
33523
|
|
|
33354
33524
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
33355
|
-
import { existsSync as
|
|
33356
|
-
import { join as
|
|
33525
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
33526
|
+
import { join as join13 } from "path";
|
|
33357
33527
|
|
|
33358
33528
|
// ../../packages/plugin-sdk/src/provider-env.ts
|
|
33359
33529
|
var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
|
|
@@ -33407,8 +33577,8 @@ function resolveProvider() {
|
|
|
33407
33577
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
33408
33578
|
try {
|
|
33409
33579
|
ensureLayoutDirSync(base);
|
|
33410
|
-
const settingsFile =
|
|
33411
|
-
if (
|
|
33580
|
+
const settingsFile = join14(settingsDir(base), "settings.json");
|
|
33581
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
33412
33582
|
} catch {
|
|
33413
33583
|
}
|
|
33414
33584
|
migrateLegacyLayout(base);
|
|
@@ -33433,7 +33603,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
33433
33603
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
33434
33604
|
import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
33435
33605
|
import { homedir as homedir2 } from "os";
|
|
33436
|
-
import { basename as basename3, join as
|
|
33606
|
+
import { basename as basename3, join as join16 } from "path";
|
|
33437
33607
|
|
|
33438
33608
|
// ../../packages/detections/src/egress/registry.ts
|
|
33439
33609
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -36391,24 +36561,20 @@ function registerBundledPacks() {
|
|
|
36391
36561
|
}
|
|
36392
36562
|
|
|
36393
36563
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
36394
|
-
import { existsSync as
|
|
36395
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
36564
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
|
|
36565
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join15, sep as sep2 } from "path";
|
|
36396
36566
|
|
|
36397
36567
|
// ../../packages/plugin-sdk/src/events.ts
|
|
36398
|
-
import { createHash as
|
|
36568
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
36399
36569
|
|
|
36400
36570
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
36401
|
-
import { existsSync as
|
|
36571
|
+
import { existsSync as existsSync10 } from "fs";
|
|
36402
36572
|
import { fileURLToPath } from "url";
|
|
36403
36573
|
import { Worker } from "worker_threads";
|
|
36404
36574
|
|
|
36405
|
-
// ../../packages/plugin-sdk/src/
|
|
36406
|
-
|
|
36407
|
-
import {
|
|
36408
|
-
import { join as join16 } from "path";
|
|
36409
|
-
|
|
36410
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
36411
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
36575
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
36576
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
36577
|
+
import { join as join18 } from "path";
|
|
36412
36578
|
|
|
36413
36579
|
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
36414
36580
|
import {
|
|
@@ -36416,24 +36582,50 @@ import {
|
|
|
36416
36582
|
fstatSync,
|
|
36417
36583
|
mkdirSync as mkdirSync2,
|
|
36418
36584
|
openSync as openSync2,
|
|
36419
|
-
readFileSync as
|
|
36585
|
+
readFileSync as readFileSync10,
|
|
36420
36586
|
readSync,
|
|
36421
36587
|
writeFileSync as writeFileSync5
|
|
36422
36588
|
} from "fs";
|
|
36423
36589
|
import { join as join17 } from "path";
|
|
36424
36590
|
var TAIL_BYTES = 256 * 1024;
|
|
36425
36591
|
|
|
36592
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
36593
|
+
var HOST_FEATURE = {
|
|
36594
|
+
ModelSwitch: "model-switch",
|
|
36595
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
36596
|
+
};
|
|
36597
|
+
var HOST_FLOORS = {
|
|
36598
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
36599
|
+
label: "model-switch protection",
|
|
36600
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
36601
|
+
since: "2.1.251"
|
|
36602
|
+
},
|
|
36603
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
36604
|
+
label: "vault pointer display",
|
|
36605
|
+
hookEvents: ["MessageDisplay"],
|
|
36606
|
+
since: "2.1.152"
|
|
36607
|
+
}
|
|
36608
|
+
};
|
|
36609
|
+
|
|
36610
|
+
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
36611
|
+
var import_ignore = __toESM(require_ignore(), 1);
|
|
36612
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
36613
|
+
import { join as join19 } from "path";
|
|
36614
|
+
|
|
36615
|
+
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
36616
|
+
import { arch, hostname as hostname4, platform, release } from "os";
|
|
36617
|
+
|
|
36426
36618
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
36427
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
36428
|
-
import { join as
|
|
36619
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
36620
|
+
import { join as join20 } from "path";
|
|
36429
36621
|
|
|
36430
36622
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
36431
36623
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
36432
36624
|
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
36433
36625
|
|
|
36434
36626
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
36435
|
-
import { existsSync as
|
|
36436
|
-
import { basename as basename5, join as
|
|
36627
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
36628
|
+
import { basename as basename5, join as join21 } from "path";
|
|
36437
36629
|
|
|
36438
36630
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
36439
36631
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -36469,7 +36661,7 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
36469
36661
|
|
|
36470
36662
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
36471
36663
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
36472
|
-
import { join as
|
|
36664
|
+
import { join as join22 } from "path";
|
|
36473
36665
|
|
|
36474
36666
|
// ../../packages/plugin-sdk/src/tokenize.ts
|
|
36475
36667
|
function redactedPlaceholder(category) {
|
|
@@ -36799,13 +36991,13 @@ function describePointerSafe(token) {
|
|
|
36799
36991
|
import {
|
|
36800
36992
|
mkdirSync as mkdirSync5,
|
|
36801
36993
|
readdirSync as readdirSync5,
|
|
36802
|
-
readFileSync as
|
|
36994
|
+
readFileSync as readFileSync14,
|
|
36803
36995
|
renameSync as renameSync5,
|
|
36804
36996
|
rmSync as rmSync7,
|
|
36805
36997
|
statSync as statSync9,
|
|
36806
36998
|
writeFileSync as writeFileSync8
|
|
36807
36999
|
} from "fs";
|
|
36808
|
-
import { dirname as dirname6, join as
|
|
37000
|
+
import { dirname as dirname6, join as join23 } from "path";
|
|
36809
37001
|
var EMPTY_CARRY = Object.freeze({
|
|
36810
37002
|
tail: "",
|
|
36811
37003
|
fence: null,
|
|
@@ -37002,7 +37194,7 @@ var CARRY_FILE_PREFIX = "display-carry";
|
|
|
37002
37194
|
var STALE_CARRY_MS = 15 * 60 * 1e3;
|
|
37003
37195
|
function carryFilePath(dataDir2, sessionId) {
|
|
37004
37196
|
const safe = sessionId.replace(/[^A-Za-z0-9_-]/g, "_").slice(0, 80);
|
|
37005
|
-
return
|
|
37197
|
+
return join23(dataDir2, `${CARRY_FILE_PREFIX}-${safe === "" ? "session" : safe}.json`);
|
|
37006
37198
|
}
|
|
37007
37199
|
function parseFence(value) {
|
|
37008
37200
|
if (typeof value !== "object" || value === null) return null;
|
|
@@ -37013,7 +37205,7 @@ function parseFence(value) {
|
|
|
37013
37205
|
}
|
|
37014
37206
|
function loadCarry(file2, keys) {
|
|
37015
37207
|
try {
|
|
37016
|
-
const parsed = JSON.parse(
|
|
37208
|
+
const parsed = JSON.parse(readFileSync14(file2, "utf8"));
|
|
37017
37209
|
if (typeof parsed !== "object" || parsed === null) return EMPTY_CARRY;
|
|
37018
37210
|
const record2 = parsed;
|
|
37019
37211
|
const revealedCount = record2.messageKey === keys.messageKey && typeof record2.revealedCount === "number" && Number.isFinite(record2.revealedCount) ? record2.revealedCount : 0;
|
|
@@ -37066,7 +37258,7 @@ function removeStaleCarryFiles(dir, keep) {
|
|
|
37066
37258
|
const cutoff = Date.now() - STALE_CARRY_MS;
|
|
37067
37259
|
for (const name of readdirSync5(dir)) {
|
|
37068
37260
|
if (!name.startsWith(CARRY_FILE_PREFIX) || !name.endsWith(".json")) continue;
|
|
37069
|
-
const path =
|
|
37261
|
+
const path = join23(dir, name);
|
|
37070
37262
|
if (path === keep) continue;
|
|
37071
37263
|
try {
|
|
37072
37264
|
if (statSync9(path).mtimeMs < cutoff) rmSync7(path, { force: true });
|
|
@@ -37097,7 +37289,7 @@ function finalizeCarry(file2, keys, carry) {
|
|
|
37097
37289
|
}
|
|
37098
37290
|
let owned = true;
|
|
37099
37291
|
try {
|
|
37100
|
-
const parsed = JSON.parse(
|
|
37292
|
+
const parsed = JSON.parse(readFileSync14(file2, "utf8"));
|
|
37101
37293
|
if (typeof parsed === "object" && parsed !== null) {
|
|
37102
37294
|
const record2 = parsed;
|
|
37103
37295
|
owned = record2.blockKey === keys.blockKey || record2.messageKey === keys.messageKey;
|