@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/remediate.js
CHANGED
|
@@ -492,7 +492,7 @@ var require_ignore = __commonJS({
|
|
|
492
492
|
});
|
|
493
493
|
|
|
494
494
|
// src/remediation/entry.ts
|
|
495
|
-
import { readFileSync as
|
|
495
|
+
import { readFileSync as readFileSync23 } from "fs";
|
|
496
496
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
497
497
|
|
|
498
498
|
// ../../packages/persistence/src/attached-derived.ts
|
|
@@ -20743,13 +20743,11 @@ var FindingGroup = external_exports.object({
|
|
|
20743
20743
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20744
20744
|
instances: external_exports.array(FindingInstance),
|
|
20745
20745
|
// Derived from instances' statuses with open-dominates precedence (see
|
|
20746
|
-
//
|
|
20746
|
+
// foldGroupStatus). Undefined only when no instance carries a status.
|
|
20747
20747
|
status: FindingStatus.optional(),
|
|
20748
|
-
// The distinct people across the WHOLE group, not just the
|
|
20749
|
-
//
|
|
20750
|
-
//
|
|
20751
|
-
// instance carries a user, or when the store supplied whole-group folds
|
|
20752
|
-
// without one.
|
|
20748
|
+
// The distinct people across the WHOLE group, not just the instances
|
|
20749
|
+
// carried here. Undefined when no instance carries a user, or when the
|
|
20750
|
+
// store supplied whole-group folds without one.
|
|
20753
20751
|
users: external_exports.array(FindingUser).optional()
|
|
20754
20752
|
}).meta({ id: "FindingGroup" });
|
|
20755
20753
|
var FindingStats = external_exports.object({
|
|
@@ -20778,21 +20776,31 @@ var FindingFacets = external_exports.object({
|
|
|
20778
20776
|
// counted under no value.
|
|
20779
20777
|
status: external_exports.array(FindingFacetItem),
|
|
20780
20778
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20781
|
-
// reads, which can filter by it; the
|
|
20779
|
+
// reads, which can filter by it; the type-level read omits the dimension
|
|
20782
20780
|
// because a group spans tools.
|
|
20783
20781
|
tool: external_exports.array(FindingFacetItem).optional()
|
|
20784
20782
|
}).meta({ id: "FindingFacets" });
|
|
20785
|
-
var
|
|
20786
|
-
|
|
20783
|
+
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20784
|
+
id: "FindingTypeSummary"
|
|
20785
|
+
});
|
|
20786
|
+
var DEFAULT_FINDING_TYPES_LIMIT = 50;
|
|
20787
|
+
var MAX_FINDING_TYPES_LIMIT = 100;
|
|
20788
|
+
var ListFindingTypesQuery = external_exports.object({
|
|
20787
20789
|
// NOTE: severity filters by Severity (critical/high/medium/low), not by
|
|
20788
|
-
// FindingAction.
|
|
20790
|
+
// FindingAction. It narrows TYPES: a type's severity is the one its newest
|
|
20791
|
+
// firing version carries, and this list pages types.
|
|
20792
|
+
//
|
|
20793
|
+
// That is NOT a claim the findings of a type share it. A rule can hold several
|
|
20794
|
+
// definition versions at different severities, so a type kept by this filter
|
|
20795
|
+
// can hold findings that individually do not match — see totals.findings on
|
|
20796
|
+
// ListFindingTypesResponse, which counts them all.
|
|
20789
20797
|
severity: external_exports.array(Severity).optional(),
|
|
20790
20798
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20791
20799
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20792
20800
|
action: external_exports.array(FindingAction).optional(),
|
|
20793
|
-
// Matches a
|
|
20794
|
-
// individual
|
|
20795
|
-
//
|
|
20801
|
+
// Matches a type's DERIVED status (see FindingGroup.status), not its
|
|
20802
|
+
// individual findings' — so a filtered row's status always reads one of the
|
|
20803
|
+
// requested values.
|
|
20796
20804
|
status: external_exports.array(FindingStatus).optional(),
|
|
20797
20805
|
q: external_exports.string().optional(),
|
|
20798
20806
|
// Scope to findings whose event carries this session id (the Activity page's
|
|
@@ -20802,23 +20810,37 @@ var ListGroupedFindingsQuery = external_exports.object({
|
|
|
20802
20810
|
// from a time-scoped page (Activity's range) can carry that scope. Absent
|
|
20803
20811
|
// means all time — this list has no default window.
|
|
20804
20812
|
from: external_exports.iso.datetime().optional(),
|
|
20805
|
-
// A
|
|
20806
|
-
//
|
|
20807
|
-
//
|
|
20808
|
-
//
|
|
20809
|
-
//
|
|
20813
|
+
// A RULE id that must appear in the page even when the cursor has already
|
|
20814
|
+
// advanced past its sort position. This is what keeps the selected type
|
|
20815
|
+
// visible in the list once it paginates: the target is appended out of sort
|
|
20816
|
+
// order rather than scanned forward for. Never affects totals, facets or the
|
|
20817
|
+
// cursor. Unlike the grouped read this replaces, it names a rule only — an
|
|
20818
|
+
// instance id is resolved by `findingInstance`, which is a primary-key seek
|
|
20819
|
+
// and so is not bounded by what any page happens to hold.
|
|
20810
20820
|
includeId: external_exports.string().optional(),
|
|
20811
|
-
|
|
20812
|
-
limit: external_exports.coerce.number().int().min(1).max(100).optional(),
|
|
20821
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
|
|
20813
20822
|
cursor: external_exports.string().optional()
|
|
20814
20823
|
});
|
|
20815
|
-
var
|
|
20824
|
+
var ListFindingTypesResponse = external_exports.object({
|
|
20816
20825
|
totals: external_exports.object({
|
|
20826
|
+
// Findings belonging to the matching TYPES — not findings that each match
|
|
20827
|
+
// the filters. The filters here select types, so a type that survives
|
|
20828
|
+
// contributes its whole instanceCount.
|
|
20829
|
+
//
|
|
20830
|
+
// `status` is the one exception, narrowed per finding via
|
|
20831
|
+
// countInstancesByStatus. `severity`, `provider` and `action` are not, so
|
|
20832
|
+
// this can exceed what the instance read reports for the same filters: a
|
|
20833
|
+
// rule whose severity moved between versions is kept on its newest and
|
|
20834
|
+
// still counts its older findings. Narrowing the other three needs
|
|
20835
|
+
// per-dimension counts the aggregate does not carry today.
|
|
20817
20836
|
findings: external_exports.number().int().nonnegative(),
|
|
20818
|
-
|
|
20837
|
+
// Counts TYPES, which is the unit this read pages. The instance read's
|
|
20838
|
+
// own totals count findings; the two deliberately answer different
|
|
20839
|
+
// questions and are never summed.
|
|
20840
|
+
types: external_exports.number().int().nonnegative()
|
|
20819
20841
|
}),
|
|
20820
20842
|
facets: FindingFacets,
|
|
20821
|
-
items: external_exports.array(
|
|
20843
|
+
items: external_exports.array(FindingTypeSummary),
|
|
20822
20844
|
nextCursor: external_exports.string().nullable(),
|
|
20823
20845
|
// Present only on session-scoped queries (`sessionId` set): per ruleId, how
|
|
20824
20846
|
// many times that rule fired in the session's persisted transcript. Findings
|
|
@@ -20826,7 +20848,7 @@ var ListGroupedFindingsResponse = external_exports.object({
|
|
|
20826
20848
|
// every firing, so the two numbers legitimately differ — this map lets a
|
|
20827
20849
|
// session-scoped view show both.
|
|
20828
20850
|
sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
|
|
20829
|
-
}).meta({ id: "
|
|
20851
|
+
}).meta({ id: "ListFindingTypesResponse" });
|
|
20830
20852
|
var ApplyFindingActionRequest = external_exports.object({
|
|
20831
20853
|
// 'quarantined' is system-assigned (see FindingAction) — clients may not set
|
|
20832
20854
|
// it, so it is excluded from the request contract. The mapping helper
|
|
@@ -20856,12 +20878,13 @@ var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
|
20856
20878
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
20857
20879
|
var ListFindingInstancesQuery = external_exports.object({
|
|
20858
20880
|
severity: external_exports.array(Severity).optional(),
|
|
20859
|
-
// Rule ids, the same vocabulary the
|
|
20881
|
+
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
20882
|
+
// ONE of them is how the master/detail view scopes its right-hand panel.
|
|
20860
20883
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20861
20884
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20862
20885
|
action: external_exports.array(FindingAction).optional(),
|
|
20863
20886
|
// Matches each instance's OWN derived status (deriveFindingStatus), unlike
|
|
20864
|
-
// the
|
|
20887
|
+
// the types query's type-level fold.
|
|
20865
20888
|
status: external_exports.array(FindingStatus).optional(),
|
|
20866
20889
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20867
20890
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
@@ -20878,37 +20901,47 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20878
20901
|
});
|
|
20879
20902
|
var ListFindingInstancesResponse = external_exports.object({
|
|
20880
20903
|
// Instances matching the filters across the whole scope, not just this
|
|
20881
|
-
// page — cursor-independent, like the
|
|
20904
|
+
// page — cursor-independent, like the types list's totals.
|
|
20882
20905
|
totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
|
|
20883
|
-
// Counts in INSTANCES here, where the
|
|
20906
|
+
// Counts in INSTANCES here, where the types response counts types. Each
|
|
20884
20907
|
// dimension still excludes its own filter.
|
|
20885
20908
|
facets: FindingFacets,
|
|
20886
20909
|
items: external_exports.array(FindingInstanceDetail),
|
|
20887
20910
|
nextCursor: external_exports.string().nullable()
|
|
20888
20911
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20889
|
-
var
|
|
20890
|
-
//
|
|
20891
|
-
//
|
|
20892
|
-
|
|
20893
|
-
|
|
20894
|
-
|
|
20895
|
-
|
|
20896
|
-
// Folded from the instances' derived statuses with the same
|
|
20897
|
-
// open-dominates precedence a group uses.
|
|
20898
|
-
status: FindingStatus.optional(),
|
|
20899
|
-
// Distinct rules seen at this location, capped — the row shows them as
|
|
20900
|
-
// chips, and the count is what conveys scale.
|
|
20901
|
-
ruleIds: external_exports.array(external_exports.string())
|
|
20902
|
-
}).meta({ id: "FindingLocationFile" });
|
|
20903
|
-
var FindingLocationRepo = external_exports.object({
|
|
20912
|
+
var FindingLocationSummary = external_exports.object({
|
|
20913
|
+
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20914
|
+
// because a location's identity is two values and a URL param carries one:
|
|
20915
|
+
// `?loc=` names a location the way `?rule=` names a type. Only ever compared
|
|
20916
|
+
// for EQUALITY — the page's selection check, this read's `includeId`, the
|
|
20917
|
+
// client's page dedupe — never decoded, and never a sort key.
|
|
20918
|
+
id: external_exports.string(),
|
|
20904
20919
|
/** Empty when the instances carried no repo attribute. */
|
|
20905
20920
|
repo: external_exports.string(),
|
|
20921
|
+
// Empty when the instances carried no file path (a prompt, or a tool call
|
|
20922
|
+
// with no file attribution). Both halves empty is a real location — usually
|
|
20923
|
+
// the largest one in a store — and is selectable like any other.
|
|
20924
|
+
file: external_exports.string(),
|
|
20906
20925
|
instanceCount: external_exports.number().int().nonnegative(),
|
|
20926
|
+
// The WORST severity present, not the first row's. It is this list's primary
|
|
20927
|
+
// sort key, so it is also what explains why a row is where it is, and it is
|
|
20928
|
+
// how a reader decides what to open without opening everything.
|
|
20907
20929
|
maxSeverity: Severity,
|
|
20908
20930
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20931
|
+
// Folded from the instances' derived statuses with the same open-dominates
|
|
20932
|
+
// precedence a group uses, so it answers "is anything left to do here" and
|
|
20933
|
+
// not much more: a location holding 1 open among 40 resolved reads like one
|
|
20934
|
+
// holding 40 open. That loss is accepted — the panel beside this list
|
|
20935
|
+
// carries each finding's own status, and instanceCount sits next to the
|
|
20936
|
+
// badge.
|
|
20909
20937
|
status: FindingStatus.optional(),
|
|
20910
|
-
|
|
20911
|
-
|
|
20938
|
+
// Every distinct rule seen at this location, UNCAPPED — so the length is a
|
|
20939
|
+
// tally rather than a sample and a row can say how many there are. Bounded
|
|
20940
|
+
// by the ruleset, not by the store. The view bounds what it DISPLAYS.
|
|
20941
|
+
ruleIds: external_exports.array(external_exports.string())
|
|
20942
|
+
}).meta({ id: "FindingLocationSummary" });
|
|
20943
|
+
var DEFAULT_FINDING_LOCATIONS_LIMIT = 50;
|
|
20944
|
+
var MAX_FINDING_LOCATIONS_LIMIT = 100;
|
|
20912
20945
|
var ListFindingLocationsQuery = external_exports.object({
|
|
20913
20946
|
severity: external_exports.array(Severity).optional(),
|
|
20914
20947
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
@@ -20921,18 +20954,42 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20921
20954
|
q: external_exports.string().optional(),
|
|
20922
20955
|
sessionId: external_exports.string().optional(),
|
|
20923
20956
|
from: external_exports.iso.datetime().optional(),
|
|
20924
|
-
|
|
20957
|
+
// A LOCATION id (see FindingLocationSummary.id) that must appear in the page
|
|
20958
|
+
// even when the cursor has already advanced past its sort position — the
|
|
20959
|
+
// counterpart of ListFindingTypesQuery.includeId, and needed far more often
|
|
20960
|
+
// here. Selecting a row pushes the URL, which re-renders the server and resets
|
|
20961
|
+
// the client's page cache to page 0; with distinct (repo, file) pairs running
|
|
20962
|
+
// into the thousands, a selection sitting off page 0 is the ordinary case
|
|
20963
|
+
// rather than a deep-link corner. Never affects totals, facets or the cursor.
|
|
20964
|
+
includeId: external_exports.string().optional(),
|
|
20965
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
|
|
20966
|
+
cursor: external_exports.string().optional()
|
|
20925
20967
|
});
|
|
20926
20968
|
var ListFindingLocationsResponse = external_exports.object({
|
|
20927
20969
|
totals: external_exports.object({
|
|
20970
|
+
// Findings matching the filters across the whole scope. Unlike the types
|
|
20971
|
+
// read's same-named field this needs no caveat: the filters here narrow
|
|
20972
|
+
// per finding, so this is the sum of every row's instanceCount.
|
|
20928
20973
|
findings: external_exports.number().int().nonnegative(),
|
|
20929
|
-
|
|
20930
|
-
|
|
20974
|
+
// Counts LOCATIONS, the unit this read pages — the number the paginator
|
|
20975
|
+
// states. The facets beside it count FINDINGS (see below); a surface
|
|
20976
|
+
// showing both says which is which.
|
|
20977
|
+
locations: external_exports.number().int().nonnegative()
|
|
20931
20978
|
}),
|
|
20932
|
-
|
|
20933
|
-
|
|
20934
|
-
|
|
20935
|
-
|
|
20979
|
+
// Counts in FINDINGS, where the types response counts types, each dimension
|
|
20980
|
+
// still excluding its own filter. Deliberately not locations: counting those
|
|
20981
|
+
// needs a set of location keys per dimension per value — memory tracking the
|
|
20982
|
+
// store times the vocabulary, in a read whose scan promises flat memory —
|
|
20983
|
+
// and the cheap per-location version is not an approximation but WRONG. A
|
|
20984
|
+
// location holding {claudecode, block} and {codex, warn} would survive
|
|
20985
|
+
// provider=claudecode AND action=warn, under which no single finding
|
|
20986
|
+
// matches, so the facet would contradict the instanceCount this whole view
|
|
20987
|
+
// rests on. Findings also keep the toolbar in the same unit as the page
|
|
20988
|
+
// tally and the panel it sits above.
|
|
20989
|
+
facets: FindingFacets,
|
|
20990
|
+
/** Sorted by max severity, then most recent, then (repo, file). */
|
|
20991
|
+
items: external_exports.array(FindingLocationSummary),
|
|
20992
|
+
nextCursor: external_exports.string().nullable()
|
|
20936
20993
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
20937
20994
|
|
|
20938
20995
|
// ../../packages/schema/src/zod/meta.ts
|
|
@@ -22101,6 +22158,14 @@ var ControlPlaneErrorBody = external_exports.object({
|
|
|
22101
22158
|
message: external_exports.string().optional()
|
|
22102
22159
|
}).optional()
|
|
22103
22160
|
});
|
|
22161
|
+
var RemoteFailureKind = external_exports.enum([
|
|
22162
|
+
"unauthorized",
|
|
22163
|
+
"forbidden",
|
|
22164
|
+
"route-absent",
|
|
22165
|
+
"invalid-request",
|
|
22166
|
+
"rejected",
|
|
22167
|
+
"unreachable"
|
|
22168
|
+
]);
|
|
22104
22169
|
var AttachDeviceRequest = external_exports.object({
|
|
22105
22170
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22106
22171
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22794,139 +22859,62 @@ function deriveFindingStatus(row) {
|
|
|
22794
22859
|
if (row.latestResolutionStatus === "dismissed") return "dismissed";
|
|
22795
22860
|
return "open";
|
|
22796
22861
|
}
|
|
22797
|
-
function distinctUsers(instances) {
|
|
22798
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22799
|
-
const users = [];
|
|
22800
|
-
for (const i of instances) {
|
|
22801
|
-
if (i.user === void 0 || seen.has(i.user.id)) continue;
|
|
22802
|
-
seen.add(i.user.id);
|
|
22803
|
-
users.push(i.user);
|
|
22804
|
-
}
|
|
22805
|
-
return users;
|
|
22806
|
-
}
|
|
22807
22862
|
function sortUsers(users) {
|
|
22808
22863
|
return [...users].sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
22809
22864
|
}
|
|
22810
|
-
function
|
|
22811
|
-
const overrides = opts.overrides;
|
|
22865
|
+
function buildFindingTypes(aggregates, opts = {}) {
|
|
22812
22866
|
const packNames = opts.packNames;
|
|
22813
|
-
const
|
|
22814
|
-
const
|
|
22815
|
-
|
|
22816
|
-
const
|
|
22817
|
-
|
|
22818
|
-
else byRuleId.set(row.ruleId, [row]);
|
|
22819
|
-
}
|
|
22820
|
-
const groups = [];
|
|
22821
|
-
for (const [ruleId, ruleRows] of byRuleId) {
|
|
22822
|
-
const instances = ruleRows.map((r) => {
|
|
22823
|
-
const effectiveDbAction = overrides?.get(r.id) ?? r.actionTaken;
|
|
22824
|
-
return {
|
|
22825
|
-
id: r.id,
|
|
22826
|
-
provider: toApiProvider(r.sourceTool),
|
|
22827
|
-
repo: r.repo,
|
|
22828
|
-
file: r.file,
|
|
22829
|
-
...r.toolName === void 0 ? {} : { toolName: r.toolName },
|
|
22830
|
-
...r.eventId === void 0 ? {} : { eventId: r.eventId },
|
|
22831
|
-
...r.sessionId === void 0 ? {} : { sessionId: r.sessionId },
|
|
22832
|
-
...r.user === void 0 ? {} : { user: r.user },
|
|
22833
|
-
action: toApiAction(effectiveDbAction),
|
|
22834
|
-
detectedAt: r.occurredAt,
|
|
22835
|
-
confidence: r.confidence,
|
|
22836
|
-
status: r.status
|
|
22837
|
-
};
|
|
22838
|
-
});
|
|
22839
|
-
const agg = aggregates?.get(ruleId);
|
|
22840
|
-
const users = agg ? sortUsers(agg.users ?? []) : distinctUsers(instances);
|
|
22841
|
-
const latestDetectedAt = agg?.latestDetectedAt ?? ruleRows.reduce(
|
|
22842
|
-
(max, r) => r.occurredAt > max ? r.occurredAt : max,
|
|
22843
|
-
ruleRows[0]?.occurredAt ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
22844
|
-
);
|
|
22845
|
-
const seenProviders = /* @__PURE__ */ new Set();
|
|
22846
|
-
const providers = (agg ? [...new Set(agg.sourceTools.map(toApiProvider))].sort() : instances.map((i) => i.provider)).filter((p) => {
|
|
22847
|
-
if (seenProviders.has(p)) return false;
|
|
22848
|
-
seenProviders.add(p);
|
|
22849
|
-
return true;
|
|
22850
|
-
});
|
|
22851
|
-
const actionSet = new Set(
|
|
22852
|
-
agg ? agg.actionsTaken.map(toApiAction) : instances.map((i) => i.action)
|
|
22853
|
-
);
|
|
22867
|
+
const types = [];
|
|
22868
|
+
for (const [ruleId, agg] of aggregates) {
|
|
22869
|
+
const users = sortUsers(agg.users ?? []);
|
|
22870
|
+
const providers = [...new Set(agg.sourceTools.map(toApiProvider))].sort();
|
|
22871
|
+
const actionSet = new Set(agg.actionsTaken.map(toApiAction));
|
|
22854
22872
|
const aggregateAction = actionSet.size === 1 ? [...actionSet][0] ?? null : null;
|
|
22855
|
-
const
|
|
22856
|
-
const
|
|
22857
|
-
id: ruleId,
|
|
22858
|
-
name: packNames?.get(ruleId) ?? null
|
|
22859
|
-
};
|
|
22860
|
-
const apiCategory = toApiCategory(ruleRows[0]?.category ?? "custom");
|
|
22861
|
-
const policy = { id: `category:${apiCategory}`, name: apiCategory };
|
|
22862
|
-
const match = {
|
|
22863
|
-
maskedValue: ruleRows[0]?.maskedMatch ?? "",
|
|
22864
|
-
contextPrefix: ""
|
|
22865
|
-
// empty (pending privacy review)
|
|
22866
|
-
};
|
|
22867
|
-
const status = foldGroupStatus(
|
|
22868
|
-
agg ? agg.statusInputs.map(deriveFindingStatus) : instances.map((i) => i.status)
|
|
22869
|
-
);
|
|
22870
|
-
const group = {
|
|
22873
|
+
const apiCategory = toApiCategory(agg.category ?? "custom");
|
|
22874
|
+
const type = {
|
|
22871
22875
|
id: ruleId,
|
|
22872
22876
|
category: apiCategory,
|
|
22873
22877
|
subtype: ruleId,
|
|
22874
22878
|
// human label comes with pack metadata later
|
|
22875
|
-
severity,
|
|
22876
|
-
|
|
22877
|
-
|
|
22878
|
-
|
|
22879
|
-
instanceCount: agg?.instanceCount ?? instances.length,
|
|
22879
|
+
severity: agg.severity ?? "low",
|
|
22880
|
+
detection: { id: ruleId, name: packNames?.get(ruleId) ?? null },
|
|
22881
|
+
policy: { id: `category:${apiCategory}`, name: apiCategory },
|
|
22882
|
+
instanceCount: agg.instanceCount,
|
|
22880
22883
|
providers,
|
|
22881
22884
|
aggregateAction,
|
|
22882
|
-
latestDetectedAt,
|
|
22883
|
-
|
|
22884
|
-
status,
|
|
22885
|
+
latestDetectedAt: agg.latestDetectedAt,
|
|
22886
|
+
status: foldGroupStatus(agg.statusInputs.map(deriveFindingStatus)),
|
|
22885
22887
|
...users.length > 0 ? { users } : {}
|
|
22886
22888
|
};
|
|
22887
|
-
|
|
22888
|
-
|
|
22889
|
-
|
|
22890
|
-
haystackCache.set(group, buildHaystack(group, agg.searchText));
|
|
22891
|
-
}
|
|
22889
|
+
actionsCache.set(type, [...actionSet]);
|
|
22890
|
+
if (agg.searchText !== void 0) {
|
|
22891
|
+
haystackCache.set(type, buildHaystack(type, agg.searchText));
|
|
22892
22892
|
}
|
|
22893
|
-
|
|
22893
|
+
types.push(type);
|
|
22894
22894
|
}
|
|
22895
|
-
return
|
|
22895
|
+
return types;
|
|
22896
22896
|
}
|
|
22897
22897
|
var haystackCache = /* @__PURE__ */ new WeakMap();
|
|
22898
|
-
function buildHaystack(
|
|
22898
|
+
function buildHaystack(t, extra) {
|
|
22899
22899
|
return [
|
|
22900
|
-
|
|
22901
|
-
|
|
22902
|
-
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
...g.instances.map((i) => i.repo),
|
|
22906
|
-
...g.instances.map((i) => i.file),
|
|
22907
|
-
...g.instances.map((i) => i.toolName ? `via ${i.toolName}` : ""),
|
|
22908
|
-
...g.instances.map((i) => i.id),
|
|
22909
|
-
// The people: the whole group's list when the store folded one, plus the
|
|
22910
|
-
// preview's own — the two overlap, and a haystack does not mind.
|
|
22911
|
-
...(g.users ?? []).map((u) => u.name),
|
|
22912
|
-
...g.instances.map((i) => i.user?.name ?? ""),
|
|
22900
|
+
t.subtype,
|
|
22901
|
+
t.category,
|
|
22902
|
+
t.policy.name,
|
|
22903
|
+
t.id,
|
|
22904
|
+
...(t.users ?? []).map((u) => u.name),
|
|
22913
22905
|
...extra === void 0 ? [] : [extra]
|
|
22914
22906
|
].join(" ").toLowerCase();
|
|
22915
22907
|
}
|
|
22916
|
-
function
|
|
22917
|
-
const cached2 = haystackCache.get(
|
|
22908
|
+
function typeHaystack(t) {
|
|
22909
|
+
const cached2 = haystackCache.get(t);
|
|
22918
22910
|
if (cached2 !== void 0) return cached2;
|
|
22919
|
-
const haystack = buildHaystack(
|
|
22920
|
-
haystackCache.set(
|
|
22911
|
+
const haystack = buildHaystack(t);
|
|
22912
|
+
haystackCache.set(t, haystack);
|
|
22921
22913
|
return haystack;
|
|
22922
22914
|
}
|
|
22923
22915
|
var actionsCache = /* @__PURE__ */ new WeakMap();
|
|
22924
|
-
function
|
|
22925
|
-
|
|
22926
|
-
if (cached2 !== void 0) return cached2;
|
|
22927
|
-
const actions = [...new Set(g.instances.map((i) => i.action))];
|
|
22928
|
-
actionsCache.set(g, actions);
|
|
22929
|
-
return actions;
|
|
22916
|
+
function typeActions(t) {
|
|
22917
|
+
return actionsCache.get(t) ?? [];
|
|
22930
22918
|
}
|
|
22931
22919
|
function countInstancesByStatus(statusInputs, statuses) {
|
|
22932
22920
|
const statusSet = new Set(statuses);
|
|
@@ -22937,8 +22925,8 @@ function countInstancesByStatus(statusInputs, statuses) {
|
|
|
22937
22925
|
}
|
|
22938
22926
|
return sum;
|
|
22939
22927
|
}
|
|
22940
|
-
function applyFindingFilters(
|
|
22941
|
-
let filtered =
|
|
22928
|
+
function applyFindingFilters(types, opts) {
|
|
22929
|
+
let filtered = types;
|
|
22942
22930
|
if (opts.severity && opts.severity.length > 0) {
|
|
22943
22931
|
const sevSet = new Set(opts.severity);
|
|
22944
22932
|
filtered = filtered.filter((g) => sevSet.has(g.severity));
|
|
@@ -22949,7 +22937,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22949
22937
|
}
|
|
22950
22938
|
if (opts.actions && opts.actions.length > 0) {
|
|
22951
22939
|
const actionSet = new Set(opts.actions);
|
|
22952
|
-
filtered = filtered.filter((
|
|
22940
|
+
filtered = filtered.filter((t) => typeActions(t).some((a) => actionSet.has(a)));
|
|
22953
22941
|
}
|
|
22954
22942
|
if (opts.subtype && opts.subtype.length > 0) {
|
|
22955
22943
|
const subtypeSet = new Set(opts.subtype);
|
|
@@ -22961,7 +22949,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22961
22949
|
}
|
|
22962
22950
|
if (opts.q) {
|
|
22963
22951
|
const q = opts.q.toLowerCase();
|
|
22964
|
-
filtered = filtered.filter((
|
|
22952
|
+
filtered = filtered.filter((t) => typeHaystack(t).includes(q));
|
|
22965
22953
|
}
|
|
22966
22954
|
return filtered;
|
|
22967
22955
|
}
|
|
@@ -22976,11 +22964,11 @@ function compareFindingGroupOrder(a, b) {
|
|
|
22976
22964
|
if (recencyDiff !== 0) return recencyDiff;
|
|
22977
22965
|
return a.id.localeCompare(b.id);
|
|
22978
22966
|
}
|
|
22979
|
-
function
|
|
22980
|
-
return [...
|
|
22967
|
+
function sortFindingTypes(types) {
|
|
22968
|
+
return [...types].sort(compareFindingGroupOrder);
|
|
22981
22969
|
}
|
|
22982
|
-
function computeFindingFacets(
|
|
22983
|
-
const forSeverity = applyFindingFilters(
|
|
22970
|
+
function computeFindingFacets(allTypes, opts) {
|
|
22971
|
+
const forSeverity = applyFindingFilters(allTypes, {
|
|
22984
22972
|
providers: opts.providers,
|
|
22985
22973
|
actions: opts.actions,
|
|
22986
22974
|
statuses: opts.statuses,
|
|
@@ -22991,7 +22979,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22991
22979
|
for (const g of forSeverity) {
|
|
22992
22980
|
severityMap.set(g.severity, (severityMap.get(g.severity) ?? 0) + 1);
|
|
22993
22981
|
}
|
|
22994
|
-
const forProvider = applyFindingFilters(
|
|
22982
|
+
const forProvider = applyFindingFilters(allTypes, {
|
|
22995
22983
|
actions: opts.actions,
|
|
22996
22984
|
statuses: opts.statuses,
|
|
22997
22985
|
q: opts.q,
|
|
@@ -23002,7 +22990,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23002
22990
|
for (const g of forProvider) {
|
|
23003
22991
|
for (const p of g.providers) providerMap.set(p, (providerMap.get(p) ?? 0) + 1);
|
|
23004
22992
|
}
|
|
23005
|
-
const forAction = applyFindingFilters(
|
|
22993
|
+
const forAction = applyFindingFilters(allTypes, {
|
|
23006
22994
|
providers: opts.providers,
|
|
23007
22995
|
statuses: opts.statuses,
|
|
23008
22996
|
q: opts.q,
|
|
@@ -23011,9 +22999,9 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23011
22999
|
});
|
|
23012
23000
|
const actionMap = /* @__PURE__ */ new Map();
|
|
23013
23001
|
for (const g of forAction) {
|
|
23014
|
-
for (const a of
|
|
23002
|
+
for (const a of typeActions(g)) actionMap.set(a, (actionMap.get(a) ?? 0) + 1);
|
|
23015
23003
|
}
|
|
23016
|
-
const forSubtype = applyFindingFilters(
|
|
23004
|
+
const forSubtype = applyFindingFilters(allTypes, {
|
|
23017
23005
|
providers: opts.providers,
|
|
23018
23006
|
actions: opts.actions,
|
|
23019
23007
|
statuses: opts.statuses,
|
|
@@ -23022,7 +23010,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23022
23010
|
});
|
|
23023
23011
|
const subtypeMap = /* @__PURE__ */ new Map();
|
|
23024
23012
|
for (const g of forSubtype) subtypeMap.set(g.subtype, (subtypeMap.get(g.subtype) ?? 0) + 1);
|
|
23025
|
-
const forStatus = applyFindingFilters(
|
|
23013
|
+
const forStatus = applyFindingFilters(allTypes, {
|
|
23026
23014
|
providers: opts.providers,
|
|
23027
23015
|
actions: opts.actions,
|
|
23028
23016
|
q: opts.q,
|
|
@@ -23070,10 +23058,20 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23070
23058
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23071
23059
|
case "tools":
|
|
23072
23060
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23061
|
+
// An EMPTY value is a real filter here, not an absent one. The location
|
|
23062
|
+
// list buckets a finding whose event recorded no repo — or no file — under
|
|
23063
|
+
// the empty string, and selecting that bucket has to narrow the panel to
|
|
23064
|
+
// exactly it. Only `undefined` means "no filter"; a caller that wants every
|
|
23065
|
+
// row omits the key, which every call site already does.
|
|
23066
|
+
//
|
|
23067
|
+
// Reading '' as unset is what this replaced, and it failed in the one place
|
|
23068
|
+
// it mattered: the no-repo/no-file bucket is often the largest in a real
|
|
23069
|
+
// store, and its panel dropped both predicates and returned the WHOLE scope
|
|
23070
|
+
// — a row reading 3 findings beside a panel listing every finding there is.
|
|
23073
23071
|
case "repo":
|
|
23074
|
-
return opts.repo === void 0 ||
|
|
23072
|
+
return opts.repo === void 0 || row.repo === opts.repo;
|
|
23075
23073
|
case "file":
|
|
23076
|
-
return opts.file === void 0 ||
|
|
23074
|
+
return opts.file === void 0 || row.file === opts.file;
|
|
23077
23075
|
case "q":
|
|
23078
23076
|
return !opts.q || rowHaystack(row).includes(opts.q.toLowerCase());
|
|
23079
23077
|
}
|
|
@@ -23187,6 +23185,23 @@ function addToLocation(acc, row) {
|
|
|
23187
23185
|
acc.statuses.push(row.status);
|
|
23188
23186
|
acc.ruleIds.add(row.ruleId);
|
|
23189
23187
|
}
|
|
23188
|
+
function compareLocationOrder(a, b) {
|
|
23189
|
+
const rankA = SEVERITY_ORDER2[a.maxSeverity] ?? -1;
|
|
23190
|
+
const rankB = SEVERITY_ORDER2[b.maxSeverity] ?? -1;
|
|
23191
|
+
if (rankA !== rankB) return rankA - rankB;
|
|
23192
|
+
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23193
|
+
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23194
|
+
}
|
|
23195
|
+
if (a.repo !== b.repo) return a.repo < b.repo ? -1 : 1;
|
|
23196
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
23197
|
+
return 0;
|
|
23198
|
+
}
|
|
23199
|
+
function encodeLocationId(repo, file2) {
|
|
23200
|
+
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
23201
|
+
}
|
|
23202
|
+
function encodePart(value) {
|
|
23203
|
+
return encodeURIComponent(value.replace(/[\uD800-\uDFFF]/gu, "\uFFFD"));
|
|
23204
|
+
}
|
|
23190
23205
|
|
|
23191
23206
|
// ../../packages/schema/src/zod/installed-pack.ts
|
|
23192
23207
|
var InstalledPack = external_exports.object({
|
|
@@ -23700,11 +23715,11 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23700
23715
|
// covers the current payload and must be re-granted.
|
|
23701
23716
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23702
23717
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23703
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23704
|
-
// that covers
|
|
23705
|
-
// carry prompt/reply text in `content
|
|
23706
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23707
|
-
// payload no longer counts.
|
|
23718
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23719
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23720
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23721
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23722
|
+
// or an older payload no longer counts.
|
|
23708
23723
|
historySyncConsent: HistorySyncConsent.optional()
|
|
23709
23724
|
});
|
|
23710
23725
|
function defaultWorkspaceSettings() {
|
|
@@ -23835,6 +23850,9 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23835
23850
|
"dataSharesInPlace",
|
|
23836
23851
|
"redactFallback"
|
|
23837
23852
|
]).meta({ id: "ManagedSettingKey" });
|
|
23853
|
+
function isManagedSettingKey(value) {
|
|
23854
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
23855
|
+
}
|
|
23838
23856
|
var ManagedSettingsValues = external_exports.object({
|
|
23839
23857
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
23840
23858
|
controlPlane: external_exports.object({
|
|
@@ -23859,7 +23877,27 @@ var ManagedSettings = external_exports.object({
|
|
|
23859
23877
|
// Which of those the user may not change. A key here with no matching value
|
|
23860
23878
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23861
23879
|
// the user may still override. The two are separable on purpose.
|
|
23862
|
-
|
|
23880
|
+
//
|
|
23881
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
23882
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
23883
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
23884
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
23885
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
23886
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23887
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
23888
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23889
|
+
}).transform(({ lockedFields, ...rest }) => {
|
|
23890
|
+
const known = [];
|
|
23891
|
+
const unknown2 = [];
|
|
23892
|
+
for (const name of lockedFields) {
|
|
23893
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
23894
|
+
else unknown2.push(name);
|
|
23895
|
+
}
|
|
23896
|
+
return {
|
|
23897
|
+
...rest,
|
|
23898
|
+
lockedFields: known,
|
|
23899
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
23900
|
+
};
|
|
23863
23901
|
}).meta({ id: "ManagedSettings" });
|
|
23864
23902
|
|
|
23865
23903
|
// ../../packages/schema/src/zod/project-files.ts
|
|
@@ -23983,7 +24021,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23983
24021
|
timestamp: external_exports.iso.date(),
|
|
23984
24022
|
critical: external_exports.number().int().nonnegative(),
|
|
23985
24023
|
high: external_exports.number().int().nonnegative(),
|
|
23986
|
-
medium: external_exports.number().int().nonnegative()
|
|
24024
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24025
|
+
// Optional and additive, so a producer written against the earlier
|
|
24026
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24027
|
+
// absent case itself — the chart point requires a number.
|
|
24028
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23987
24029
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23988
24030
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23989
24031
|
range: TimeRange,
|
|
@@ -24009,6 +24051,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24009
24051
|
findingKey: external_exports.string(),
|
|
24010
24052
|
ruleId: external_exports.string(),
|
|
24011
24053
|
severity: Severity,
|
|
24054
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24055
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24056
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24057
|
+
repo: external_exports.string().optional(),
|
|
24012
24058
|
path: external_exports.string(),
|
|
24013
24059
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24014
24060
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -25582,7 +25628,8 @@ var SqliteActivityRepository = class {
|
|
|
25582
25628
|
SELECT 1 FROM audit_events d
|
|
25583
25629
|
WHERE d.root_session_id = audit_events.id
|
|
25584
25630
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25585
|
-
OR json_extract(d.attributes, '$.detail')
|
|
25631
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
25632
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25586
25633
|
);
|
|
25587
25634
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25588
25635
|
}
|
|
@@ -26920,23 +26967,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26920
26967
|
)`;
|
|
26921
26968
|
|
|
26922
26969
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26923
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26924
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26925
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26926
|
-
function compareLocationOrder(a, b) {
|
|
26927
|
-
return compareFindingGroupOrder(
|
|
26928
|
-
{
|
|
26929
|
-
severity: a.maxSeverity,
|
|
26930
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26931
|
-
id: ""
|
|
26932
|
-
},
|
|
26933
|
-
{
|
|
26934
|
-
severity: b.maxSeverity,
|
|
26935
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26936
|
-
id: ""
|
|
26937
|
-
}
|
|
26938
|
-
);
|
|
26939
|
-
}
|
|
26940
26970
|
var CONCAT_SEP = ",";
|
|
26941
26971
|
var TUPLE_SEP = "|";
|
|
26942
26972
|
function splitConcat(value) {
|
|
@@ -26988,13 +27018,48 @@ function decodeGroupCursor(cursor) {
|
|
|
26988
27018
|
return null;
|
|
26989
27019
|
}
|
|
26990
27020
|
function firstAfter(sorted, cursor) {
|
|
26991
|
-
const index = sorted.findIndex((
|
|
27021
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26992
27022
|
return index === -1 ? sorted.length : index;
|
|
26993
27023
|
}
|
|
26994
27024
|
function findDeepLinked(sorted, page, id) {
|
|
26995
|
-
if (page.some((
|
|
26996
|
-
return sorted.find((
|
|
27025
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
27026
|
+
return sorted.find((t) => t.id === id);
|
|
27027
|
+
}
|
|
27028
|
+
function encodeLocationCursor(location) {
|
|
27029
|
+
const payload = {
|
|
27030
|
+
sev: location.maxSeverity,
|
|
27031
|
+
t: location.latestDetectedAt,
|
|
27032
|
+
r: location.repo,
|
|
27033
|
+
f: location.file
|
|
27034
|
+
};
|
|
27035
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
27036
|
+
}
|
|
27037
|
+
function decodeLocationCursor(cursor) {
|
|
27038
|
+
const parsed2 = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
27039
|
+
if (parsed2 !== void 0 && typeof parsed2.sev === "string" && typeof parsed2.t === "string" && typeof parsed2.r === "string" && typeof parsed2.f === "string") {
|
|
27040
|
+
return { maxSeverity: parsed2.sev, latestDetectedAt: parsed2.t, repo: parsed2.r, file: parsed2.f };
|
|
27041
|
+
}
|
|
27042
|
+
return null;
|
|
26997
27043
|
}
|
|
27044
|
+
function firstLocationAfter(sorted, cursor) {
|
|
27045
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
27046
|
+
return index === -1 ? sorted.length : index;
|
|
27047
|
+
}
|
|
27048
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
27049
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
27050
|
+
return sorted.find((l) => l.id === id);
|
|
27051
|
+
}
|
|
27052
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
27053
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
27054
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27055
|
+
e.started_at AS occurred_at,
|
|
27056
|
+
e.source_tool AS source_tool,
|
|
27057
|
+
e.repo AS repo,
|
|
27058
|
+
e.file_path AS file,
|
|
27059
|
+
e.tool_name AS tool_name,
|
|
27060
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27061
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27062
|
+
${latestResolutionStatusSql("f")} AS latest_status`;
|
|
26998
27063
|
var DAY_MS3 = 864e5;
|
|
26999
27064
|
var SqliteFindingsRepository = class {
|
|
27000
27065
|
constructor(db) {
|
|
@@ -27115,30 +27180,26 @@ var SqliteFindingsRepository = class {
|
|
|
27115
27180
|
);
|
|
27116
27181
|
}
|
|
27117
27182
|
/**
|
|
27118
|
-
*
|
|
27119
|
-
*
|
|
27120
|
-
*
|
|
27121
|
-
*
|
|
27122
|
-
*
|
|
27123
|
-
*
|
|
27124
|
-
*
|
|
27125
|
-
*
|
|
27126
|
-
*
|
|
27127
|
-
*
|
|
27128
|
-
*
|
|
27129
|
-
*
|
|
27183
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
27184
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
27185
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
27186
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
27187
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
27188
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
27189
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
27190
|
+
* derived status was requested.
|
|
27191
|
+
*
|
|
27192
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
27193
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
27194
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
27195
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
27196
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
27130
27197
|
*
|
|
27131
|
-
* Two reads, neither of which materializes a row per finding:
|
|
27132
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
27133
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
27134
|
-
* latest, search text);
|
|
27135
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
27136
|
-
* populate `instances` for the table's expanded rows.
|
|
27137
27198
|
* The aggregates carry raw DB values and are translated by the same
|
|
27138
|
-
* @akasecurity/schema mappers
|
|
27139
|
-
* rule is ever restated in SQL.
|
|
27199
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
27200
|
+
* status rule is ever restated in SQL.
|
|
27140
27201
|
*/
|
|
27141
|
-
|
|
27202
|
+
listFindingTypes(query) {
|
|
27142
27203
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
27143
27204
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
27144
27205
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -27151,12 +27212,7 @@ var SqliteFindingsRepository = class {
|
|
|
27151
27212
|
predicate,
|
|
27152
27213
|
params: sessionParams
|
|
27153
27214
|
});
|
|
27154
|
-
const
|
|
27155
|
-
sessionId: query.sessionId,
|
|
27156
|
-
from: query.from
|
|
27157
|
-
});
|
|
27158
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27159
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
27215
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27160
27216
|
const filterOpts = {
|
|
27161
27217
|
severity: query.severity,
|
|
27162
27218
|
providers: query.provider,
|
|
@@ -27165,30 +27221,25 @@ var SqliteFindingsRepository = class {
|
|
|
27165
27221
|
subtype: query.subtype,
|
|
27166
27222
|
q: query.q
|
|
27167
27223
|
};
|
|
27168
|
-
const facets = computeFindingFacets(
|
|
27169
|
-
const sorted =
|
|
27224
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
27225
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27170
27226
|
const statusFilter = query.status ?? [];
|
|
27171
27227
|
const totals = {
|
|
27172
|
-
findings: sorted.reduce((acc,
|
|
27173
|
-
if (statusFilter.length === 0) return acc +
|
|
27174
|
-
const agg = aggregates.get(
|
|
27175
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
27228
|
+
findings: sorted.reduce((acc, t) => {
|
|
27229
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
27230
|
+
const agg = aggregates.get(t.id);
|
|
27231
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27176
27232
|
}, 0),
|
|
27177
|
-
|
|
27233
|
+
types: sorted.length
|
|
27178
27234
|
};
|
|
27179
|
-
const limit = query.limit ??
|
|
27235
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27180
27236
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27181
27237
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27182
27238
|
const page = sorted.slice(start, start + limit);
|
|
27183
27239
|
const lastOnPage = page.at(-1);
|
|
27184
27240
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27185
27241
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27186
|
-
const
|
|
27187
|
-
const narrow = (g) => statusSet ? {
|
|
27188
|
-
...g,
|
|
27189
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27190
|
-
} : g;
|
|
27191
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
27242
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27192
27243
|
return Promise.resolve({
|
|
27193
27244
|
totals,
|
|
27194
27245
|
facets,
|
|
@@ -27199,7 +27250,7 @@ var SqliteFindingsRepository = class {
|
|
|
27199
27250
|
}
|
|
27200
27251
|
/**
|
|
27201
27252
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27202
|
-
*
|
|
27253
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27203
27254
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27204
27255
|
*
|
|
27205
27256
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27293,13 +27344,25 @@ var SqliteFindingsRepository = class {
|
|
|
27293
27344
|
});
|
|
27294
27345
|
}
|
|
27295
27346
|
/**
|
|
27296
|
-
* The same findings folded by
|
|
27347
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27297
27348
|
*
|
|
27298
27349
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27299
|
-
* the local store relates a finding to
|
|
27300
|
-
*
|
|
27301
|
-
* empty-string bucket, which
|
|
27302
|
-
*
|
|
27350
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
27351
|
+
* by instead. A repo or file the event did not record folds into the
|
|
27352
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
27353
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
27354
|
+
*
|
|
27355
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
27356
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
27357
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
27358
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
27359
|
+
* place.
|
|
27360
|
+
*
|
|
27361
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
27362
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
27363
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
27364
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
27365
|
+
* its fields.
|
|
27303
27366
|
*/
|
|
27304
27367
|
listFindingLocations(query) {
|
|
27305
27368
|
const opts = {
|
|
@@ -27311,13 +27374,16 @@ var SqliteFindingsRepository = class {
|
|
|
27311
27374
|
tools: query.tool,
|
|
27312
27375
|
q: query.q
|
|
27313
27376
|
};
|
|
27314
|
-
const limit = query.limit ??
|
|
27377
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
27378
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27315
27379
|
const byRepo = /* @__PURE__ */ new Map();
|
|
27380
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27316
27381
|
let total = 0;
|
|
27317
27382
|
for (const row of this.scanFindingRows({
|
|
27318
27383
|
sessionId: query.sessionId,
|
|
27319
27384
|
from: query.from
|
|
27320
27385
|
})) {
|
|
27386
|
+
accumulator.add(row);
|
|
27321
27387
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27322
27388
|
total += 1;
|
|
27323
27389
|
let files = byRepo.get(row.repo);
|
|
@@ -27332,103 +27398,35 @@ var SqliteFindingsRepository = class {
|
|
|
27332
27398
|
}
|
|
27333
27399
|
addToLocation(acc, row);
|
|
27334
27400
|
}
|
|
27335
|
-
|
|
27336
|
-
const
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
|
|
27345
|
-
|
|
27346
|
-
|
|
27347
|
-
|
|
27348
|
-
|
|
27349
|
-
|
|
27350
|
-
|
|
27351
|
-
|
|
27352
|
-
|
|
27353
|
-
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
|
|
27357
|
-
);
|
|
27358
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27359
|
-
const folded = foldGroupStatus(statuses);
|
|
27360
|
-
return {
|
|
27361
|
-
repo,
|
|
27362
|
-
instanceCount: rollup.instanceCount,
|
|
27363
|
-
maxSeverity: rollup.maxSeverity,
|
|
27364
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27365
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27366
|
-
files: fileRows
|
|
27367
|
-
};
|
|
27368
|
-
});
|
|
27369
|
-
repos.sort(compareLocationOrder);
|
|
27401
|
+
const sorted = [];
|
|
27402
|
+
for (const [repo, files] of byRepo) {
|
|
27403
|
+
for (const [file2, acc] of files) {
|
|
27404
|
+
const status = foldGroupStatus(acc.statuses);
|
|
27405
|
+
sorted.push({
|
|
27406
|
+
id: encodeLocationId(repo, file2),
|
|
27407
|
+
repo,
|
|
27408
|
+
file: file2,
|
|
27409
|
+
instanceCount: acc.instanceCount,
|
|
27410
|
+
maxSeverity: acc.maxSeverity,
|
|
27411
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
27412
|
+
...status === void 0 ? {} : { status },
|
|
27413
|
+
ruleIds: [...acc.ruleIds]
|
|
27414
|
+
});
|
|
27415
|
+
}
|
|
27416
|
+
}
|
|
27417
|
+
sorted.sort(compareLocationOrder);
|
|
27418
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
27419
|
+
const page = sorted.slice(start, start + limit);
|
|
27420
|
+
const lastOnPage = page.at(-1);
|
|
27421
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
27422
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27370
27423
|
return Promise.resolve({
|
|
27371
|
-
totals: { findings: total,
|
|
27372
|
-
|
|
27373
|
-
|
|
27424
|
+
totals: { findings: total, locations: sorted.length },
|
|
27425
|
+
facets: accumulator.facets(),
|
|
27426
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
27427
|
+
nextCursor
|
|
27374
27428
|
});
|
|
27375
27429
|
}
|
|
27376
|
-
/**
|
|
27377
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27378
|
-
*
|
|
27379
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27380
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27381
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27382
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27383
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27384
|
-
* store while the answer does not.
|
|
27385
|
-
*
|
|
27386
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27387
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27388
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27389
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27390
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27391
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27392
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27393
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27394
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27395
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27396
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27397
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27398
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27399
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27400
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27401
|
-
* sort of the scope, which is still that floor.
|
|
27402
|
-
*
|
|
27403
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27404
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27405
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27406
|
-
* built from.
|
|
27407
|
-
*/
|
|
27408
|
-
previewRows(aggregates, scope) {
|
|
27409
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27410
|
-
let remaining = 0;
|
|
27411
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27412
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27413
|
-
wanted.set(ruleId, n);
|
|
27414
|
-
remaining += n;
|
|
27415
|
-
}
|
|
27416
|
-
const rows = [];
|
|
27417
|
-
if (remaining === 0) return rows;
|
|
27418
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27419
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27420
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27421
|
-
const want = wanted.get(r.rule_id);
|
|
27422
|
-
if (want === void 0) continue;
|
|
27423
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27424
|
-
if (have >= want) continue;
|
|
27425
|
-
taken.set(r.rule_id, have + 1);
|
|
27426
|
-
rows.push(r);
|
|
27427
|
-
remaining -= 1;
|
|
27428
|
-
if (remaining === 0) break;
|
|
27429
|
-
}
|
|
27430
|
-
return rows;
|
|
27431
|
-
}
|
|
27432
27430
|
/**
|
|
27433
27431
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27434
27432
|
*
|
|
@@ -27455,6 +27453,33 @@ var SqliteFindingsRepository = class {
|
|
|
27455
27453
|
yield toFlatFindingRow(r);
|
|
27456
27454
|
}
|
|
27457
27455
|
}
|
|
27456
|
+
/**
|
|
27457
|
+
* One finding by its own id, or null when no such row exists.
|
|
27458
|
+
*
|
|
27459
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
27460
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
27461
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
27462
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
27463
|
+
* older than anything a first page holds.
|
|
27464
|
+
*
|
|
27465
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
27466
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
27467
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
27468
|
+
* worse than showing it.
|
|
27469
|
+
*
|
|
27470
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
27471
|
+
* type should the list select?" and "what does the drawer show?".
|
|
27472
|
+
*/
|
|
27473
|
+
findingInstance(id) {
|
|
27474
|
+
const row = this.db.prepare(
|
|
27475
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27476
|
+
FROM inspection_findings f
|
|
27477
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
27478
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27479
|
+
WHERE f.id = ?`
|
|
27480
|
+
).get(id);
|
|
27481
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
27482
|
+
}
|
|
27458
27483
|
/**
|
|
27459
27484
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27460
27485
|
* joined to its event and definition, newest first.
|
|
@@ -27488,17 +27513,7 @@ var SqliteFindingsRepository = class {
|
|
|
27488
27513
|
conditions.push("e.started_at >= ?");
|
|
27489
27514
|
params.push(isoToEpochMillis(scope.from));
|
|
27490
27515
|
}
|
|
27491
|
-
const sql = `SELECT
|
|
27492
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27493
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27494
|
-
e.started_at AS occurred_at,
|
|
27495
|
-
e.source_tool AS source_tool,
|
|
27496
|
-
e.repo AS repo,
|
|
27497
|
-
e.file_path AS file,
|
|
27498
|
-
e.tool_name AS tool_name,
|
|
27499
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27500
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27501
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
27516
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27502
27517
|
FROM audit_events e
|
|
27503
27518
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27504
27519
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27512,6 +27527,26 @@ var SqliteFindingsRepository = class {
|
|
|
27512
27527
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27513
27528
|
const rows = this.db.prepare(
|
|
27514
27529
|
`SELECT rule_id,
|
|
27530
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
27531
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
27532
|
+
-- in an aggregate query, every bare column takes its value from
|
|
27533
|
+
-- the row that produced the extremum. So these are the severity
|
|
27534
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
27535
|
+
-- is what the row-based build they replaced read off its first
|
|
27536
|
+
-- (newest-first) row.
|
|
27537
|
+
--
|
|
27538
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
27539
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
27540
|
+
-- mints a new row), so a rule whose severity moved between
|
|
27541
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
27542
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
27543
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
27544
|
+
-- filter, the facet counts and the primary sort key.
|
|
27545
|
+
--
|
|
27546
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
27547
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
27548
|
+
severity,
|
|
27549
|
+
category,
|
|
27515
27550
|
sum(tuple_count) AS instance_count,
|
|
27516
27551
|
max(latest_at) AS latest_at,
|
|
27517
27552
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27522,6 +27557,14 @@ var SqliteFindingsRepository = class {
|
|
|
27522
27557
|
group_concat(tool_names) AS tool_names
|
|
27523
27558
|
FROM (
|
|
27524
27559
|
SELECT d.rule_id AS rule_id,
|
|
27560
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
27561
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
27562
|
+
-- these are grouped on below and resolved to the newest
|
|
27563
|
+
-- firing version by the outer query's bare-column select.
|
|
27564
|
+
-- They ride the aggregate because the type build has no rows
|
|
27565
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
27566
|
+
d.severity AS severity,
|
|
27567
|
+
d.category AS category,
|
|
27525
27568
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27526
27569
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27527
27570
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27536,7 +27579,7 @@ var SqliteFindingsRepository = class {
|
|
|
27536
27579
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27537
27580
|
ON latest.finding_key = f.finding_key
|
|
27538
27581
|
${scope.predicate}
|
|
27539
|
-
GROUP BY d.rule_id, status_tuple
|
|
27582
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27540
27583
|
)
|
|
27541
27584
|
GROUP BY rule_id`
|
|
27542
27585
|
).all(scope.params);
|
|
@@ -27545,6 +27588,8 @@ var SqliteFindingsRepository = class {
|
|
|
27545
27588
|
r.rule_id,
|
|
27546
27589
|
{
|
|
27547
27590
|
instanceCount: r.instance_count,
|
|
27591
|
+
severity: r.severity,
|
|
27592
|
+
category: r.category,
|
|
27548
27593
|
sourceTools: splitConcat(r.source_tools),
|
|
27549
27594
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27550
27595
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27561,7 +27606,7 @@ var SqliteFindingsRepository = class {
|
|
|
27561
27606
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27562
27607
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27563
27608
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27564
|
-
// Left undefined (not '') when unfetched, so
|
|
27609
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27565
27610
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27566
27611
|
// and skip priming a haystack nothing will read.
|
|
27567
27612
|
...withSearchText ? {
|
|
@@ -27713,6 +27758,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
27713
27758
|
this.markOwedStmt = db.prepare(
|
|
27714
27759
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27715
27760
|
);
|
|
27761
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27762
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
27763
|
+
WHERE synced_at IS NULL
|
|
27764
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27765
|
+
AND started_at < :before`
|
|
27766
|
+
);
|
|
27716
27767
|
this.stampStmt = db.prepare(
|
|
27717
27768
|
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27718
27769
|
);
|
|
@@ -27761,7 +27812,9 @@ var SqliteHistorySyncRepository = class {
|
|
|
27761
27812
|
);
|
|
27762
27813
|
this.disownCapturesStmt = db.prepare(
|
|
27763
27814
|
`UPDATE audit_events SET outbox_owed = NULL
|
|
27764
|
-
WHERE outbox_owed IS NOT NULL
|
|
27815
|
+
WHERE outbox_owed IS NOT NULL
|
|
27816
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27817
|
+
AND started_at < :attachedAt`
|
|
27765
27818
|
);
|
|
27766
27819
|
this.rearmStmt = db.prepare(
|
|
27767
27820
|
`UPDATE audit_events SET synced_at = NULL
|
|
@@ -27837,6 +27890,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27837
27890
|
freezeBoundaryStmt;
|
|
27838
27891
|
captureRowsStmt;
|
|
27839
27892
|
markOwedStmt;
|
|
27893
|
+
markCaptureBacklogOwedStmt;
|
|
27840
27894
|
captureSkipCountStmt;
|
|
27841
27895
|
disownCapturesStmt;
|
|
27842
27896
|
partitionStmt;
|
|
@@ -27900,6 +27954,23 @@ var SqliteHistorySyncRepository = class {
|
|
|
27900
27954
|
markCaptureOwed(id) {
|
|
27901
27955
|
this.markOwedStmt.run({ id });
|
|
27902
27956
|
}
|
|
27957
|
+
/**
|
|
27958
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
27959
|
+
*
|
|
27960
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
27961
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27962
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
27963
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27964
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27965
|
+
* later re-attach or key rotation might widen it to.
|
|
27966
|
+
*
|
|
27967
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27968
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27969
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27970
|
+
*/
|
|
27971
|
+
markCaptureBacklogOwed(before) {
|
|
27972
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27973
|
+
}
|
|
27903
27974
|
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27904
27975
|
markSynced(ids, atMs) {
|
|
27905
27976
|
this.stampAll(ids, atMs);
|
|
@@ -28016,15 +28087,42 @@ var SqliteHistorySyncRepository = class {
|
|
|
28016
28087
|
*
|
|
28017
28088
|
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
28018
28089
|
* machine has just left are undelivered as far as the new one is concerned.
|
|
28019
|
-
* All
|
|
28020
|
-
* attributed to the wrong deployment,
|
|
28090
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
28091
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
28092
|
+
* a disown with no re-mark to follow it.
|
|
28021
28093
|
*
|
|
28022
28094
|
* The boundary is written HERE and only here, which is what freezes it: a
|
|
28023
28095
|
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
28024
28096
|
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
28025
28097
|
* the live path has since delivered.
|
|
28098
|
+
*
|
|
28099
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
28100
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
28101
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
28102
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
28103
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
28104
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
28105
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
28106
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
28107
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
28108
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
28109
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
28110
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
28111
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
28112
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
28113
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
28114
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
28115
|
+
*
|
|
28116
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
28117
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
28118
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
28119
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
28120
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
28121
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
28122
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
28123
|
+
* transaction above.
|
|
28026
28124
|
*/
|
|
28027
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
28125
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
28028
28126
|
this.ensureRowStmt.run();
|
|
28029
28127
|
withTransaction(
|
|
28030
28128
|
this.db,
|
|
@@ -28032,7 +28130,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
28032
28130
|
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
28033
28131
|
this.rearmStmt.run();
|
|
28034
28132
|
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
28035
|
-
this.disownCapturesStmt.run();
|
|
28133
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
28134
|
+
}
|
|
28135
|
+
if (backfillCapturesBefore !== void 0) {
|
|
28136
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
28036
28137
|
}
|
|
28037
28138
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
28038
28139
|
},
|
|
@@ -28312,7 +28413,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28312
28413
|
}
|
|
28313
28414
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28314
28415
|
}
|
|
28315
|
-
|
|
28416
|
+
var testOnlyManagedPaths = null;
|
|
28417
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28316
28418
|
for (const path of paths) {
|
|
28317
28419
|
let text;
|
|
28318
28420
|
try {
|
|
@@ -30792,7 +30894,7 @@ function toUtcDateString(ms) {
|
|
|
30792
30894
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30793
30895
|
}
|
|
30794
30896
|
function isTimeseriesSeverity(s) {
|
|
30795
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
30897
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30796
30898
|
}
|
|
30797
30899
|
var SqliteSecurityRepository = class {
|
|
30798
30900
|
constructor(db, now = () => Date.now()) {
|
|
@@ -30921,12 +31023,16 @@ var SqliteSecurityRepository = class {
|
|
|
30921
31023
|
const now = this.now();
|
|
30922
31024
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
30923
31025
|
const rows = this.findingsInRange(windowStart, now);
|
|
30924
|
-
const points = Array.from(
|
|
30925
|
-
|
|
30926
|
-
|
|
30927
|
-
|
|
30928
|
-
|
|
30929
|
-
|
|
31026
|
+
const points = Array.from(
|
|
31027
|
+
{ length: numBuckets },
|
|
31028
|
+
(_, i) => ({
|
|
31029
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
31030
|
+
critical: 0,
|
|
31031
|
+
high: 0,
|
|
31032
|
+
medium: 0,
|
|
31033
|
+
low: 0
|
|
31034
|
+
})
|
|
31035
|
+
);
|
|
30930
31036
|
for (const r of rows) {
|
|
30931
31037
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
30932
31038
|
const bucket = points[idx];
|
|
@@ -31144,6 +31250,7 @@ var SqliteSecurityRepository = class {
|
|
|
31144
31250
|
`SELECT f.finding_key AS finding_key,
|
|
31145
31251
|
d.rule_id AS rule_id,
|
|
31146
31252
|
d.severity AS severity,
|
|
31253
|
+
e.repo AS repo,
|
|
31147
31254
|
e.file_path AS path,
|
|
31148
31255
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31149
31256
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31163,6 +31270,7 @@ var SqliteSecurityRepository = class {
|
|
|
31163
31270
|
const items = rows.map((r) => ({
|
|
31164
31271
|
findingKey: r.finding_key,
|
|
31165
31272
|
ruleId: r.rule_id,
|
|
31273
|
+
repo: r.repo ?? "",
|
|
31166
31274
|
severity: r.severity,
|
|
31167
31275
|
path: r.path ?? "",
|
|
31168
31276
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31172,13 +31280,66 @@ var SqliteSecurityRepository = class {
|
|
|
31172
31280
|
}));
|
|
31173
31281
|
return Promise.resolve({ items });
|
|
31174
31282
|
}
|
|
31283
|
+
/**
|
|
31284
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31285
|
+
*
|
|
31286
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31287
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31288
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31289
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31290
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31291
|
+
*
|
|
31292
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31293
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31294
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31295
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31296
|
+
* The two answer different questions and only this one has to match a link.
|
|
31297
|
+
*
|
|
31298
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31299
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31300
|
+
*/
|
|
31301
|
+
recommendationInputs() {
|
|
31302
|
+
const rows = allRows(
|
|
31303
|
+
this.db.prepare(
|
|
31304
|
+
`SELECT d.rule_id AS rule_id,
|
|
31305
|
+
d.category AS category,
|
|
31306
|
+
d.severity AS severity,
|
|
31307
|
+
COUNT(*) AS count
|
|
31308
|
+
FROM inspection_findings f
|
|
31309
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31310
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31311
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31312
|
+
ON latest.finding_key = f.finding_key
|
|
31313
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31314
|
+
AND e.event_type = 'code_change'
|
|
31315
|
+
AND (
|
|
31316
|
+
f.finding_key IS NULL
|
|
31317
|
+
OR latest.status IS NULL
|
|
31318
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31319
|
+
)
|
|
31320
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31321
|
+
)
|
|
31322
|
+
);
|
|
31323
|
+
return Promise.resolve(
|
|
31324
|
+
rows.map((r) => ({
|
|
31325
|
+
ruleId: r.rule_id,
|
|
31326
|
+
category: r.category,
|
|
31327
|
+
severity: r.severity,
|
|
31328
|
+
count: r.count
|
|
31329
|
+
}))
|
|
31330
|
+
);
|
|
31331
|
+
}
|
|
31175
31332
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31176
31333
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31177
31334
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31178
31335
|
findingsInRange(fromMs, toMs) {
|
|
31179
31336
|
const rows = allRows(
|
|
31180
31337
|
this.db.prepare(
|
|
31181
|
-
`
|
|
31338
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31339
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31340
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31341
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31342
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31182
31343
|
FROM inspection_findings f
|
|
31183
31344
|
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31184
31345
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -31191,7 +31352,9 @@ var SqliteSecurityRepository = class {
|
|
|
31191
31352
|
return rows.map((r) => ({
|
|
31192
31353
|
occurredAt: r.occurred_at,
|
|
31193
31354
|
severity: r.severity,
|
|
31194
|
-
actionTaken: r.action_taken
|
|
31355
|
+
actionTaken: r.action_taken,
|
|
31356
|
+
ruleId: r.rule_id,
|
|
31357
|
+
category: r.category
|
|
31195
31358
|
}));
|
|
31196
31359
|
}
|
|
31197
31360
|
};
|
|
@@ -32361,6 +32524,43 @@ function openLocalDatabase(dir) {
|
|
|
32361
32524
|
};
|
|
32362
32525
|
}
|
|
32363
32526
|
|
|
32527
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32528
|
+
import { createHash as createHash3 } from "crypto";
|
|
32529
|
+
function hashProjectKey(projectKey) {
|
|
32530
|
+
return createHash3("sha256").update(projectKey, "utf8").digest("hex");
|
|
32531
|
+
}
|
|
32532
|
+
function toIngestHit(hit) {
|
|
32533
|
+
return {
|
|
32534
|
+
host: hit.host,
|
|
32535
|
+
kind: hit.kind,
|
|
32536
|
+
name: hit.name,
|
|
32537
|
+
category: hit.category,
|
|
32538
|
+
trust: hit.trust,
|
|
32539
|
+
network: hit.network,
|
|
32540
|
+
method: hit.method,
|
|
32541
|
+
transport: hit.transport,
|
|
32542
|
+
url: hit.url,
|
|
32543
|
+
template: hit.template,
|
|
32544
|
+
dataClass: hit.dataClass,
|
|
32545
|
+
site: {
|
|
32546
|
+
file: hit.site.file,
|
|
32547
|
+
line: hit.site.line,
|
|
32548
|
+
dynamic: hit.site.dynamic,
|
|
32549
|
+
vendored: hit.site.vendored
|
|
32550
|
+
}
|
|
32551
|
+
};
|
|
32552
|
+
}
|
|
32553
|
+
function toEgressIngestRequest(input2) {
|
|
32554
|
+
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
32555
|
+
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
32556
|
+
return {
|
|
32557
|
+
projectKey: hashProjectKey(input2.projectKey),
|
|
32558
|
+
project: input2.project,
|
|
32559
|
+
reconcile,
|
|
32560
|
+
hits: hits.map(toIngestHit)
|
|
32561
|
+
};
|
|
32562
|
+
}
|
|
32563
|
+
|
|
32364
32564
|
// ../../packages/persistence/src/exception-policy.ts
|
|
32365
32565
|
var UserGrantPolicyProvider = class {
|
|
32366
32566
|
#exceptions;
|
|
@@ -32382,13 +32582,13 @@ var UserGrantPolicyProvider = class {
|
|
|
32382
32582
|
};
|
|
32383
32583
|
|
|
32384
32584
|
// ../../packages/persistence/src/finding-key.ts
|
|
32385
|
-
import { createHash as
|
|
32585
|
+
import { createHash as createHash4 } from "crypto";
|
|
32386
32586
|
function normalizeFilePath(filePath) {
|
|
32387
32587
|
return filePath.replaceAll("\\", "/");
|
|
32388
32588
|
}
|
|
32389
32589
|
function computeFindingKey(input2) {
|
|
32390
32590
|
const normalizedPath = normalizeFilePath(input2.filePath);
|
|
32391
|
-
return
|
|
32591
|
+
return createHash4("sha256").update(`${input2.ruleId}\0${normalizedPath}\0${input2.valueFingerprint}`).digest("hex");
|
|
32392
32592
|
}
|
|
32393
32593
|
|
|
32394
32594
|
// ../../packages/persistence/src/fingerprint.ts
|
|
@@ -32514,14 +32714,18 @@ function fingerprintValue(key, raw) {
|
|
|
32514
32714
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
32515
32715
|
}
|
|
32516
32716
|
|
|
32517
|
-
// ../../packages/persistence/src/history-
|
|
32717
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
32518
32718
|
import { existsSync as existsSync4 } from "fs";
|
|
32519
32719
|
import { join as join9 } from "path";
|
|
32720
|
+
|
|
32721
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
32722
|
+
import { existsSync as existsSync5 } from "fs";
|
|
32723
|
+
import { join as join10 } from "path";
|
|
32520
32724
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32521
32725
|
|
|
32522
32726
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32523
|
-
import { existsSync as
|
|
32524
|
-
import { dirname as dirname3, join as
|
|
32727
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32728
|
+
import { dirname as dirname3, join as join11, resolve } from "path";
|
|
32525
32729
|
|
|
32526
32730
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32527
32731
|
import {
|
|
@@ -32635,7 +32839,7 @@ function formatPointer(category, keyVersion, pointerId, tag) {
|
|
|
32635
32839
|
import { execFileSync } from "child_process";
|
|
32636
32840
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32637
32841
|
import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
32638
|
-
import { join as
|
|
32842
|
+
import { join as join12 } from "path";
|
|
32639
32843
|
var VAULT_OCCUPANT_REASON = {
|
|
32640
32844
|
symlink: "the path is a symlink; remove it so a keyring can be created",
|
|
32641
32845
|
gone: "the path was occupied but holds no keyring (removed while it was being created)",
|
|
@@ -32734,7 +32938,7 @@ function claimRotationLock(lock, owner) {
|
|
|
32734
32938
|
throw asError(err);
|
|
32735
32939
|
}
|
|
32736
32940
|
try {
|
|
32737
|
-
writeFileSync3(
|
|
32941
|
+
writeFileSync3(join12(lock, LOCK_OWNER_FILE), `${owner}
|
|
32738
32942
|
`, { mode: DATA_FILE_MODE });
|
|
32739
32943
|
return true;
|
|
32740
32944
|
} catch (err) {
|
|
@@ -32743,7 +32947,7 @@ function claimRotationLock(lock, owner) {
|
|
|
32743
32947
|
}
|
|
32744
32948
|
}
|
|
32745
32949
|
function acquireRotationLock(keysDir2) {
|
|
32746
|
-
const lock =
|
|
32950
|
+
const lock = join12(keysDir2, `${VAULT_KEY_FILENAME}.lock`);
|
|
32747
32951
|
const owner = randomBytes2(16).toString("hex");
|
|
32748
32952
|
if (claimRotationLock(lock, owner)) return { lock, owner };
|
|
32749
32953
|
let held;
|
|
@@ -32770,7 +32974,7 @@ function acquireRotationLock(keysDir2) {
|
|
|
32770
32974
|
}
|
|
32771
32975
|
function releaseRotationLock(lease) {
|
|
32772
32976
|
try {
|
|
32773
|
-
if (readFileSync7(
|
|
32977
|
+
if (readFileSync7(join12(lease.lock, LOCK_OWNER_FILE), "utf8").trim() !== lease.owner) return;
|
|
32774
32978
|
} catch {
|
|
32775
32979
|
return;
|
|
32776
32980
|
}
|
|
@@ -32791,7 +32995,7 @@ var FileKeyProvider = class {
|
|
|
32791
32995
|
this.#keysDir = keysDir2;
|
|
32792
32996
|
}
|
|
32793
32997
|
get filePath() {
|
|
32794
|
-
return
|
|
32998
|
+
return join12(this.#keysDir, VAULT_KEY_FILENAME);
|
|
32795
32999
|
}
|
|
32796
33000
|
loadOrCreate() {
|
|
32797
33001
|
return asAsync(() => {
|
|
@@ -33456,13 +33660,13 @@ var SecretVault = class {
|
|
|
33456
33660
|
};
|
|
33457
33661
|
|
|
33458
33662
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
33459
|
-
import { existsSync as
|
|
33460
|
-
import { join as
|
|
33663
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
33664
|
+
import { join as join13 } from "path";
|
|
33461
33665
|
var MARKER = "warn-era-capped";
|
|
33462
33666
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
33463
33667
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
33464
|
-
const marker =
|
|
33465
|
-
if (
|
|
33668
|
+
const marker = join13(dataDir2, MARKER);
|
|
33669
|
+
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
33466
33670
|
const capped = db.policies.capCategoryActions();
|
|
33467
33671
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
33468
33672
|
`, { mode: DATA_FILE_MODE });
|
|
@@ -33470,8 +33674,8 @@ function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
|
33470
33674
|
}
|
|
33471
33675
|
|
|
33472
33676
|
// ../../packages/plugin-sdk/src/config.ts
|
|
33473
|
-
import { existsSync as
|
|
33474
|
-
import { join as
|
|
33677
|
+
import { existsSync as existsSync8 } from "fs";
|
|
33678
|
+
import { join as join14 } from "path";
|
|
33475
33679
|
|
|
33476
33680
|
// ../../packages/plugin-sdk/src/provider-env.ts
|
|
33477
33681
|
var DEFAULT_ANTHROPIC_HOST = "api.anthropic.com";
|
|
@@ -33525,8 +33729,8 @@ function resolveProvider() {
|
|
|
33525
33729
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
33526
33730
|
try {
|
|
33527
33731
|
ensureLayoutDirSync(base);
|
|
33528
|
-
const settingsFile =
|
|
33529
|
-
if (
|
|
33732
|
+
const settingsFile = join14(settingsDir(base), "settings.json");
|
|
33733
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
33530
33734
|
} catch {
|
|
33531
33735
|
}
|
|
33532
33736
|
migrateLegacyLayout(base);
|
|
@@ -33551,7 +33755,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
33551
33755
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
33552
33756
|
import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
33553
33757
|
import { homedir as homedir2 } from "os";
|
|
33554
|
-
import { basename as basename3, join as
|
|
33758
|
+
import { basename as basename3, join as join16 } from "path";
|
|
33555
33759
|
|
|
33556
33760
|
// ../../packages/detections/src/egress/registry.ts
|
|
33557
33761
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -36640,8 +36844,8 @@ function bundledDetections() {
|
|
|
36640
36844
|
}
|
|
36641
36845
|
|
|
36642
36846
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
36643
|
-
import { existsSync as
|
|
36644
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
36847
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
|
|
36848
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join15, sep as sep2 } from "path";
|
|
36645
36849
|
function resolveRepo(cwd) {
|
|
36646
36850
|
try {
|
|
36647
36851
|
const root = findGitRoot(cwd);
|
|
@@ -36663,32 +36867,32 @@ function resolveWorktreeRoot(cwd) {
|
|
|
36663
36867
|
function findGitRoot(start) {
|
|
36664
36868
|
let dir = start;
|
|
36665
36869
|
for (; ; ) {
|
|
36666
|
-
if (
|
|
36870
|
+
if (existsSync9(join15(dir, ".git"))) return dir;
|
|
36667
36871
|
const parent = dirname4(dir);
|
|
36668
36872
|
if (parent === dir) return void 0;
|
|
36669
36873
|
dir = parent;
|
|
36670
36874
|
}
|
|
36671
36875
|
}
|
|
36672
36876
|
function resolveGitContext(root) {
|
|
36673
|
-
const dotGit =
|
|
36877
|
+
const dotGit = join15(root, ".git");
|
|
36674
36878
|
try {
|
|
36675
36879
|
if (statSync6(dotGit).isDirectory()) {
|
|
36676
|
-
return { configPath:
|
|
36880
|
+
return { configPath: join15(dotGit, "config"), headRoot: root };
|
|
36677
36881
|
}
|
|
36678
36882
|
} catch {
|
|
36679
36883
|
return void 0;
|
|
36680
36884
|
}
|
|
36681
36885
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
36682
36886
|
if (!target) return void 0;
|
|
36683
|
-
const gitdir = isAbsolute(target) ? target :
|
|
36684
|
-
if (
|
|
36685
|
-
return { configPath:
|
|
36887
|
+
const gitdir = isAbsolute(target) ? target : join15(root, target);
|
|
36888
|
+
if (existsSync9(join15(gitdir, "config"))) {
|
|
36889
|
+
return { configPath: join15(gitdir, "config"), headRoot: root };
|
|
36686
36890
|
}
|
|
36687
|
-
const commonRaw = safeRead(
|
|
36891
|
+
const commonRaw = safeRead(join15(gitdir, "commondir"))?.trim();
|
|
36688
36892
|
if (!commonRaw) return void 0;
|
|
36689
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
36893
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join15(gitdir, commonRaw);
|
|
36690
36894
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
36691
|
-
return { configPath:
|
|
36895
|
+
return { configPath: join15(commonGitDir, "config"), headRoot };
|
|
36692
36896
|
}
|
|
36693
36897
|
function safeRead(path) {
|
|
36694
36898
|
try {
|
|
@@ -36730,9 +36934,9 @@ function slugFromUrl(url2) {
|
|
|
36730
36934
|
}
|
|
36731
36935
|
|
|
36732
36936
|
// ../../packages/plugin-sdk/src/events.ts
|
|
36733
|
-
import { createHash as
|
|
36937
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
36734
36938
|
function contentHashOf(text) {
|
|
36735
|
-
return
|
|
36939
|
+
return createHash5("sha256").update(text).digest("hex");
|
|
36736
36940
|
}
|
|
36737
36941
|
function buildIngestEvent(input2) {
|
|
36738
36942
|
const contentHash = input2.contentHash ?? contentHashOf(input2.content);
|
|
@@ -36758,7 +36962,7 @@ function buildIngestEvent(input2) {
|
|
|
36758
36962
|
}
|
|
36759
36963
|
|
|
36760
36964
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
36761
|
-
import { existsSync as
|
|
36965
|
+
import { existsSync as existsSync10 } from "fs";
|
|
36762
36966
|
import { fileURLToPath } from "url";
|
|
36763
36967
|
import { Worker } from "worker_threads";
|
|
36764
36968
|
var ISOLATED_SCAN_BUDGET_MS = 2e3;
|
|
@@ -36772,7 +36976,7 @@ function resolveWorkerUrl() {
|
|
|
36772
36976
|
for (const name of ["scan-worker.js", "scan-worker.ts"]) {
|
|
36773
36977
|
const candidate = new URL(name, import.meta.url);
|
|
36774
36978
|
try {
|
|
36775
|
-
if (
|
|
36979
|
+
if (existsSync10(fileURLToPath(candidate))) {
|
|
36776
36980
|
resolvedWorkerUrl = candidate;
|
|
36777
36981
|
return candidate;
|
|
36778
36982
|
}
|
|
@@ -37235,13 +37439,9 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
37235
37439
|
};
|
|
37236
37440
|
}
|
|
37237
37441
|
|
|
37238
|
-
// ../../packages/plugin-sdk/src/
|
|
37239
|
-
|
|
37240
|
-
import {
|
|
37241
|
-
import { join as join16 } from "path";
|
|
37242
|
-
|
|
37243
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
37244
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
37442
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
37443
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
37444
|
+
import { join as join18 } from "path";
|
|
37245
37445
|
|
|
37246
37446
|
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
37247
37447
|
import {
|
|
@@ -37249,16 +37449,42 @@ import {
|
|
|
37249
37449
|
fstatSync,
|
|
37250
37450
|
mkdirSync as mkdirSync2,
|
|
37251
37451
|
openSync as openSync2,
|
|
37252
|
-
readFileSync as
|
|
37452
|
+
readFileSync as readFileSync10,
|
|
37253
37453
|
readSync,
|
|
37254
37454
|
writeFileSync as writeFileSync5
|
|
37255
37455
|
} from "fs";
|
|
37256
37456
|
import { join as join17 } from "path";
|
|
37257
37457
|
var TAIL_BYTES = 256 * 1024;
|
|
37258
37458
|
|
|
37459
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
37460
|
+
var HOST_FEATURE = {
|
|
37461
|
+
ModelSwitch: "model-switch",
|
|
37462
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
37463
|
+
};
|
|
37464
|
+
var HOST_FLOORS = {
|
|
37465
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
37466
|
+
label: "model-switch protection",
|
|
37467
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
37468
|
+
since: "2.1.251"
|
|
37469
|
+
},
|
|
37470
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
37471
|
+
label: "vault pointer display",
|
|
37472
|
+
hookEvents: ["MessageDisplay"],
|
|
37473
|
+
since: "2.1.152"
|
|
37474
|
+
}
|
|
37475
|
+
};
|
|
37476
|
+
|
|
37477
|
+
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
37478
|
+
var import_ignore = __toESM(require_ignore(), 1);
|
|
37479
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
37480
|
+
import { join as join19 } from "path";
|
|
37481
|
+
|
|
37482
|
+
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
37483
|
+
import { arch, hostname as hostname4, platform, release } from "os";
|
|
37484
|
+
|
|
37259
37485
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
37260
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
37261
|
-
import { join as
|
|
37486
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
37487
|
+
import { join as join20 } from "path";
|
|
37262
37488
|
|
|
37263
37489
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
37264
37490
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
@@ -37310,8 +37536,8 @@ function applyCategoryPosture(posture, repo, mode = "fill-gaps") {
|
|
|
37310
37536
|
}
|
|
37311
37537
|
|
|
37312
37538
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
37313
|
-
import { existsSync as
|
|
37314
|
-
import { basename as basename5, join as
|
|
37539
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
37540
|
+
import { basename as basename5, join as join21 } from "path";
|
|
37315
37541
|
|
|
37316
37542
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
37317
37543
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -37352,6 +37578,14 @@ function safeMaskedMatch(rawMatch) {
|
|
|
37352
37578
|
// ../../packages/plugin-sdk/src/runtime.ts
|
|
37353
37579
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
37354
37580
|
var ENFORCEMENT_CEILING_ENABLED = false;
|
|
37581
|
+
function applyEnforcementCeiling(action, policyMode, enabled) {
|
|
37582
|
+
if (!enabled || policyMode !== "warn") return action;
|
|
37583
|
+
return action === "block" || action === "redact" ? "warn" : action;
|
|
37584
|
+
}
|
|
37585
|
+
function resolveEnforcedAction(action, opts) {
|
|
37586
|
+
const degraded = !opts.rewritable && action === "redact" ? builtinPolicyToAction(opts.redactFallback) : action;
|
|
37587
|
+
return applyEnforcementCeiling(degraded, opts.policyMode, opts.ceilingEnabled);
|
|
37588
|
+
}
|
|
37355
37589
|
function startTiming() {
|
|
37356
37590
|
try {
|
|
37357
37591
|
return performance.now();
|
|
@@ -37460,12 +37694,12 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
37460
37694
|
}
|
|
37461
37695
|
function actionForFinding(finding, excepted, rewritable = true) {
|
|
37462
37696
|
if (excepted?.has(finding)) return "allow";
|
|
37463
|
-
|
|
37464
|
-
|
|
37465
|
-
|
|
37466
|
-
|
|
37467
|
-
|
|
37468
|
-
|
|
37697
|
+
return resolveEnforcedAction(resolveAction(finding.ruleId, finding.category), {
|
|
37698
|
+
policyMode,
|
|
37699
|
+
redactFallback,
|
|
37700
|
+
rewritable,
|
|
37701
|
+
ceilingEnabled: ENFORCEMENT_CEILING_ENABLED
|
|
37702
|
+
});
|
|
37469
37703
|
}
|
|
37470
37704
|
function decide(findings, text, excepted, rewritable = true) {
|
|
37471
37705
|
if (findings.length === 0) return { action: "log", text, findings: [] };
|
|
@@ -37714,7 +37948,7 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
37714
37948
|
|
|
37715
37949
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
37716
37950
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
37717
|
-
import { join as
|
|
37951
|
+
import { join as join22 } from "path";
|
|
37718
37952
|
|
|
37719
37953
|
// ../../packages/plugin-sdk/src/tokenize.ts
|
|
37720
37954
|
function redactedPlaceholder(category) {
|
|
@@ -38070,7 +38304,7 @@ function routeRemediationOption(option, handlers) {
|
|
|
38070
38304
|
|
|
38071
38305
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
38072
38306
|
import { writeFileSync as writeFileSync8 } from "fs";
|
|
38073
|
-
import { join as
|
|
38307
|
+
import { join as join23 } from "path";
|
|
38074
38308
|
var GENERIC_CONSOLE_PATH = "rotate via the provider's own console";
|
|
38075
38309
|
var CONSOLE_PATHS = {
|
|
38076
38310
|
anthropic: "console.anthropic.com \u2192 Settings \u2192 API keys",
|
|
@@ -38170,7 +38404,7 @@ function generateRotationChecklist(input2) {
|
|
|
38170
38404
|
try {
|
|
38171
38405
|
const target = resolveRotationChecklistTarget(input2.cwd);
|
|
38172
38406
|
targetDirectory = target.directory;
|
|
38173
|
-
const filePath =
|
|
38407
|
+
const filePath = join23(target.directory, "rotation-checklist.md");
|
|
38174
38408
|
writeRotationChecklist(input2.entries, target.directory);
|
|
38175
38409
|
return {
|
|
38176
38410
|
status: "written",
|
|
@@ -38281,9 +38515,9 @@ var RANK = Object.fromEntries(
|
|
|
38281
38515
|
);
|
|
38282
38516
|
|
|
38283
38517
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
38284
|
-
import { mkdtempSync, readFileSync as
|
|
38518
|
+
import { mkdtempSync, readFileSync as readFileSync14, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
|
|
38285
38519
|
import { tmpdir } from "os";
|
|
38286
|
-
import { basename as basename6, dirname as dirname6, join as
|
|
38520
|
+
import { basename as basename6, dirname as dirname6, join as join24 } from "path";
|
|
38287
38521
|
var SuppressionEntrySchema = external_exports.object({
|
|
38288
38522
|
ruleId: external_exports.string(),
|
|
38289
38523
|
category: DetectionCategory,
|
|
@@ -38487,44 +38721,7 @@ function renderRemediationDecision(findings, moreCount, registry2) {
|
|
|
38487
38721
|
}
|
|
38488
38722
|
|
|
38489
38723
|
// src/remediation/surfaced-redact.ts
|
|
38490
|
-
import { readFileSync as
|
|
38491
|
-
|
|
38492
|
-
// ../../packages/plugin-runtime/src/attached/egress-wire.ts
|
|
38493
|
-
import { createHash as createHash5 } from "crypto";
|
|
38494
|
-
function hashProjectKey(projectKey) {
|
|
38495
|
-
return createHash5("sha256").update(projectKey, "utf8").digest("hex");
|
|
38496
|
-
}
|
|
38497
|
-
function toIngestHit(hit) {
|
|
38498
|
-
return {
|
|
38499
|
-
host: hit.host,
|
|
38500
|
-
kind: hit.kind,
|
|
38501
|
-
name: hit.name,
|
|
38502
|
-
category: hit.category,
|
|
38503
|
-
trust: hit.trust,
|
|
38504
|
-
network: hit.network,
|
|
38505
|
-
method: hit.method,
|
|
38506
|
-
transport: hit.transport,
|
|
38507
|
-
url: hit.url,
|
|
38508
|
-
template: hit.template,
|
|
38509
|
-
dataClass: hit.dataClass,
|
|
38510
|
-
site: {
|
|
38511
|
-
file: hit.site.file,
|
|
38512
|
-
line: hit.site.line,
|
|
38513
|
-
dynamic: hit.site.dynamic,
|
|
38514
|
-
vendored: hit.site.vendored
|
|
38515
|
-
}
|
|
38516
|
-
};
|
|
38517
|
-
}
|
|
38518
|
-
function toEgressIngestRequest(input2) {
|
|
38519
|
-
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
38520
|
-
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
38521
|
-
return {
|
|
38522
|
-
projectKey: hashProjectKey(input2.projectKey),
|
|
38523
|
-
project: input2.project,
|
|
38524
|
-
reconcile,
|
|
38525
|
-
hits: hits.map(toIngestHit)
|
|
38526
|
-
};
|
|
38527
|
-
}
|
|
38724
|
+
import { readFileSync as readFileSync22 } from "fs";
|
|
38528
38725
|
|
|
38529
38726
|
// ../../packages/remote/src/http.ts
|
|
38530
38727
|
import { request as httpRequest } from "http";
|
|
@@ -38805,6 +39002,7 @@ function createRemoteClient(options) {
|
|
|
38805
39002
|
url: url2(ROUTES.shares),
|
|
38806
39003
|
body: JSON.stringify(validated.data)
|
|
38807
39004
|
});
|
|
39005
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
38808
39006
|
okBody(response);
|
|
38809
39007
|
},
|
|
38810
39008
|
async pollCommand() {
|
|
@@ -38827,19 +39025,51 @@ function createRemoteClient(options) {
|
|
|
38827
39025
|
};
|
|
38828
39026
|
}
|
|
38829
39027
|
|
|
38830
|
-
// ../../packages/
|
|
39028
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
38831
39029
|
function statusOf(err) {
|
|
38832
39030
|
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
38833
39031
|
const { status } = err;
|
|
38834
39032
|
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
38835
39033
|
return status >= 100 && status <= 599 ? status : null;
|
|
38836
39034
|
}
|
|
38837
|
-
function
|
|
38838
|
-
|
|
39035
|
+
function nameOf(err) {
|
|
39036
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
39037
|
+
return typeof err.name === "string" ? err.name : null;
|
|
39038
|
+
}
|
|
39039
|
+
function classifyRemoteFailure(err) {
|
|
39040
|
+
switch (nameOf(err)) {
|
|
39041
|
+
case "RemoteRouteAbsent":
|
|
39042
|
+
return "route-absent";
|
|
39043
|
+
case "RemoteRequestInvalid":
|
|
39044
|
+
return "invalid-request";
|
|
39045
|
+
case "RemoteResponseInvalid":
|
|
39046
|
+
return "rejected";
|
|
39047
|
+
default:
|
|
39048
|
+
break;
|
|
39049
|
+
}
|
|
39050
|
+
const status = statusOf(err);
|
|
39051
|
+
if (status === null) return "unreachable";
|
|
39052
|
+
switch (status) {
|
|
38839
39053
|
case 401:
|
|
38840
39054
|
return "unauthorized";
|
|
38841
39055
|
case 403:
|
|
38842
39056
|
return "forbidden";
|
|
39057
|
+
case 429:
|
|
39058
|
+
return "unreachable";
|
|
39059
|
+
case 404:
|
|
39060
|
+
return "unreachable";
|
|
39061
|
+
default:
|
|
39062
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
39063
|
+
}
|
|
39064
|
+
}
|
|
39065
|
+
|
|
39066
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
39067
|
+
function classifyFailure(err) {
|
|
39068
|
+
switch (classifyRemoteFailure(err)) {
|
|
39069
|
+
case "unauthorized":
|
|
39070
|
+
return "unauthorized";
|
|
39071
|
+
case "forbidden":
|
|
39072
|
+
return "forbidden";
|
|
38843
39073
|
default:
|
|
38844
39074
|
return "unreachable";
|
|
38845
39075
|
}
|
|
@@ -38861,11 +39091,11 @@ function withTimeout(promise2, ms) {
|
|
|
38861
39091
|
}
|
|
38862
39092
|
|
|
38863
39093
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
38864
|
-
import { readFileSync as
|
|
38865
|
-
import { join as
|
|
39094
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
39095
|
+
import { join as join25 } from "path";
|
|
38866
39096
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
38867
39097
|
function forwardDropsPath(dataDir2) {
|
|
38868
|
-
return
|
|
39098
|
+
return join25(dataDir2, FORWARD_DROPS_FILENAME);
|
|
38869
39099
|
}
|
|
38870
39100
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
38871
39101
|
if (count <= 0) return;
|
|
@@ -38883,7 +39113,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
38883
39113
|
}
|
|
38884
39114
|
function readForwardDrops(dataDir2) {
|
|
38885
39115
|
try {
|
|
38886
|
-
const parsed2 = JSON.parse(
|
|
39116
|
+
const parsed2 = JSON.parse(readFileSync15(forwardDropsPath(dataDir2), "utf8"));
|
|
38887
39117
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
38888
39118
|
const record2 = parsed2;
|
|
38889
39119
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -38901,9 +39131,9 @@ function readForwardDrops(dataDir2) {
|
|
|
38901
39131
|
|
|
38902
39132
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
38903
39133
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
38904
|
-
import { readFileSync as
|
|
39134
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
38905
39135
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
38906
|
-
import { join as
|
|
39136
|
+
import { join as join26 } from "path";
|
|
38907
39137
|
function isInvalidRequest(err) {
|
|
38908
39138
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
38909
39139
|
}
|
|
@@ -38941,7 +39171,7 @@ function parseBreakerState(raw, nowMs) {
|
|
|
38941
39171
|
}
|
|
38942
39172
|
function createForwardPolicy(deps) {
|
|
38943
39173
|
const now = deps.now ?? (() => Date.now());
|
|
38944
|
-
const file2 =
|
|
39174
|
+
const file2 = join26(deps.dir, STATE_FILENAME);
|
|
38945
39175
|
let state = null;
|
|
38946
39176
|
let loading = null;
|
|
38947
39177
|
async function readState() {
|
|
@@ -39663,8 +39893,8 @@ function toolAuditEvent(input2) {
|
|
|
39663
39893
|
}
|
|
39664
39894
|
|
|
39665
39895
|
// ../../packages/plugin-runtime/src/attached/history-state.ts
|
|
39666
|
-
import { readFileSync as
|
|
39667
|
-
import { join as
|
|
39896
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
39897
|
+
import { join as join27 } from "path";
|
|
39668
39898
|
|
|
39669
39899
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
39670
39900
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -39681,7 +39911,7 @@ import { fileURLToPath as fileURLToPath3 } from "url";
|
|
|
39681
39911
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
39682
39912
|
|
|
39683
39913
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
39684
|
-
import { readFileSync as
|
|
39914
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
39685
39915
|
function createPluginBlock(build, policyStore) {
|
|
39686
39916
|
return async () => {
|
|
39687
39917
|
const cached2 = await policyStore.read();
|
|
@@ -39700,7 +39930,7 @@ function createPluginBlock(build, policyStore) {
|
|
|
39700
39930
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
39701
39931
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
39702
39932
|
import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
39703
|
-
import { join as
|
|
39933
|
+
import { join as join28 } from "path";
|
|
39704
39934
|
|
|
39705
39935
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
39706
39936
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -39724,7 +39954,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
39724
39954
|
|
|
39725
39955
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
39726
39956
|
function createPolicyStore(dir = dataDir()) {
|
|
39727
|
-
const file2 =
|
|
39957
|
+
const file2 = join28(dir, "policy-cache.json");
|
|
39728
39958
|
async function read() {
|
|
39729
39959
|
try {
|
|
39730
39960
|
const raw = await readFile2(file2, "utf8");
|
|
@@ -39955,11 +40185,11 @@ function readStorePosture(dbPath2) {
|
|
|
39955
40185
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
39956
40186
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
39957
40187
|
import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
39958
|
-
import { join as
|
|
40188
|
+
import { join as join29 } from "path";
|
|
39959
40189
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
39960
40190
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
39961
|
-
const file2 =
|
|
39962
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
40191
|
+
const file2 = join29(dir, "posture-state.json");
|
|
40192
|
+
const legacyFile = legacyDir === void 0 ? null : join29(legacyDir, "posture-state.json");
|
|
39963
40193
|
async function persist(state) {
|
|
39964
40194
|
await ensureDataDir(dir);
|
|
39965
40195
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -40027,8 +40257,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
40027
40257
|
}
|
|
40028
40258
|
|
|
40029
40259
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
40030
|
-
import { readFileSync as
|
|
40031
|
-
import { join as
|
|
40260
|
+
import { readFileSync as readFileSync19 } from "fs";
|
|
40261
|
+
import { join as join30 } from "path";
|
|
40032
40262
|
|
|
40033
40263
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
40034
40264
|
var REFUSAL_LINES = {
|
|
@@ -40499,11 +40729,11 @@ import { randomUUID as randomUUID19 } from "crypto";
|
|
|
40499
40729
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
40500
40730
|
|
|
40501
40731
|
// src/history/transcripts.ts
|
|
40502
|
-
import { readdirSync as readdirSync6, readFileSync as
|
|
40732
|
+
import { readdirSync as readdirSync6, readFileSync as readFileSync20 } from "fs";
|
|
40503
40733
|
import { homedir as homedir3 } from "os";
|
|
40504
|
-
import { join as
|
|
40734
|
+
import { join as join31 } from "path";
|
|
40505
40735
|
function transcriptsDir(home) {
|
|
40506
|
-
return
|
|
40736
|
+
return join31(home ?? homedir3(), ".claude", "projects");
|
|
40507
40737
|
}
|
|
40508
40738
|
var DAY_MS5 = 24 * 60 * 60 * 1e3;
|
|
40509
40739
|
|
|
@@ -40511,14 +40741,14 @@ var DAY_MS5 = 24 * 60 * 60 * 1e3;
|
|
|
40511
40741
|
import {
|
|
40512
40742
|
lstatSync as lstatSync4,
|
|
40513
40743
|
readdirSync as readdirSync7,
|
|
40514
|
-
readFileSync as
|
|
40744
|
+
readFileSync as readFileSync21,
|
|
40515
40745
|
realpathSync as realpathSync4,
|
|
40516
40746
|
renameSync as renameSync5,
|
|
40517
40747
|
rmSync as rmSync8,
|
|
40518
40748
|
statSync as statSync10,
|
|
40519
40749
|
writeFileSync as writeFileSync10
|
|
40520
40750
|
} from "fs";
|
|
40521
|
-
import { basename as basename7, dirname as dirname7, isAbsolute as isAbsolute2, join as
|
|
40751
|
+
import { basename as basename7, dirname as dirname7, isAbsolute as isAbsolute2, join as join32, relative, resolve as resolve2 } from "path";
|
|
40522
40752
|
var REDACTED_PLACEHOLDER = "[REDACTED:SECRET]";
|
|
40523
40753
|
var REPLACE_PATTERN_SEQUENCE = /\$[$&`'<0-9]/;
|
|
40524
40754
|
function replacementFor(rawValue, replacements) {
|
|
@@ -40577,7 +40807,7 @@ function sweepStrandedTemps(realPath) {
|
|
|
40577
40807
|
const pid = Number(pidPart);
|
|
40578
40808
|
if (pid !== process.pid && isProcessAlive(pid)) continue;
|
|
40579
40809
|
try {
|
|
40580
|
-
const stranded =
|
|
40810
|
+
const stranded = join32(dir, name);
|
|
40581
40811
|
if (!lstatSync4(stranded).isFile()) continue;
|
|
40582
40812
|
rmSync8(stranded, { force: true });
|
|
40583
40813
|
} catch {
|
|
@@ -40602,7 +40832,7 @@ function redactLeakedKeysDetailed(targets, scope = platformRedactionScope(), rep
|
|
|
40602
40832
|
let mode;
|
|
40603
40833
|
try {
|
|
40604
40834
|
mode = statSync10(filePath).mode & 511;
|
|
40605
|
-
content =
|
|
40835
|
+
content = readFileSync21(filePath, "utf8");
|
|
40606
40836
|
} catch {
|
|
40607
40837
|
continue;
|
|
40608
40838
|
}
|
|
@@ -40727,7 +40957,7 @@ async function redactSurfacedSecrets(findings, overrides = {}) {
|
|
|
40727
40957
|
for (const [filePath, fileFindings] of byFile) {
|
|
40728
40958
|
let content;
|
|
40729
40959
|
try {
|
|
40730
|
-
content =
|
|
40960
|
+
content = readFileSync22(filePath, "utf8");
|
|
40731
40961
|
} catch {
|
|
40732
40962
|
unrecovered.push(...fileFindings);
|
|
40733
40963
|
continue;
|
|
@@ -40892,7 +41122,7 @@ if (process.argv[1] && fileURLToPath5(import.meta.url) === process.argv[1]) {
|
|
|
40892
41122
|
try {
|
|
40893
41123
|
const argv = process.argv.slice(2);
|
|
40894
41124
|
const optionIndex = argv.indexOf("--option");
|
|
40895
|
-
const frameText =
|
|
41125
|
+
const frameText = readFileSync23(0, "utf8");
|
|
40896
41126
|
if (optionIndex === -1) {
|
|
40897
41127
|
present(frameText);
|
|
40898
41128
|
} else {
|