@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
package/scripts/onboard.js
CHANGED
|
@@ -20737,13 +20737,11 @@ var FindingGroup = external_exports.object({
|
|
|
20737
20737
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20738
20738
|
instances: external_exports.array(FindingInstance),
|
|
20739
20739
|
// Derived from instances' statuses with open-dominates precedence (see
|
|
20740
|
-
//
|
|
20740
|
+
// foldGroupStatus). Undefined only when no instance carries a status.
|
|
20741
20741
|
status: FindingStatus.optional(),
|
|
20742
|
-
// The distinct people across the WHOLE group, not just the
|
|
20743
|
-
//
|
|
20744
|
-
//
|
|
20745
|
-
// instance carries a user, or when the store supplied whole-group folds
|
|
20746
|
-
// without one.
|
|
20742
|
+
// The distinct people across the WHOLE group, not just the instances
|
|
20743
|
+
// carried here. Undefined when no instance carries a user, or when the
|
|
20744
|
+
// store supplied whole-group folds without one.
|
|
20747
20745
|
users: external_exports.array(FindingUser).optional()
|
|
20748
20746
|
}).meta({ id: "FindingGroup" });
|
|
20749
20747
|
var FindingStats = external_exports.object({
|
|
@@ -20772,21 +20770,31 @@ var FindingFacets = external_exports.object({
|
|
|
20772
20770
|
// counted under no value.
|
|
20773
20771
|
status: external_exports.array(FindingFacetItem),
|
|
20774
20772
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20775
|
-
// reads, which can filter by it; the
|
|
20773
|
+
// reads, which can filter by it; the type-level read omits the dimension
|
|
20776
20774
|
// because a group spans tools.
|
|
20777
20775
|
tool: external_exports.array(FindingFacetItem).optional()
|
|
20778
20776
|
}).meta({ id: "FindingFacets" });
|
|
20779
|
-
var
|
|
20780
|
-
|
|
20777
|
+
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20778
|
+
id: "FindingTypeSummary"
|
|
20779
|
+
});
|
|
20780
|
+
var DEFAULT_FINDING_TYPES_LIMIT = 50;
|
|
20781
|
+
var MAX_FINDING_TYPES_LIMIT = 100;
|
|
20782
|
+
var ListFindingTypesQuery = external_exports.object({
|
|
20781
20783
|
// NOTE: severity filters by Severity (critical/high/medium/low), not by
|
|
20782
|
-
// FindingAction.
|
|
20784
|
+
// FindingAction. It narrows TYPES: a type's severity is the one its newest
|
|
20785
|
+
// firing version carries, and this list pages types.
|
|
20786
|
+
//
|
|
20787
|
+
// That is NOT a claim the findings of a type share it. A rule can hold several
|
|
20788
|
+
// definition versions at different severities, so a type kept by this filter
|
|
20789
|
+
// can hold findings that individually do not match — see totals.findings on
|
|
20790
|
+
// ListFindingTypesResponse, which counts them all.
|
|
20783
20791
|
severity: external_exports.array(Severity).optional(),
|
|
20784
20792
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20785
20793
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20786
20794
|
action: external_exports.array(FindingAction).optional(),
|
|
20787
|
-
// Matches a
|
|
20788
|
-
// individual
|
|
20789
|
-
//
|
|
20795
|
+
// Matches a type's DERIVED status (see FindingGroup.status), not its
|
|
20796
|
+
// individual findings' — so a filtered row's status always reads one of the
|
|
20797
|
+
// requested values.
|
|
20790
20798
|
status: external_exports.array(FindingStatus).optional(),
|
|
20791
20799
|
q: external_exports.string().optional(),
|
|
20792
20800
|
// Scope to findings whose event carries this session id (the Activity page's
|
|
@@ -20796,23 +20804,37 @@ var ListGroupedFindingsQuery = external_exports.object({
|
|
|
20796
20804
|
// from a time-scoped page (Activity's range) can carry that scope. Absent
|
|
20797
20805
|
// means all time — this list has no default window.
|
|
20798
20806
|
from: external_exports.iso.datetime().optional(),
|
|
20799
|
-
// A
|
|
20800
|
-
//
|
|
20801
|
-
//
|
|
20802
|
-
//
|
|
20803
|
-
//
|
|
20807
|
+
// A RULE id that must appear in the page even when the cursor has already
|
|
20808
|
+
// advanced past its sort position. This is what keeps the selected type
|
|
20809
|
+
// visible in the list once it paginates: the target is appended out of sort
|
|
20810
|
+
// order rather than scanned forward for. Never affects totals, facets or the
|
|
20811
|
+
// cursor. Unlike the grouped read this replaces, it names a rule only — an
|
|
20812
|
+
// instance id is resolved by `findingInstance`, which is a primary-key seek
|
|
20813
|
+
// and so is not bounded by what any page happens to hold.
|
|
20804
20814
|
includeId: external_exports.string().optional(),
|
|
20805
|
-
|
|
20806
|
-
limit: external_exports.coerce.number().int().min(1).max(100).optional(),
|
|
20815
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
|
|
20807
20816
|
cursor: external_exports.string().optional()
|
|
20808
20817
|
});
|
|
20809
|
-
var
|
|
20818
|
+
var ListFindingTypesResponse = external_exports.object({
|
|
20810
20819
|
totals: external_exports.object({
|
|
20820
|
+
// Findings belonging to the matching TYPES — not findings that each match
|
|
20821
|
+
// the filters. The filters here select types, so a type that survives
|
|
20822
|
+
// contributes its whole instanceCount.
|
|
20823
|
+
//
|
|
20824
|
+
// `status` is the one exception, narrowed per finding via
|
|
20825
|
+
// countInstancesByStatus. `severity`, `provider` and `action` are not, so
|
|
20826
|
+
// this can exceed what the instance read reports for the same filters: a
|
|
20827
|
+
// rule whose severity moved between versions is kept on its newest and
|
|
20828
|
+
// still counts its older findings. Narrowing the other three needs
|
|
20829
|
+
// per-dimension counts the aggregate does not carry today.
|
|
20811
20830
|
findings: external_exports.number().int().nonnegative(),
|
|
20812
|
-
|
|
20831
|
+
// Counts TYPES, which is the unit this read pages. The instance read's
|
|
20832
|
+
// own totals count findings; the two deliberately answer different
|
|
20833
|
+
// questions and are never summed.
|
|
20834
|
+
types: external_exports.number().int().nonnegative()
|
|
20813
20835
|
}),
|
|
20814
20836
|
facets: FindingFacets,
|
|
20815
|
-
items: external_exports.array(
|
|
20837
|
+
items: external_exports.array(FindingTypeSummary),
|
|
20816
20838
|
nextCursor: external_exports.string().nullable(),
|
|
20817
20839
|
// Present only on session-scoped queries (`sessionId` set): per ruleId, how
|
|
20818
20840
|
// many times that rule fired in the session's persisted transcript. Findings
|
|
@@ -20820,7 +20842,7 @@ var ListGroupedFindingsResponse = external_exports.object({
|
|
|
20820
20842
|
// every firing, so the two numbers legitimately differ — this map lets a
|
|
20821
20843
|
// session-scoped view show both.
|
|
20822
20844
|
sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
|
|
20823
|
-
}).meta({ id: "
|
|
20845
|
+
}).meta({ id: "ListFindingTypesResponse" });
|
|
20824
20846
|
var ApplyFindingActionRequest = external_exports.object({
|
|
20825
20847
|
// 'quarantined' is system-assigned (see FindingAction) — clients may not set
|
|
20826
20848
|
// it, so it is excluded from the request contract. The mapping helper
|
|
@@ -20850,12 +20872,13 @@ var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
|
20850
20872
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
20851
20873
|
var ListFindingInstancesQuery = external_exports.object({
|
|
20852
20874
|
severity: external_exports.array(Severity).optional(),
|
|
20853
|
-
// Rule ids, the same vocabulary the
|
|
20875
|
+
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
20876
|
+
// ONE of them is how the master/detail view scopes its right-hand panel.
|
|
20854
20877
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20855
20878
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20856
20879
|
action: external_exports.array(FindingAction).optional(),
|
|
20857
20880
|
// Matches each instance's OWN derived status (deriveFindingStatus), unlike
|
|
20858
|
-
// the
|
|
20881
|
+
// the types query's type-level fold.
|
|
20859
20882
|
status: external_exports.array(FindingStatus).optional(),
|
|
20860
20883
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20861
20884
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
@@ -20872,37 +20895,47 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20872
20895
|
});
|
|
20873
20896
|
var ListFindingInstancesResponse = external_exports.object({
|
|
20874
20897
|
// Instances matching the filters across the whole scope, not just this
|
|
20875
|
-
// page — cursor-independent, like the
|
|
20898
|
+
// page — cursor-independent, like the types list's totals.
|
|
20876
20899
|
totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
|
|
20877
|
-
// Counts in INSTANCES here, where the
|
|
20900
|
+
// Counts in INSTANCES here, where the types response counts types. Each
|
|
20878
20901
|
// dimension still excludes its own filter.
|
|
20879
20902
|
facets: FindingFacets,
|
|
20880
20903
|
items: external_exports.array(FindingInstanceDetail),
|
|
20881
20904
|
nextCursor: external_exports.string().nullable()
|
|
20882
20905
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20883
|
-
var
|
|
20884
|
-
//
|
|
20885
|
-
//
|
|
20886
|
-
|
|
20887
|
-
|
|
20888
|
-
|
|
20889
|
-
|
|
20890
|
-
// Folded from the instances' derived statuses with the same
|
|
20891
|
-
// open-dominates precedence a group uses.
|
|
20892
|
-
status: FindingStatus.optional(),
|
|
20893
|
-
// Distinct rules seen at this location, capped — the row shows them as
|
|
20894
|
-
// chips, and the count is what conveys scale.
|
|
20895
|
-
ruleIds: external_exports.array(external_exports.string())
|
|
20896
|
-
}).meta({ id: "FindingLocationFile" });
|
|
20897
|
-
var FindingLocationRepo = external_exports.object({
|
|
20906
|
+
var FindingLocationSummary = external_exports.object({
|
|
20907
|
+
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20908
|
+
// because a location's identity is two values and a URL param carries one:
|
|
20909
|
+
// `?loc=` names a location the way `?rule=` names a type. Only ever compared
|
|
20910
|
+
// for EQUALITY — the page's selection check, this read's `includeId`, the
|
|
20911
|
+
// client's page dedupe — never decoded, and never a sort key.
|
|
20912
|
+
id: external_exports.string(),
|
|
20898
20913
|
/** Empty when the instances carried no repo attribute. */
|
|
20899
20914
|
repo: external_exports.string(),
|
|
20915
|
+
// Empty when the instances carried no file path (a prompt, or a tool call
|
|
20916
|
+
// with no file attribution). Both halves empty is a real location — usually
|
|
20917
|
+
// the largest one in a store — and is selectable like any other.
|
|
20918
|
+
file: external_exports.string(),
|
|
20900
20919
|
instanceCount: external_exports.number().int().nonnegative(),
|
|
20920
|
+
// The WORST severity present, not the first row's. It is this list's primary
|
|
20921
|
+
// sort key, so it is also what explains why a row is where it is, and it is
|
|
20922
|
+
// how a reader decides what to open without opening everything.
|
|
20901
20923
|
maxSeverity: Severity,
|
|
20902
20924
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20925
|
+
// Folded from the instances' derived statuses with the same open-dominates
|
|
20926
|
+
// precedence a group uses, so it answers "is anything left to do here" and
|
|
20927
|
+
// not much more: a location holding 1 open among 40 resolved reads like one
|
|
20928
|
+
// holding 40 open. That loss is accepted — the panel beside this list
|
|
20929
|
+
// carries each finding's own status, and instanceCount sits next to the
|
|
20930
|
+
// badge.
|
|
20903
20931
|
status: FindingStatus.optional(),
|
|
20904
|
-
|
|
20905
|
-
|
|
20932
|
+
// Every distinct rule seen at this location, UNCAPPED — so the length is a
|
|
20933
|
+
// tally rather than a sample and a row can say how many there are. Bounded
|
|
20934
|
+
// by the ruleset, not by the store. The view bounds what it DISPLAYS.
|
|
20935
|
+
ruleIds: external_exports.array(external_exports.string())
|
|
20936
|
+
}).meta({ id: "FindingLocationSummary" });
|
|
20937
|
+
var DEFAULT_FINDING_LOCATIONS_LIMIT = 50;
|
|
20938
|
+
var MAX_FINDING_LOCATIONS_LIMIT = 100;
|
|
20906
20939
|
var ListFindingLocationsQuery = external_exports.object({
|
|
20907
20940
|
severity: external_exports.array(Severity).optional(),
|
|
20908
20941
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
@@ -20915,18 +20948,42 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20915
20948
|
q: external_exports.string().optional(),
|
|
20916
20949
|
sessionId: external_exports.string().optional(),
|
|
20917
20950
|
from: external_exports.iso.datetime().optional(),
|
|
20918
|
-
|
|
20951
|
+
// A LOCATION id (see FindingLocationSummary.id) that must appear in the page
|
|
20952
|
+
// even when the cursor has already advanced past its sort position — the
|
|
20953
|
+
// counterpart of ListFindingTypesQuery.includeId, and needed far more often
|
|
20954
|
+
// here. Selecting a row pushes the URL, which re-renders the server and resets
|
|
20955
|
+
// the client's page cache to page 0; with distinct (repo, file) pairs running
|
|
20956
|
+
// into the thousands, a selection sitting off page 0 is the ordinary case
|
|
20957
|
+
// rather than a deep-link corner. Never affects totals, facets or the cursor.
|
|
20958
|
+
includeId: external_exports.string().optional(),
|
|
20959
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
|
|
20960
|
+
cursor: external_exports.string().optional()
|
|
20919
20961
|
});
|
|
20920
20962
|
var ListFindingLocationsResponse = external_exports.object({
|
|
20921
20963
|
totals: external_exports.object({
|
|
20964
|
+
// Findings matching the filters across the whole scope. Unlike the types
|
|
20965
|
+
// read's same-named field this needs no caveat: the filters here narrow
|
|
20966
|
+
// per finding, so this is the sum of every row's instanceCount.
|
|
20922
20967
|
findings: external_exports.number().int().nonnegative(),
|
|
20923
|
-
|
|
20924
|
-
|
|
20968
|
+
// Counts LOCATIONS, the unit this read pages — the number the paginator
|
|
20969
|
+
// states. The facets beside it count FINDINGS (see below); a surface
|
|
20970
|
+
// showing both says which is which.
|
|
20971
|
+
locations: external_exports.number().int().nonnegative()
|
|
20925
20972
|
}),
|
|
20926
|
-
|
|
20927
|
-
|
|
20928
|
-
|
|
20929
|
-
|
|
20973
|
+
// Counts in FINDINGS, where the types response counts types, each dimension
|
|
20974
|
+
// still excluding its own filter. Deliberately not locations: counting those
|
|
20975
|
+
// needs a set of location keys per dimension per value — memory tracking the
|
|
20976
|
+
// store times the vocabulary, in a read whose scan promises flat memory —
|
|
20977
|
+
// and the cheap per-location version is not an approximation but WRONG. A
|
|
20978
|
+
// location holding {claudecode, block} and {codex, warn} would survive
|
|
20979
|
+
// provider=claudecode AND action=warn, under which no single finding
|
|
20980
|
+
// matches, so the facet would contradict the instanceCount this whole view
|
|
20981
|
+
// rests on. Findings also keep the toolbar in the same unit as the page
|
|
20982
|
+
// tally and the panel it sits above.
|
|
20983
|
+
facets: FindingFacets,
|
|
20984
|
+
/** Sorted by max severity, then most recent, then (repo, file). */
|
|
20985
|
+
items: external_exports.array(FindingLocationSummary),
|
|
20986
|
+
nextCursor: external_exports.string().nullable()
|
|
20930
20987
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
20931
20988
|
|
|
20932
20989
|
// ../../packages/schema/src/zod/meta.ts
|
|
@@ -22094,6 +22151,14 @@ var ControlPlaneErrorBody = external_exports.object({
|
|
|
22094
22151
|
message: external_exports.string().optional()
|
|
22095
22152
|
}).optional()
|
|
22096
22153
|
});
|
|
22154
|
+
var RemoteFailureKind = external_exports.enum([
|
|
22155
|
+
"unauthorized",
|
|
22156
|
+
"forbidden",
|
|
22157
|
+
"route-absent",
|
|
22158
|
+
"invalid-request",
|
|
22159
|
+
"rejected",
|
|
22160
|
+
"unreachable"
|
|
22161
|
+
]);
|
|
22097
22162
|
var AttachDeviceRequest = external_exports.object({
|
|
22098
22163
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22099
22164
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22787,139 +22852,62 @@ function deriveFindingStatus(row) {
|
|
|
22787
22852
|
if (row.latestResolutionStatus === "dismissed") return "dismissed";
|
|
22788
22853
|
return "open";
|
|
22789
22854
|
}
|
|
22790
|
-
function distinctUsers(instances) {
|
|
22791
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22792
|
-
const users = [];
|
|
22793
|
-
for (const i of instances) {
|
|
22794
|
-
if (i.user === void 0 || seen.has(i.user.id)) continue;
|
|
22795
|
-
seen.add(i.user.id);
|
|
22796
|
-
users.push(i.user);
|
|
22797
|
-
}
|
|
22798
|
-
return users;
|
|
22799
|
-
}
|
|
22800
22855
|
function sortUsers(users) {
|
|
22801
22856
|
return [...users].sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
22802
22857
|
}
|
|
22803
|
-
function
|
|
22804
|
-
const overrides = opts.overrides;
|
|
22858
|
+
function buildFindingTypes(aggregates, opts = {}) {
|
|
22805
22859
|
const packNames = opts.packNames;
|
|
22806
|
-
const
|
|
22807
|
-
const
|
|
22808
|
-
|
|
22809
|
-
const
|
|
22810
|
-
|
|
22811
|
-
else byRuleId.set(row.ruleId, [row]);
|
|
22812
|
-
}
|
|
22813
|
-
const groups = [];
|
|
22814
|
-
for (const [ruleId, ruleRows] of byRuleId) {
|
|
22815
|
-
const instances = ruleRows.map((r) => {
|
|
22816
|
-
const effectiveDbAction = overrides?.get(r.id) ?? r.actionTaken;
|
|
22817
|
-
return {
|
|
22818
|
-
id: r.id,
|
|
22819
|
-
provider: toApiProvider(r.sourceTool),
|
|
22820
|
-
repo: r.repo,
|
|
22821
|
-
file: r.file,
|
|
22822
|
-
...r.toolName === void 0 ? {} : { toolName: r.toolName },
|
|
22823
|
-
...r.eventId === void 0 ? {} : { eventId: r.eventId },
|
|
22824
|
-
...r.sessionId === void 0 ? {} : { sessionId: r.sessionId },
|
|
22825
|
-
...r.user === void 0 ? {} : { user: r.user },
|
|
22826
|
-
action: toApiAction(effectiveDbAction),
|
|
22827
|
-
detectedAt: r.occurredAt,
|
|
22828
|
-
confidence: r.confidence,
|
|
22829
|
-
status: r.status
|
|
22830
|
-
};
|
|
22831
|
-
});
|
|
22832
|
-
const agg = aggregates?.get(ruleId);
|
|
22833
|
-
const users = agg ? sortUsers(agg.users ?? []) : distinctUsers(instances);
|
|
22834
|
-
const latestDetectedAt = agg?.latestDetectedAt ?? ruleRows.reduce(
|
|
22835
|
-
(max, r) => r.occurredAt > max ? r.occurredAt : max,
|
|
22836
|
-
ruleRows[0]?.occurredAt ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
22837
|
-
);
|
|
22838
|
-
const seenProviders = /* @__PURE__ */ new Set();
|
|
22839
|
-
const providers = (agg ? [...new Set(agg.sourceTools.map(toApiProvider))].sort() : instances.map((i) => i.provider)).filter((p) => {
|
|
22840
|
-
if (seenProviders.has(p)) return false;
|
|
22841
|
-
seenProviders.add(p);
|
|
22842
|
-
return true;
|
|
22843
|
-
});
|
|
22844
|
-
const actionSet = new Set(
|
|
22845
|
-
agg ? agg.actionsTaken.map(toApiAction) : instances.map((i) => i.action)
|
|
22846
|
-
);
|
|
22860
|
+
const types = [];
|
|
22861
|
+
for (const [ruleId, agg] of aggregates) {
|
|
22862
|
+
const users = sortUsers(agg.users ?? []);
|
|
22863
|
+
const providers = [...new Set(agg.sourceTools.map(toApiProvider))].sort();
|
|
22864
|
+
const actionSet = new Set(agg.actionsTaken.map(toApiAction));
|
|
22847
22865
|
const aggregateAction = actionSet.size === 1 ? [...actionSet][0] ?? null : null;
|
|
22848
|
-
const
|
|
22849
|
-
const
|
|
22850
|
-
id: ruleId,
|
|
22851
|
-
name: packNames?.get(ruleId) ?? null
|
|
22852
|
-
};
|
|
22853
|
-
const apiCategory = toApiCategory(ruleRows[0]?.category ?? "custom");
|
|
22854
|
-
const policy = { id: `category:${apiCategory}`, name: apiCategory };
|
|
22855
|
-
const match = {
|
|
22856
|
-
maskedValue: ruleRows[0]?.maskedMatch ?? "",
|
|
22857
|
-
contextPrefix: ""
|
|
22858
|
-
// empty (pending privacy review)
|
|
22859
|
-
};
|
|
22860
|
-
const status = foldGroupStatus(
|
|
22861
|
-
agg ? agg.statusInputs.map(deriveFindingStatus) : instances.map((i) => i.status)
|
|
22862
|
-
);
|
|
22863
|
-
const group = {
|
|
22866
|
+
const apiCategory = toApiCategory(agg.category ?? "custom");
|
|
22867
|
+
const type = {
|
|
22864
22868
|
id: ruleId,
|
|
22865
22869
|
category: apiCategory,
|
|
22866
22870
|
subtype: ruleId,
|
|
22867
22871
|
// human label comes with pack metadata later
|
|
22868
|
-
severity,
|
|
22869
|
-
|
|
22870
|
-
|
|
22871
|
-
|
|
22872
|
-
instanceCount: agg?.instanceCount ?? instances.length,
|
|
22872
|
+
severity: agg.severity ?? "low",
|
|
22873
|
+
detection: { id: ruleId, name: packNames?.get(ruleId) ?? null },
|
|
22874
|
+
policy: { id: `category:${apiCategory}`, name: apiCategory },
|
|
22875
|
+
instanceCount: agg.instanceCount,
|
|
22873
22876
|
providers,
|
|
22874
22877
|
aggregateAction,
|
|
22875
|
-
latestDetectedAt,
|
|
22876
|
-
|
|
22877
|
-
status,
|
|
22878
|
+
latestDetectedAt: agg.latestDetectedAt,
|
|
22879
|
+
status: foldGroupStatus(agg.statusInputs.map(deriveFindingStatus)),
|
|
22878
22880
|
...users.length > 0 ? { users } : {}
|
|
22879
22881
|
};
|
|
22880
|
-
|
|
22881
|
-
|
|
22882
|
-
|
|
22883
|
-
haystackCache.set(group, buildHaystack(group, agg.searchText));
|
|
22884
|
-
}
|
|
22882
|
+
actionsCache.set(type, [...actionSet]);
|
|
22883
|
+
if (agg.searchText !== void 0) {
|
|
22884
|
+
haystackCache.set(type, buildHaystack(type, agg.searchText));
|
|
22885
22885
|
}
|
|
22886
|
-
|
|
22886
|
+
types.push(type);
|
|
22887
22887
|
}
|
|
22888
|
-
return
|
|
22888
|
+
return types;
|
|
22889
22889
|
}
|
|
22890
22890
|
var haystackCache = /* @__PURE__ */ new WeakMap();
|
|
22891
|
-
function buildHaystack(
|
|
22891
|
+
function buildHaystack(t, extra) {
|
|
22892
22892
|
return [
|
|
22893
|
-
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
|
|
22897
|
-
|
|
22898
|
-
...g.instances.map((i) => i.repo),
|
|
22899
|
-
...g.instances.map((i) => i.file),
|
|
22900
|
-
...g.instances.map((i) => i.toolName ? `via ${i.toolName}` : ""),
|
|
22901
|
-
...g.instances.map((i) => i.id),
|
|
22902
|
-
// The people: the whole group's list when the store folded one, plus the
|
|
22903
|
-
// preview's own — the two overlap, and a haystack does not mind.
|
|
22904
|
-
...(g.users ?? []).map((u) => u.name),
|
|
22905
|
-
...g.instances.map((i) => i.user?.name ?? ""),
|
|
22893
|
+
t.subtype,
|
|
22894
|
+
t.category,
|
|
22895
|
+
t.policy.name,
|
|
22896
|
+
t.id,
|
|
22897
|
+
...(t.users ?? []).map((u) => u.name),
|
|
22906
22898
|
...extra === void 0 ? [] : [extra]
|
|
22907
22899
|
].join(" ").toLowerCase();
|
|
22908
22900
|
}
|
|
22909
|
-
function
|
|
22910
|
-
const cached2 = haystackCache.get(
|
|
22901
|
+
function typeHaystack(t) {
|
|
22902
|
+
const cached2 = haystackCache.get(t);
|
|
22911
22903
|
if (cached2 !== void 0) return cached2;
|
|
22912
|
-
const haystack = buildHaystack(
|
|
22913
|
-
haystackCache.set(
|
|
22904
|
+
const haystack = buildHaystack(t);
|
|
22905
|
+
haystackCache.set(t, haystack);
|
|
22914
22906
|
return haystack;
|
|
22915
22907
|
}
|
|
22916
22908
|
var actionsCache = /* @__PURE__ */ new WeakMap();
|
|
22917
|
-
function
|
|
22918
|
-
|
|
22919
|
-
if (cached2 !== void 0) return cached2;
|
|
22920
|
-
const actions = [...new Set(g.instances.map((i) => i.action))];
|
|
22921
|
-
actionsCache.set(g, actions);
|
|
22922
|
-
return actions;
|
|
22909
|
+
function typeActions(t) {
|
|
22910
|
+
return actionsCache.get(t) ?? [];
|
|
22923
22911
|
}
|
|
22924
22912
|
function countInstancesByStatus(statusInputs, statuses) {
|
|
22925
22913
|
const statusSet = new Set(statuses);
|
|
@@ -22930,8 +22918,8 @@ function countInstancesByStatus(statusInputs, statuses) {
|
|
|
22930
22918
|
}
|
|
22931
22919
|
return sum;
|
|
22932
22920
|
}
|
|
22933
|
-
function applyFindingFilters(
|
|
22934
|
-
let filtered =
|
|
22921
|
+
function applyFindingFilters(types, opts) {
|
|
22922
|
+
let filtered = types;
|
|
22935
22923
|
if (opts.severity && opts.severity.length > 0) {
|
|
22936
22924
|
const sevSet = new Set(opts.severity);
|
|
22937
22925
|
filtered = filtered.filter((g) => sevSet.has(g.severity));
|
|
@@ -22942,7 +22930,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22942
22930
|
}
|
|
22943
22931
|
if (opts.actions && opts.actions.length > 0) {
|
|
22944
22932
|
const actionSet = new Set(opts.actions);
|
|
22945
|
-
filtered = filtered.filter((
|
|
22933
|
+
filtered = filtered.filter((t) => typeActions(t).some((a) => actionSet.has(a)));
|
|
22946
22934
|
}
|
|
22947
22935
|
if (opts.subtype && opts.subtype.length > 0) {
|
|
22948
22936
|
const subtypeSet = new Set(opts.subtype);
|
|
@@ -22954,7 +22942,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22954
22942
|
}
|
|
22955
22943
|
if (opts.q) {
|
|
22956
22944
|
const q = opts.q.toLowerCase();
|
|
22957
|
-
filtered = filtered.filter((
|
|
22945
|
+
filtered = filtered.filter((t) => typeHaystack(t).includes(q));
|
|
22958
22946
|
}
|
|
22959
22947
|
return filtered;
|
|
22960
22948
|
}
|
|
@@ -22969,11 +22957,11 @@ function compareFindingGroupOrder(a, b) {
|
|
|
22969
22957
|
if (recencyDiff !== 0) return recencyDiff;
|
|
22970
22958
|
return a.id.localeCompare(b.id);
|
|
22971
22959
|
}
|
|
22972
|
-
function
|
|
22973
|
-
return [...
|
|
22960
|
+
function sortFindingTypes(types) {
|
|
22961
|
+
return [...types].sort(compareFindingGroupOrder);
|
|
22974
22962
|
}
|
|
22975
|
-
function computeFindingFacets(
|
|
22976
|
-
const forSeverity = applyFindingFilters(
|
|
22963
|
+
function computeFindingFacets(allTypes, opts) {
|
|
22964
|
+
const forSeverity = applyFindingFilters(allTypes, {
|
|
22977
22965
|
providers: opts.providers,
|
|
22978
22966
|
actions: opts.actions,
|
|
22979
22967
|
statuses: opts.statuses,
|
|
@@ -22984,7 +22972,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22984
22972
|
for (const g of forSeverity) {
|
|
22985
22973
|
severityMap.set(g.severity, (severityMap.get(g.severity) ?? 0) + 1);
|
|
22986
22974
|
}
|
|
22987
|
-
const forProvider = applyFindingFilters(
|
|
22975
|
+
const forProvider = applyFindingFilters(allTypes, {
|
|
22988
22976
|
actions: opts.actions,
|
|
22989
22977
|
statuses: opts.statuses,
|
|
22990
22978
|
q: opts.q,
|
|
@@ -22995,7 +22983,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22995
22983
|
for (const g of forProvider) {
|
|
22996
22984
|
for (const p of g.providers) providerMap.set(p, (providerMap.get(p) ?? 0) + 1);
|
|
22997
22985
|
}
|
|
22998
|
-
const forAction = applyFindingFilters(
|
|
22986
|
+
const forAction = applyFindingFilters(allTypes, {
|
|
22999
22987
|
providers: opts.providers,
|
|
23000
22988
|
statuses: opts.statuses,
|
|
23001
22989
|
q: opts.q,
|
|
@@ -23004,9 +22992,9 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23004
22992
|
});
|
|
23005
22993
|
const actionMap = /* @__PURE__ */ new Map();
|
|
23006
22994
|
for (const g of forAction) {
|
|
23007
|
-
for (const a of
|
|
22995
|
+
for (const a of typeActions(g)) actionMap.set(a, (actionMap.get(a) ?? 0) + 1);
|
|
23008
22996
|
}
|
|
23009
|
-
const forSubtype = applyFindingFilters(
|
|
22997
|
+
const forSubtype = applyFindingFilters(allTypes, {
|
|
23010
22998
|
providers: opts.providers,
|
|
23011
22999
|
actions: opts.actions,
|
|
23012
23000
|
statuses: opts.statuses,
|
|
@@ -23015,7 +23003,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23015
23003
|
});
|
|
23016
23004
|
const subtypeMap = /* @__PURE__ */ new Map();
|
|
23017
23005
|
for (const g of forSubtype) subtypeMap.set(g.subtype, (subtypeMap.get(g.subtype) ?? 0) + 1);
|
|
23018
|
-
const forStatus = applyFindingFilters(
|
|
23006
|
+
const forStatus = applyFindingFilters(allTypes, {
|
|
23019
23007
|
providers: opts.providers,
|
|
23020
23008
|
actions: opts.actions,
|
|
23021
23009
|
q: opts.q,
|
|
@@ -23063,10 +23051,20 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23063
23051
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23064
23052
|
case "tools":
|
|
23065
23053
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23054
|
+
// An EMPTY value is a real filter here, not an absent one. The location
|
|
23055
|
+
// list buckets a finding whose event recorded no repo — or no file — under
|
|
23056
|
+
// the empty string, and selecting that bucket has to narrow the panel to
|
|
23057
|
+
// exactly it. Only `undefined` means "no filter"; a caller that wants every
|
|
23058
|
+
// row omits the key, which every call site already does.
|
|
23059
|
+
//
|
|
23060
|
+
// Reading '' as unset is what this replaced, and it failed in the one place
|
|
23061
|
+
// it mattered: the no-repo/no-file bucket is often the largest in a real
|
|
23062
|
+
// store, and its panel dropped both predicates and returned the WHOLE scope
|
|
23063
|
+
// — a row reading 3 findings beside a panel listing every finding there is.
|
|
23066
23064
|
case "repo":
|
|
23067
|
-
return opts.repo === void 0 ||
|
|
23065
|
+
return opts.repo === void 0 || row.repo === opts.repo;
|
|
23068
23066
|
case "file":
|
|
23069
|
-
return opts.file === void 0 ||
|
|
23067
|
+
return opts.file === void 0 || row.file === opts.file;
|
|
23070
23068
|
case "q":
|
|
23071
23069
|
return !opts.q || rowHaystack(row).includes(opts.q.toLowerCase());
|
|
23072
23070
|
}
|
|
@@ -23180,6 +23178,23 @@ function addToLocation(acc, row) {
|
|
|
23180
23178
|
acc.statuses.push(row.status);
|
|
23181
23179
|
acc.ruleIds.add(row.ruleId);
|
|
23182
23180
|
}
|
|
23181
|
+
function compareLocationOrder(a, b) {
|
|
23182
|
+
const rankA = SEVERITY_ORDER2[a.maxSeverity] ?? -1;
|
|
23183
|
+
const rankB = SEVERITY_ORDER2[b.maxSeverity] ?? -1;
|
|
23184
|
+
if (rankA !== rankB) return rankA - rankB;
|
|
23185
|
+
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23186
|
+
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23187
|
+
}
|
|
23188
|
+
if (a.repo !== b.repo) return a.repo < b.repo ? -1 : 1;
|
|
23189
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
23190
|
+
return 0;
|
|
23191
|
+
}
|
|
23192
|
+
function encodeLocationId(repo, file2) {
|
|
23193
|
+
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
23194
|
+
}
|
|
23195
|
+
function encodePart(value) {
|
|
23196
|
+
return encodeURIComponent(value.replace(/[\uD800-\uDFFF]/gu, "\uFFFD"));
|
|
23197
|
+
}
|
|
23183
23198
|
|
|
23184
23199
|
// ../../packages/schema/src/zod/installed-pack.ts
|
|
23185
23200
|
var InstalledPack = external_exports.object({
|
|
@@ -23694,11 +23709,11 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23694
23709
|
// covers the current payload and must be re-granted.
|
|
23695
23710
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23696
23711
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23697
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23698
|
-
// that covers
|
|
23699
|
-
// carry prompt/reply text in `content
|
|
23700
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23701
|
-
// payload no longer counts.
|
|
23712
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23713
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23714
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23715
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23716
|
+
// or an older payload no longer counts.
|
|
23702
23717
|
historySyncConsent: HistorySyncConsent.optional()
|
|
23703
23718
|
});
|
|
23704
23719
|
function defaultWorkspaceSettings() {
|
|
@@ -23829,6 +23844,9 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23829
23844
|
"dataSharesInPlace",
|
|
23830
23845
|
"redactFallback"
|
|
23831
23846
|
]).meta({ id: "ManagedSettingKey" });
|
|
23847
|
+
function isManagedSettingKey(value) {
|
|
23848
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
23849
|
+
}
|
|
23832
23850
|
var ManagedSettingsValues = external_exports.object({
|
|
23833
23851
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
23834
23852
|
controlPlane: external_exports.object({
|
|
@@ -23853,7 +23871,27 @@ var ManagedSettings = external_exports.object({
|
|
|
23853
23871
|
// Which of those the user may not change. A key here with no matching value
|
|
23854
23872
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23855
23873
|
// the user may still override. The two are separable on purpose.
|
|
23856
|
-
|
|
23874
|
+
//
|
|
23875
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
23876
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
23877
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
23878
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
23879
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
23880
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23881
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
23882
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23883
|
+
}).transform(({ lockedFields, ...rest }) => {
|
|
23884
|
+
const known = [];
|
|
23885
|
+
const unknown2 = [];
|
|
23886
|
+
for (const name of lockedFields) {
|
|
23887
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
23888
|
+
else unknown2.push(name);
|
|
23889
|
+
}
|
|
23890
|
+
return {
|
|
23891
|
+
...rest,
|
|
23892
|
+
lockedFields: known,
|
|
23893
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
23894
|
+
};
|
|
23857
23895
|
}).meta({ id: "ManagedSettings" });
|
|
23858
23896
|
var NO_MANAGED_CONTEXT = { present: false, lockedFields: [] };
|
|
23859
23897
|
|
|
@@ -23978,7 +24016,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23978
24016
|
timestamp: external_exports.iso.date(),
|
|
23979
24017
|
critical: external_exports.number().int().nonnegative(),
|
|
23980
24018
|
high: external_exports.number().int().nonnegative(),
|
|
23981
|
-
medium: external_exports.number().int().nonnegative()
|
|
24019
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24020
|
+
// Optional and additive, so a producer written against the earlier
|
|
24021
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24022
|
+
// absent case itself — the chart point requires a number.
|
|
24023
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23982
24024
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23983
24025
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23984
24026
|
range: TimeRange,
|
|
@@ -24004,6 +24046,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24004
24046
|
findingKey: external_exports.string(),
|
|
24005
24047
|
ruleId: external_exports.string(),
|
|
24006
24048
|
severity: Severity,
|
|
24049
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24050
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24051
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24052
|
+
repo: external_exports.string().optional(),
|
|
24007
24053
|
path: external_exports.string(),
|
|
24008
24054
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24009
24055
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -25429,7 +25475,8 @@ var SqliteActivityRepository = class {
|
|
|
25429
25475
|
SELECT 1 FROM audit_events d
|
|
25430
25476
|
WHERE d.root_session_id = audit_events.id
|
|
25431
25477
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25432
|
-
OR json_extract(d.attributes, '$.detail')
|
|
25478
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
25479
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25433
25480
|
);
|
|
25434
25481
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25435
25482
|
}
|
|
@@ -26767,23 +26814,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26767
26814
|
)`;
|
|
26768
26815
|
|
|
26769
26816
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26770
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26771
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26772
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26773
|
-
function compareLocationOrder(a, b) {
|
|
26774
|
-
return compareFindingGroupOrder(
|
|
26775
|
-
{
|
|
26776
|
-
severity: a.maxSeverity,
|
|
26777
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26778
|
-
id: ""
|
|
26779
|
-
},
|
|
26780
|
-
{
|
|
26781
|
-
severity: b.maxSeverity,
|
|
26782
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26783
|
-
id: ""
|
|
26784
|
-
}
|
|
26785
|
-
);
|
|
26786
|
-
}
|
|
26787
26817
|
var CONCAT_SEP = ",";
|
|
26788
26818
|
var TUPLE_SEP = "|";
|
|
26789
26819
|
function splitConcat(value) {
|
|
@@ -26835,13 +26865,48 @@ function decodeGroupCursor(cursor) {
|
|
|
26835
26865
|
return null;
|
|
26836
26866
|
}
|
|
26837
26867
|
function firstAfter(sorted, cursor) {
|
|
26838
|
-
const index = sorted.findIndex((
|
|
26868
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26839
26869
|
return index === -1 ? sorted.length : index;
|
|
26840
26870
|
}
|
|
26841
26871
|
function findDeepLinked(sorted, page, id) {
|
|
26842
|
-
if (page.some((
|
|
26843
|
-
return sorted.find((
|
|
26872
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
26873
|
+
return sorted.find((t) => t.id === id);
|
|
26844
26874
|
}
|
|
26875
|
+
function encodeLocationCursor(location) {
|
|
26876
|
+
const payload = {
|
|
26877
|
+
sev: location.maxSeverity,
|
|
26878
|
+
t: location.latestDetectedAt,
|
|
26879
|
+
r: location.repo,
|
|
26880
|
+
f: location.file
|
|
26881
|
+
};
|
|
26882
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
26883
|
+
}
|
|
26884
|
+
function decodeLocationCursor(cursor) {
|
|
26885
|
+
const parsed = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
26886
|
+
if (parsed !== void 0 && typeof parsed.sev === "string" && typeof parsed.t === "string" && typeof parsed.r === "string" && typeof parsed.f === "string") {
|
|
26887
|
+
return { maxSeverity: parsed.sev, latestDetectedAt: parsed.t, repo: parsed.r, file: parsed.f };
|
|
26888
|
+
}
|
|
26889
|
+
return null;
|
|
26890
|
+
}
|
|
26891
|
+
function firstLocationAfter(sorted, cursor) {
|
|
26892
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
26893
|
+
return index === -1 ? sorted.length : index;
|
|
26894
|
+
}
|
|
26895
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
26896
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
26897
|
+
return sorted.find((l) => l.id === id);
|
|
26898
|
+
}
|
|
26899
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
26900
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
26901
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
26902
|
+
e.started_at AS occurred_at,
|
|
26903
|
+
e.source_tool AS source_tool,
|
|
26904
|
+
e.repo AS repo,
|
|
26905
|
+
e.file_path AS file,
|
|
26906
|
+
e.tool_name AS tool_name,
|
|
26907
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
26908
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
26909
|
+
${latestResolutionStatusSql("f")} AS latest_status`;
|
|
26845
26910
|
var DAY_MS3 = 864e5;
|
|
26846
26911
|
var SqliteFindingsRepository = class {
|
|
26847
26912
|
constructor(db) {
|
|
@@ -26962,30 +27027,26 @@ var SqliteFindingsRepository = class {
|
|
|
26962
27027
|
);
|
|
26963
27028
|
}
|
|
26964
27029
|
/**
|
|
26965
|
-
*
|
|
26966
|
-
*
|
|
26967
|
-
*
|
|
26968
|
-
*
|
|
26969
|
-
*
|
|
26970
|
-
*
|
|
26971
|
-
*
|
|
26972
|
-
*
|
|
26973
|
-
*
|
|
26974
|
-
*
|
|
26975
|
-
*
|
|
26976
|
-
*
|
|
27030
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
27031
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
27032
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
27033
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
27034
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
27035
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
27036
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
27037
|
+
* derived status was requested.
|
|
27038
|
+
*
|
|
27039
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
27040
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
27041
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
27042
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
27043
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
26977
27044
|
*
|
|
26978
|
-
* Two reads, neither of which materializes a row per finding:
|
|
26979
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
26980
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
26981
|
-
* latest, search text);
|
|
26982
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
26983
|
-
* populate `instances` for the table's expanded rows.
|
|
26984
27045
|
* The aggregates carry raw DB values and are translated by the same
|
|
26985
|
-
* @akasecurity/schema mappers
|
|
26986
|
-
* rule is ever restated in SQL.
|
|
27046
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
27047
|
+
* status rule is ever restated in SQL.
|
|
26987
27048
|
*/
|
|
26988
|
-
|
|
27049
|
+
listFindingTypes(query) {
|
|
26989
27050
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
26990
27051
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
26991
27052
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -26998,12 +27059,7 @@ var SqliteFindingsRepository = class {
|
|
|
26998
27059
|
predicate,
|
|
26999
27060
|
params: sessionParams
|
|
27000
27061
|
});
|
|
27001
|
-
const
|
|
27002
|
-
sessionId: query.sessionId,
|
|
27003
|
-
from: query.from
|
|
27004
|
-
});
|
|
27005
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27006
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
27062
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27007
27063
|
const filterOpts = {
|
|
27008
27064
|
severity: query.severity,
|
|
27009
27065
|
providers: query.provider,
|
|
@@ -27012,30 +27068,25 @@ var SqliteFindingsRepository = class {
|
|
|
27012
27068
|
subtype: query.subtype,
|
|
27013
27069
|
q: query.q
|
|
27014
27070
|
};
|
|
27015
|
-
const facets = computeFindingFacets(
|
|
27016
|
-
const sorted =
|
|
27071
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
27072
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27017
27073
|
const statusFilter = query.status ?? [];
|
|
27018
27074
|
const totals = {
|
|
27019
|
-
findings: sorted.reduce((acc,
|
|
27020
|
-
if (statusFilter.length === 0) return acc +
|
|
27021
|
-
const agg = aggregates.get(
|
|
27022
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
27075
|
+
findings: sorted.reduce((acc, t) => {
|
|
27076
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
27077
|
+
const agg = aggregates.get(t.id);
|
|
27078
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27023
27079
|
}, 0),
|
|
27024
|
-
|
|
27080
|
+
types: sorted.length
|
|
27025
27081
|
};
|
|
27026
|
-
const limit = query.limit ??
|
|
27082
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27027
27083
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27028
27084
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27029
27085
|
const page = sorted.slice(start, start + limit);
|
|
27030
27086
|
const lastOnPage = page.at(-1);
|
|
27031
27087
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27032
27088
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27033
|
-
const
|
|
27034
|
-
const narrow = (g) => statusSet ? {
|
|
27035
|
-
...g,
|
|
27036
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27037
|
-
} : g;
|
|
27038
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
27089
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27039
27090
|
return Promise.resolve({
|
|
27040
27091
|
totals,
|
|
27041
27092
|
facets,
|
|
@@ -27046,7 +27097,7 @@ var SqliteFindingsRepository = class {
|
|
|
27046
27097
|
}
|
|
27047
27098
|
/**
|
|
27048
27099
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27049
|
-
*
|
|
27100
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27050
27101
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27051
27102
|
*
|
|
27052
27103
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27140,13 +27191,25 @@ var SqliteFindingsRepository = class {
|
|
|
27140
27191
|
});
|
|
27141
27192
|
}
|
|
27142
27193
|
/**
|
|
27143
|
-
* The same findings folded by
|
|
27194
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27144
27195
|
*
|
|
27145
27196
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27146
|
-
* the local store relates a finding to
|
|
27147
|
-
*
|
|
27148
|
-
* empty-string bucket, which
|
|
27149
|
-
*
|
|
27197
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
27198
|
+
* by instead. A repo or file the event did not record folds into the
|
|
27199
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
27200
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
27201
|
+
*
|
|
27202
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
27203
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
27204
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
27205
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
27206
|
+
* place.
|
|
27207
|
+
*
|
|
27208
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
27209
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
27210
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
27211
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
27212
|
+
* its fields.
|
|
27150
27213
|
*/
|
|
27151
27214
|
listFindingLocations(query) {
|
|
27152
27215
|
const opts = {
|
|
@@ -27158,13 +27221,16 @@ var SqliteFindingsRepository = class {
|
|
|
27158
27221
|
tools: query.tool,
|
|
27159
27222
|
q: query.q
|
|
27160
27223
|
};
|
|
27161
|
-
const limit = query.limit ??
|
|
27224
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
27225
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27162
27226
|
const byRepo = /* @__PURE__ */ new Map();
|
|
27227
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27163
27228
|
let total = 0;
|
|
27164
27229
|
for (const row of this.scanFindingRows({
|
|
27165
27230
|
sessionId: query.sessionId,
|
|
27166
27231
|
from: query.from
|
|
27167
27232
|
})) {
|
|
27233
|
+
accumulator.add(row);
|
|
27168
27234
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27169
27235
|
total += 1;
|
|
27170
27236
|
let files = byRepo.get(row.repo);
|
|
@@ -27179,103 +27245,35 @@ var SqliteFindingsRepository = class {
|
|
|
27179
27245
|
}
|
|
27180
27246
|
addToLocation(acc, row);
|
|
27181
27247
|
}
|
|
27182
|
-
|
|
27183
|
-
const
|
|
27184
|
-
|
|
27185
|
-
|
|
27186
|
-
|
|
27187
|
-
|
|
27188
|
-
|
|
27189
|
-
|
|
27190
|
-
|
|
27191
|
-
|
|
27192
|
-
|
|
27193
|
-
|
|
27194
|
-
|
|
27195
|
-
|
|
27196
|
-
|
|
27197
|
-
|
|
27198
|
-
|
|
27199
|
-
|
|
27200
|
-
|
|
27201
|
-
|
|
27202
|
-
|
|
27203
|
-
|
|
27204
|
-
);
|
|
27205
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27206
|
-
const folded = foldGroupStatus(statuses);
|
|
27207
|
-
return {
|
|
27208
|
-
repo,
|
|
27209
|
-
instanceCount: rollup.instanceCount,
|
|
27210
|
-
maxSeverity: rollup.maxSeverity,
|
|
27211
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27212
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27213
|
-
files: fileRows
|
|
27214
|
-
};
|
|
27215
|
-
});
|
|
27216
|
-
repos.sort(compareLocationOrder);
|
|
27248
|
+
const sorted = [];
|
|
27249
|
+
for (const [repo, files] of byRepo) {
|
|
27250
|
+
for (const [file2, acc] of files) {
|
|
27251
|
+
const status = foldGroupStatus(acc.statuses);
|
|
27252
|
+
sorted.push({
|
|
27253
|
+
id: encodeLocationId(repo, file2),
|
|
27254
|
+
repo,
|
|
27255
|
+
file: file2,
|
|
27256
|
+
instanceCount: acc.instanceCount,
|
|
27257
|
+
maxSeverity: acc.maxSeverity,
|
|
27258
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
27259
|
+
...status === void 0 ? {} : { status },
|
|
27260
|
+
ruleIds: [...acc.ruleIds]
|
|
27261
|
+
});
|
|
27262
|
+
}
|
|
27263
|
+
}
|
|
27264
|
+
sorted.sort(compareLocationOrder);
|
|
27265
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
27266
|
+
const page = sorted.slice(start, start + limit);
|
|
27267
|
+
const lastOnPage = page.at(-1);
|
|
27268
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
27269
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27217
27270
|
return Promise.resolve({
|
|
27218
|
-
totals: { findings: total,
|
|
27219
|
-
|
|
27220
|
-
|
|
27271
|
+
totals: { findings: total, locations: sorted.length },
|
|
27272
|
+
facets: accumulator.facets(),
|
|
27273
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
27274
|
+
nextCursor
|
|
27221
27275
|
});
|
|
27222
27276
|
}
|
|
27223
|
-
/**
|
|
27224
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27225
|
-
*
|
|
27226
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27227
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27228
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27229
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27230
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27231
|
-
* store while the answer does not.
|
|
27232
|
-
*
|
|
27233
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27234
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27235
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27236
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27237
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27238
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27239
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27240
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27241
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27242
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27243
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27244
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27245
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27246
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27247
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27248
|
-
* sort of the scope, which is still that floor.
|
|
27249
|
-
*
|
|
27250
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27251
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27252
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27253
|
-
* built from.
|
|
27254
|
-
*/
|
|
27255
|
-
previewRows(aggregates, scope) {
|
|
27256
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27257
|
-
let remaining = 0;
|
|
27258
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27259
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27260
|
-
wanted.set(ruleId, n);
|
|
27261
|
-
remaining += n;
|
|
27262
|
-
}
|
|
27263
|
-
const rows = [];
|
|
27264
|
-
if (remaining === 0) return rows;
|
|
27265
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27266
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27267
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27268
|
-
const want = wanted.get(r.rule_id);
|
|
27269
|
-
if (want === void 0) continue;
|
|
27270
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27271
|
-
if (have >= want) continue;
|
|
27272
|
-
taken.set(r.rule_id, have + 1);
|
|
27273
|
-
rows.push(r);
|
|
27274
|
-
remaining -= 1;
|
|
27275
|
-
if (remaining === 0) break;
|
|
27276
|
-
}
|
|
27277
|
-
return rows;
|
|
27278
|
-
}
|
|
27279
27277
|
/**
|
|
27280
27278
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27281
27279
|
*
|
|
@@ -27302,6 +27300,33 @@ var SqliteFindingsRepository = class {
|
|
|
27302
27300
|
yield toFlatFindingRow(r);
|
|
27303
27301
|
}
|
|
27304
27302
|
}
|
|
27303
|
+
/**
|
|
27304
|
+
* One finding by its own id, or null when no such row exists.
|
|
27305
|
+
*
|
|
27306
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
27307
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
27308
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
27309
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
27310
|
+
* older than anything a first page holds.
|
|
27311
|
+
*
|
|
27312
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
27313
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
27314
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
27315
|
+
* worse than showing it.
|
|
27316
|
+
*
|
|
27317
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
27318
|
+
* type should the list select?" and "what does the drawer show?".
|
|
27319
|
+
*/
|
|
27320
|
+
findingInstance(id) {
|
|
27321
|
+
const row = this.db.prepare(
|
|
27322
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27323
|
+
FROM inspection_findings f
|
|
27324
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
27325
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27326
|
+
WHERE f.id = ?`
|
|
27327
|
+
).get(id);
|
|
27328
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
27329
|
+
}
|
|
27305
27330
|
/**
|
|
27306
27331
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27307
27332
|
* joined to its event and definition, newest first.
|
|
@@ -27335,17 +27360,7 @@ var SqliteFindingsRepository = class {
|
|
|
27335
27360
|
conditions.push("e.started_at >= ?");
|
|
27336
27361
|
params.push(isoToEpochMillis(scope.from));
|
|
27337
27362
|
}
|
|
27338
|
-
const sql = `SELECT
|
|
27339
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27340
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27341
|
-
e.started_at AS occurred_at,
|
|
27342
|
-
e.source_tool AS source_tool,
|
|
27343
|
-
e.repo AS repo,
|
|
27344
|
-
e.file_path AS file,
|
|
27345
|
-
e.tool_name AS tool_name,
|
|
27346
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27347
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27348
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
27363
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27349
27364
|
FROM audit_events e
|
|
27350
27365
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27351
27366
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27359,6 +27374,26 @@ var SqliteFindingsRepository = class {
|
|
|
27359
27374
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27360
27375
|
const rows = this.db.prepare(
|
|
27361
27376
|
`SELECT rule_id,
|
|
27377
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
27378
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
27379
|
+
-- in an aggregate query, every bare column takes its value from
|
|
27380
|
+
-- the row that produced the extremum. So these are the severity
|
|
27381
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
27382
|
+
-- is what the row-based build they replaced read off its first
|
|
27383
|
+
-- (newest-first) row.
|
|
27384
|
+
--
|
|
27385
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
27386
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
27387
|
+
-- mints a new row), so a rule whose severity moved between
|
|
27388
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
27389
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
27390
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
27391
|
+
-- filter, the facet counts and the primary sort key.
|
|
27392
|
+
--
|
|
27393
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
27394
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
27395
|
+
severity,
|
|
27396
|
+
category,
|
|
27362
27397
|
sum(tuple_count) AS instance_count,
|
|
27363
27398
|
max(latest_at) AS latest_at,
|
|
27364
27399
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27369,6 +27404,14 @@ var SqliteFindingsRepository = class {
|
|
|
27369
27404
|
group_concat(tool_names) AS tool_names
|
|
27370
27405
|
FROM (
|
|
27371
27406
|
SELECT d.rule_id AS rule_id,
|
|
27407
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
27408
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
27409
|
+
-- these are grouped on below and resolved to the newest
|
|
27410
|
+
-- firing version by the outer query's bare-column select.
|
|
27411
|
+
-- They ride the aggregate because the type build has no rows
|
|
27412
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
27413
|
+
d.severity AS severity,
|
|
27414
|
+
d.category AS category,
|
|
27372
27415
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27373
27416
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27374
27417
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27383,7 +27426,7 @@ var SqliteFindingsRepository = class {
|
|
|
27383
27426
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27384
27427
|
ON latest.finding_key = f.finding_key
|
|
27385
27428
|
${scope.predicate}
|
|
27386
|
-
GROUP BY d.rule_id, status_tuple
|
|
27429
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27387
27430
|
)
|
|
27388
27431
|
GROUP BY rule_id`
|
|
27389
27432
|
).all(scope.params);
|
|
@@ -27392,6 +27435,8 @@ var SqliteFindingsRepository = class {
|
|
|
27392
27435
|
r.rule_id,
|
|
27393
27436
|
{
|
|
27394
27437
|
instanceCount: r.instance_count,
|
|
27438
|
+
severity: r.severity,
|
|
27439
|
+
category: r.category,
|
|
27395
27440
|
sourceTools: splitConcat(r.source_tools),
|
|
27396
27441
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27397
27442
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27408,7 +27453,7 @@ var SqliteFindingsRepository = class {
|
|
|
27408
27453
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27409
27454
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27410
27455
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27411
|
-
// Left undefined (not '') when unfetched, so
|
|
27456
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27412
27457
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27413
27458
|
// and skip priming a haystack nothing will read.
|
|
27414
27459
|
...withSearchText ? {
|
|
@@ -27560,6 +27605,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
27560
27605
|
this.markOwedStmt = db.prepare(
|
|
27561
27606
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27562
27607
|
);
|
|
27608
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27609
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
27610
|
+
WHERE synced_at IS NULL
|
|
27611
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27612
|
+
AND started_at < :before`
|
|
27613
|
+
);
|
|
27563
27614
|
this.stampStmt = db.prepare(
|
|
27564
27615
|
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27565
27616
|
);
|
|
@@ -27608,7 +27659,9 @@ var SqliteHistorySyncRepository = class {
|
|
|
27608
27659
|
);
|
|
27609
27660
|
this.disownCapturesStmt = db.prepare(
|
|
27610
27661
|
`UPDATE audit_events SET outbox_owed = NULL
|
|
27611
|
-
WHERE outbox_owed IS NOT NULL
|
|
27662
|
+
WHERE outbox_owed IS NOT NULL
|
|
27663
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27664
|
+
AND started_at < :attachedAt`
|
|
27612
27665
|
);
|
|
27613
27666
|
this.rearmStmt = db.prepare(
|
|
27614
27667
|
`UPDATE audit_events SET synced_at = NULL
|
|
@@ -27684,6 +27737,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27684
27737
|
freezeBoundaryStmt;
|
|
27685
27738
|
captureRowsStmt;
|
|
27686
27739
|
markOwedStmt;
|
|
27740
|
+
markCaptureBacklogOwedStmt;
|
|
27687
27741
|
captureSkipCountStmt;
|
|
27688
27742
|
disownCapturesStmt;
|
|
27689
27743
|
partitionStmt;
|
|
@@ -27747,6 +27801,23 @@ var SqliteHistorySyncRepository = class {
|
|
|
27747
27801
|
markCaptureOwed(id) {
|
|
27748
27802
|
this.markOwedStmt.run({ id });
|
|
27749
27803
|
}
|
|
27804
|
+
/**
|
|
27805
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
27806
|
+
*
|
|
27807
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
27808
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27809
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
27810
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27811
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27812
|
+
* later re-attach or key rotation might widen it to.
|
|
27813
|
+
*
|
|
27814
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27815
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27816
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27817
|
+
*/
|
|
27818
|
+
markCaptureBacklogOwed(before) {
|
|
27819
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27820
|
+
}
|
|
27750
27821
|
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27751
27822
|
markSynced(ids, atMs) {
|
|
27752
27823
|
this.stampAll(ids, atMs);
|
|
@@ -27863,15 +27934,42 @@ var SqliteHistorySyncRepository = class {
|
|
|
27863
27934
|
*
|
|
27864
27935
|
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
27865
27936
|
* machine has just left are undelivered as far as the new one is concerned.
|
|
27866
|
-
* All
|
|
27867
|
-
* attributed to the wrong deployment,
|
|
27937
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
27938
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
27939
|
+
* a disown with no re-mark to follow it.
|
|
27868
27940
|
*
|
|
27869
27941
|
* The boundary is written HERE and only here, which is what freezes it: a
|
|
27870
27942
|
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
27871
27943
|
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
27872
27944
|
* the live path has since delivered.
|
|
27945
|
+
*
|
|
27946
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
27947
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
27948
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
27949
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
27950
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
27951
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
27952
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
27953
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
27954
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
27955
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
27956
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
27957
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
27958
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
27959
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
27960
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
27961
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
27962
|
+
*
|
|
27963
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
27964
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
27965
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
27966
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
27967
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
27968
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
27969
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
27970
|
+
* transaction above.
|
|
27873
27971
|
*/
|
|
27874
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
27972
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
27875
27973
|
this.ensureRowStmt.run();
|
|
27876
27974
|
withTransaction(
|
|
27877
27975
|
this.db,
|
|
@@ -27879,7 +27977,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27879
27977
|
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
27880
27978
|
this.rearmStmt.run();
|
|
27881
27979
|
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
27882
|
-
this.disownCapturesStmt.run();
|
|
27980
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
27981
|
+
}
|
|
27982
|
+
if (backfillCapturesBefore !== void 0) {
|
|
27983
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
27883
27984
|
}
|
|
27884
27985
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
27885
27986
|
},
|
|
@@ -28352,7 +28453,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28352
28453
|
}
|
|
28353
28454
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28354
28455
|
}
|
|
28355
|
-
|
|
28456
|
+
var testOnlyManagedPaths = null;
|
|
28457
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28356
28458
|
for (const path of paths) {
|
|
28357
28459
|
let text;
|
|
28358
28460
|
try {
|
|
@@ -28372,7 +28474,8 @@ function managedContextOf(managed) {
|
|
|
28372
28474
|
return {
|
|
28373
28475
|
present: true,
|
|
28374
28476
|
...managed.organization === void 0 ? {} : { organization: managed.organization },
|
|
28375
|
-
lockedFields: managed.lockedFields
|
|
28477
|
+
lockedFields: managed.lockedFields,
|
|
28478
|
+
...managed.unknownLockedFields === void 0 ? {} : { unknownLockedFields: managed.unknownLockedFields }
|
|
28376
28479
|
};
|
|
28377
28480
|
}
|
|
28378
28481
|
function overlayManagedSettings(settings, managed, now = () => /* @__PURE__ */ new Date()) {
|
|
@@ -30930,7 +31033,7 @@ function toUtcDateString(ms) {
|
|
|
30930
31033
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30931
31034
|
}
|
|
30932
31035
|
function isTimeseriesSeverity(s) {
|
|
30933
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
31036
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30934
31037
|
}
|
|
30935
31038
|
var SqliteSecurityRepository = class {
|
|
30936
31039
|
constructor(db, now = () => Date.now()) {
|
|
@@ -31059,12 +31162,16 @@ var SqliteSecurityRepository = class {
|
|
|
31059
31162
|
const now = this.now();
|
|
31060
31163
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
31061
31164
|
const rows = this.findingsInRange(windowStart, now);
|
|
31062
|
-
const points = Array.from(
|
|
31063
|
-
|
|
31064
|
-
|
|
31065
|
-
|
|
31066
|
-
|
|
31067
|
-
|
|
31165
|
+
const points = Array.from(
|
|
31166
|
+
{ length: numBuckets },
|
|
31167
|
+
(_, i) => ({
|
|
31168
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
31169
|
+
critical: 0,
|
|
31170
|
+
high: 0,
|
|
31171
|
+
medium: 0,
|
|
31172
|
+
low: 0
|
|
31173
|
+
})
|
|
31174
|
+
);
|
|
31068
31175
|
for (const r of rows) {
|
|
31069
31176
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
31070
31177
|
const bucket = points[idx];
|
|
@@ -31282,6 +31389,7 @@ var SqliteSecurityRepository = class {
|
|
|
31282
31389
|
`SELECT f.finding_key AS finding_key,
|
|
31283
31390
|
d.rule_id AS rule_id,
|
|
31284
31391
|
d.severity AS severity,
|
|
31392
|
+
e.repo AS repo,
|
|
31285
31393
|
e.file_path AS path,
|
|
31286
31394
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31287
31395
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31301,6 +31409,7 @@ var SqliteSecurityRepository = class {
|
|
|
31301
31409
|
const items = rows.map((r) => ({
|
|
31302
31410
|
findingKey: r.finding_key,
|
|
31303
31411
|
ruleId: r.rule_id,
|
|
31412
|
+
repo: r.repo ?? "",
|
|
31304
31413
|
severity: r.severity,
|
|
31305
31414
|
path: r.path ?? "",
|
|
31306
31415
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31310,13 +31419,66 @@ var SqliteSecurityRepository = class {
|
|
|
31310
31419
|
}));
|
|
31311
31420
|
return Promise.resolve({ items });
|
|
31312
31421
|
}
|
|
31422
|
+
/**
|
|
31423
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31424
|
+
*
|
|
31425
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31426
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31427
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31428
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31429
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31430
|
+
*
|
|
31431
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31432
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31433
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31434
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31435
|
+
* The two answer different questions and only this one has to match a link.
|
|
31436
|
+
*
|
|
31437
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31438
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31439
|
+
*/
|
|
31440
|
+
recommendationInputs() {
|
|
31441
|
+
const rows = allRows(
|
|
31442
|
+
this.db.prepare(
|
|
31443
|
+
`SELECT d.rule_id AS rule_id,
|
|
31444
|
+
d.category AS category,
|
|
31445
|
+
d.severity AS severity,
|
|
31446
|
+
COUNT(*) AS count
|
|
31447
|
+
FROM inspection_findings f
|
|
31448
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31449
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31450
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31451
|
+
ON latest.finding_key = f.finding_key
|
|
31452
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31453
|
+
AND e.event_type = 'code_change'
|
|
31454
|
+
AND (
|
|
31455
|
+
f.finding_key IS NULL
|
|
31456
|
+
OR latest.status IS NULL
|
|
31457
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31458
|
+
)
|
|
31459
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31460
|
+
)
|
|
31461
|
+
);
|
|
31462
|
+
return Promise.resolve(
|
|
31463
|
+
rows.map((r) => ({
|
|
31464
|
+
ruleId: r.rule_id,
|
|
31465
|
+
category: r.category,
|
|
31466
|
+
severity: r.severity,
|
|
31467
|
+
count: r.count
|
|
31468
|
+
}))
|
|
31469
|
+
);
|
|
31470
|
+
}
|
|
31313
31471
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31314
31472
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31315
31473
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31316
31474
|
findingsInRange(fromMs, toMs) {
|
|
31317
31475
|
const rows = allRows(
|
|
31318
31476
|
this.db.prepare(
|
|
31319
|
-
`
|
|
31477
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31478
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31479
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31480
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31481
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31320
31482
|
FROM inspection_findings f
|
|
31321
31483
|
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31322
31484
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -31329,7 +31491,9 @@ var SqliteSecurityRepository = class {
|
|
|
31329
31491
|
return rows.map((r) => ({
|
|
31330
31492
|
occurredAt: r.occurred_at,
|
|
31331
31493
|
severity: r.severity,
|
|
31332
|
-
actionTaken: r.action_taken
|
|
31494
|
+
actionTaken: r.action_taken,
|
|
31495
|
+
ruleId: r.rule_id,
|
|
31496
|
+
category: r.category
|
|
31333
31497
|
}));
|
|
31334
31498
|
}
|
|
31335
31499
|
};
|
|
@@ -32499,23 +32663,30 @@ function openLocalDatabase(dir) {
|
|
|
32499
32663
|
};
|
|
32500
32664
|
}
|
|
32501
32665
|
|
|
32502
|
-
// ../../packages/persistence/src/
|
|
32666
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32503
32667
|
import { createHash as createHash3 } from "crypto";
|
|
32504
32668
|
|
|
32669
|
+
// ../../packages/persistence/src/finding-key.ts
|
|
32670
|
+
import { createHash as createHash4 } from "crypto";
|
|
32671
|
+
|
|
32505
32672
|
// ../../packages/persistence/src/fingerprint.ts
|
|
32506
32673
|
import { createHmac, randomBytes } from "crypto";
|
|
32507
32674
|
import { existsSync as existsSync3, readFileSync as readFileSync6 } from "fs";
|
|
32508
32675
|
import { join as join8 } from "path";
|
|
32509
32676
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
32510
32677
|
|
|
32511
|
-
// ../../packages/persistence/src/history-
|
|
32678
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
32512
32679
|
import { existsSync as existsSync4 } from "fs";
|
|
32513
32680
|
import { join as join9 } from "path";
|
|
32681
|
+
|
|
32682
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
32683
|
+
import { existsSync as existsSync5 } from "fs";
|
|
32684
|
+
import { join as join10 } from "path";
|
|
32514
32685
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32515
32686
|
|
|
32516
32687
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32517
|
-
import { existsSync as
|
|
32518
|
-
import { dirname as dirname3, join as
|
|
32688
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32689
|
+
import { dirname as dirname3, join as join11, resolve } from "path";
|
|
32519
32690
|
|
|
32520
32691
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32521
32692
|
import {
|
|
@@ -32530,19 +32701,19 @@ import {
|
|
|
32530
32701
|
import { execFileSync } from "child_process";
|
|
32531
32702
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32532
32703
|
import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
32533
|
-
import { join as
|
|
32704
|
+
import { join as join12 } from "path";
|
|
32534
32705
|
|
|
32535
32706
|
// ../../packages/persistence/src/vault/vault.ts
|
|
32536
32707
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
32537
32708
|
|
|
32538
32709
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
32539
|
-
import { existsSync as
|
|
32540
|
-
import { join as
|
|
32710
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
32711
|
+
import { join as join13 } from "path";
|
|
32541
32712
|
var MARKER = "warn-era-capped";
|
|
32542
32713
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
32543
32714
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
32544
|
-
const marker =
|
|
32545
|
-
if (
|
|
32715
|
+
const marker = join13(dataDir2, MARKER);
|
|
32716
|
+
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
32546
32717
|
const capped = db.policies.capCategoryActions();
|
|
32547
32718
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
32548
32719
|
`, { mode: DATA_FILE_MODE });
|
|
@@ -32550,8 +32721,8 @@ function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
|
32550
32721
|
}
|
|
32551
32722
|
|
|
32552
32723
|
// ../../packages/plugin-sdk/src/config.ts
|
|
32553
|
-
import { existsSync as
|
|
32554
|
-
import { join as
|
|
32724
|
+
import { existsSync as existsSync8 } from "fs";
|
|
32725
|
+
import { join as join14 } from "path";
|
|
32555
32726
|
|
|
32556
32727
|
// ../../packages/plugin-sdk/src/provider-env.ts
|
|
32557
32728
|
var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
|
|
@@ -32605,8 +32776,8 @@ function resolveProvider() {
|
|
|
32605
32776
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
32606
32777
|
try {
|
|
32607
32778
|
ensureLayoutDirSync(base);
|
|
32608
|
-
const settingsFile =
|
|
32609
|
-
if (
|
|
32779
|
+
const settingsFile = join14(settingsDir(base), "settings.json");
|
|
32780
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
32610
32781
|
} catch {
|
|
32611
32782
|
}
|
|
32612
32783
|
migrateLegacyLayout(base);
|
|
@@ -32631,7 +32802,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
32631
32802
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
32632
32803
|
import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
32633
32804
|
import { homedir as homedir2 } from "os";
|
|
32634
|
-
import { basename as basename3, join as
|
|
32805
|
+
import { basename as basename3, join as join16 } from "path";
|
|
32635
32806
|
|
|
32636
32807
|
// ../../packages/detections/src/egress/registry.ts
|
|
32637
32808
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -33389,24 +33560,20 @@ var CPU_CORROBORATION_SHARE = 0.2;
|
|
|
33389
33560
|
var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
|
|
33390
33561
|
|
|
33391
33562
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
33392
|
-
import { existsSync as
|
|
33393
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
33563
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
|
|
33564
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join15, sep as sep2 } from "path";
|
|
33394
33565
|
|
|
33395
33566
|
// ../../packages/plugin-sdk/src/events.ts
|
|
33396
|
-
import { createHash as
|
|
33567
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
33397
33568
|
|
|
33398
33569
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
33399
|
-
import { existsSync as
|
|
33570
|
+
import { existsSync as existsSync10 } from "fs";
|
|
33400
33571
|
import { fileURLToPath } from "url";
|
|
33401
33572
|
import { Worker } from "worker_threads";
|
|
33402
33573
|
|
|
33403
|
-
// ../../packages/plugin-sdk/src/
|
|
33404
|
-
|
|
33405
|
-
import {
|
|
33406
|
-
import { join as join16 } from "path";
|
|
33407
|
-
|
|
33408
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
33409
|
-
import { arch, hostname as hostname4, platform, release as release2 } from "os";
|
|
33574
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
33575
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
33576
|
+
import { join as join18 } from "path";
|
|
33410
33577
|
|
|
33411
33578
|
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
33412
33579
|
import {
|
|
@@ -33414,16 +33581,42 @@ import {
|
|
|
33414
33581
|
fstatSync,
|
|
33415
33582
|
mkdirSync as mkdirSync2,
|
|
33416
33583
|
openSync as openSync2,
|
|
33417
|
-
readFileSync as
|
|
33584
|
+
readFileSync as readFileSync10,
|
|
33418
33585
|
readSync,
|
|
33419
33586
|
writeFileSync as writeFileSync5
|
|
33420
33587
|
} from "fs";
|
|
33421
33588
|
import { join as join17 } from "path";
|
|
33422
33589
|
var TAIL_BYTES = 256 * 1024;
|
|
33423
33590
|
|
|
33591
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
33592
|
+
var HOST_FEATURE = {
|
|
33593
|
+
ModelSwitch: "model-switch",
|
|
33594
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
33595
|
+
};
|
|
33596
|
+
var HOST_FLOORS = {
|
|
33597
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
33598
|
+
label: "model-switch protection",
|
|
33599
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
33600
|
+
since: "2.1.251"
|
|
33601
|
+
},
|
|
33602
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
33603
|
+
label: "vault pointer display",
|
|
33604
|
+
hookEvents: ["MessageDisplay"],
|
|
33605
|
+
since: "2.1.152"
|
|
33606
|
+
}
|
|
33607
|
+
};
|
|
33608
|
+
|
|
33609
|
+
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
33610
|
+
var import_ignore = __toESM(require_ignore(), 1);
|
|
33611
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
33612
|
+
import { join as join19 } from "path";
|
|
33613
|
+
|
|
33614
|
+
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
33615
|
+
import { arch, hostname as hostname4, platform, release as release2 } from "os";
|
|
33616
|
+
|
|
33424
33617
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
33425
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
33426
|
-
import { join as
|
|
33618
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
33619
|
+
import { join as join20 } from "path";
|
|
33427
33620
|
|
|
33428
33621
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
33429
33622
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
@@ -33440,8 +33633,8 @@ function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
|
33440
33633
|
}
|
|
33441
33634
|
|
|
33442
33635
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
33443
|
-
import { existsSync as
|
|
33444
|
-
import { basename as basename5, join as
|
|
33636
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
33637
|
+
import { basename as basename5, join as join21 } from "path";
|
|
33445
33638
|
|
|
33446
33639
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
33447
33640
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -33477,7 +33670,7 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
33477
33670
|
|
|
33478
33671
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
33479
33672
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
33480
|
-
import { join as
|
|
33673
|
+
import { join as join22 } from "path";
|
|
33481
33674
|
|
|
33482
33675
|
// ../../packages/setup-wizard/src/onboard-posture.ts
|
|
33483
33676
|
function parsePosture(json2) {
|
|
@@ -33500,7 +33693,7 @@ function parsePosture(json2) {
|
|
|
33500
33693
|
|
|
33501
33694
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
33502
33695
|
import { writeFileSync as writeFileSync8 } from "fs";
|
|
33503
|
-
import { join as
|
|
33696
|
+
import { join as join23 } from "path";
|
|
33504
33697
|
|
|
33505
33698
|
// ../../packages/setup-wizard/src/triage/merge.ts
|
|
33506
33699
|
var RANK = Object.fromEntries(
|
|
@@ -33508,9 +33701,9 @@ var RANK = Object.fromEntries(
|
|
|
33508
33701
|
);
|
|
33509
33702
|
|
|
33510
33703
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
33511
|
-
import { mkdtempSync, readFileSync as
|
|
33704
|
+
import { mkdtempSync, readFileSync as readFileSync14, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
|
|
33512
33705
|
import { tmpdir } from "os";
|
|
33513
|
-
import { basename as basename6, dirname as dirname6, join as
|
|
33706
|
+
import { basename as basename6, dirname as dirname6, join as join24 } from "path";
|
|
33514
33707
|
var SuppressionEntrySchema = external_exports.object({
|
|
33515
33708
|
ruleId: external_exports.string(),
|
|
33516
33709
|
category: DetectionCategory,
|