@akasecurity/ai-tc-codex 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/.codex-plugin/plugin.json +1 -1
- package/package.json +4 -4
- package/scripts/apply-suppressions.js +627 -435
- package/scripts/backfill.js +727 -497
- package/scripts/filescan.js +726 -496
- package/scripts/firstrun.js +775 -519
- package/scripts/history-sync.js +611 -418
- package/scripts/intro.js +242 -92
- package/scripts/onboard.js +603 -410
- package/scripts/post-tool-use.js +711 -483
- package/scripts/pre-tool-use.js +715 -485
- package/scripts/query.js +780 -524
- package/scripts/reconcile.js +707 -485
- package/scripts/remediate.js +725 -495
- package/scripts/scan-worker.js +153 -58
- package/scripts/session-start.js +755 -535
- package/scripts/start-light.js +240 -90
- package/scripts/stop.js +264 -116
- package/scripts/sync.js +722 -494
- package/scripts/user-prompt-submit.js +719 -489
package/scripts/backfill.js
CHANGED
|
@@ -495,8 +495,8 @@ var require_ignore = __commonJS({
|
|
|
495
495
|
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
496
496
|
|
|
497
497
|
// ../../packages/plugin-sdk/src/config.ts
|
|
498
|
-
import { existsSync as
|
|
499
|
-
import { join as
|
|
498
|
+
import { existsSync as existsSync8 } from "fs";
|
|
499
|
+
import { join as join14 } from "path";
|
|
500
500
|
|
|
501
501
|
// ../../packages/persistence/src/attached-derived.ts
|
|
502
502
|
import { rmSync } from "fs";
|
|
@@ -20749,13 +20749,11 @@ var FindingGroup = external_exports.object({
|
|
|
20749
20749
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20750
20750
|
instances: external_exports.array(FindingInstance),
|
|
20751
20751
|
// Derived from instances' statuses with open-dominates precedence (see
|
|
20752
|
-
//
|
|
20752
|
+
// foldGroupStatus). Undefined only when no instance carries a status.
|
|
20753
20753
|
status: FindingStatus.optional(),
|
|
20754
|
-
// The distinct people across the WHOLE group, not just the
|
|
20755
|
-
//
|
|
20756
|
-
//
|
|
20757
|
-
// instance carries a user, or when the store supplied whole-group folds
|
|
20758
|
-
// without one.
|
|
20754
|
+
// The distinct people across the WHOLE group, not just the instances
|
|
20755
|
+
// carried here. Undefined when no instance carries a user, or when the
|
|
20756
|
+
// store supplied whole-group folds without one.
|
|
20759
20757
|
users: external_exports.array(FindingUser).optional()
|
|
20760
20758
|
}).meta({ id: "FindingGroup" });
|
|
20761
20759
|
var FindingStats = external_exports.object({
|
|
@@ -20784,21 +20782,31 @@ var FindingFacets = external_exports.object({
|
|
|
20784
20782
|
// counted under no value.
|
|
20785
20783
|
status: external_exports.array(FindingFacetItem),
|
|
20786
20784
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20787
|
-
// reads, which can filter by it; the
|
|
20785
|
+
// reads, which can filter by it; the type-level read omits the dimension
|
|
20788
20786
|
// because a group spans tools.
|
|
20789
20787
|
tool: external_exports.array(FindingFacetItem).optional()
|
|
20790
20788
|
}).meta({ id: "FindingFacets" });
|
|
20791
|
-
var
|
|
20792
|
-
|
|
20789
|
+
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20790
|
+
id: "FindingTypeSummary"
|
|
20791
|
+
});
|
|
20792
|
+
var DEFAULT_FINDING_TYPES_LIMIT = 50;
|
|
20793
|
+
var MAX_FINDING_TYPES_LIMIT = 100;
|
|
20794
|
+
var ListFindingTypesQuery = external_exports.object({
|
|
20793
20795
|
// NOTE: severity filters by Severity (critical/high/medium/low), not by
|
|
20794
|
-
// FindingAction.
|
|
20796
|
+
// FindingAction. It narrows TYPES: a type's severity is the one its newest
|
|
20797
|
+
// firing version carries, and this list pages types.
|
|
20798
|
+
//
|
|
20799
|
+
// That is NOT a claim the findings of a type share it. A rule can hold several
|
|
20800
|
+
// definition versions at different severities, so a type kept by this filter
|
|
20801
|
+
// can hold findings that individually do not match — see totals.findings on
|
|
20802
|
+
// ListFindingTypesResponse, which counts them all.
|
|
20795
20803
|
severity: external_exports.array(Severity).optional(),
|
|
20796
20804
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20797
20805
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20798
20806
|
action: external_exports.array(FindingAction).optional(),
|
|
20799
|
-
// Matches a
|
|
20800
|
-
// individual
|
|
20801
|
-
//
|
|
20807
|
+
// Matches a type's DERIVED status (see FindingGroup.status), not its
|
|
20808
|
+
// individual findings' — so a filtered row's status always reads one of the
|
|
20809
|
+
// requested values.
|
|
20802
20810
|
status: external_exports.array(FindingStatus).optional(),
|
|
20803
20811
|
q: external_exports.string().optional(),
|
|
20804
20812
|
// Scope to findings whose event carries this session id (the Activity page's
|
|
@@ -20808,23 +20816,37 @@ var ListGroupedFindingsQuery = external_exports.object({
|
|
|
20808
20816
|
// from a time-scoped page (Activity's range) can carry that scope. Absent
|
|
20809
20817
|
// means all time — this list has no default window.
|
|
20810
20818
|
from: external_exports.iso.datetime().optional(),
|
|
20811
|
-
// A
|
|
20812
|
-
//
|
|
20813
|
-
//
|
|
20814
|
-
//
|
|
20815
|
-
//
|
|
20819
|
+
// A RULE id that must appear in the page even when the cursor has already
|
|
20820
|
+
// advanced past its sort position. This is what keeps the selected type
|
|
20821
|
+
// visible in the list once it paginates: the target is appended out of sort
|
|
20822
|
+
// order rather than scanned forward for. Never affects totals, facets or the
|
|
20823
|
+
// cursor. Unlike the grouped read this replaces, it names a rule only — an
|
|
20824
|
+
// instance id is resolved by `findingInstance`, which is a primary-key seek
|
|
20825
|
+
// and so is not bounded by what any page happens to hold.
|
|
20816
20826
|
includeId: external_exports.string().optional(),
|
|
20817
|
-
|
|
20818
|
-
limit: external_exports.coerce.number().int().min(1).max(100).optional(),
|
|
20827
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
|
|
20819
20828
|
cursor: external_exports.string().optional()
|
|
20820
20829
|
});
|
|
20821
|
-
var
|
|
20830
|
+
var ListFindingTypesResponse = external_exports.object({
|
|
20822
20831
|
totals: external_exports.object({
|
|
20832
|
+
// Findings belonging to the matching TYPES — not findings that each match
|
|
20833
|
+
// the filters. The filters here select types, so a type that survives
|
|
20834
|
+
// contributes its whole instanceCount.
|
|
20835
|
+
//
|
|
20836
|
+
// `status` is the one exception, narrowed per finding via
|
|
20837
|
+
// countInstancesByStatus. `severity`, `provider` and `action` are not, so
|
|
20838
|
+
// this can exceed what the instance read reports for the same filters: a
|
|
20839
|
+
// rule whose severity moved between versions is kept on its newest and
|
|
20840
|
+
// still counts its older findings. Narrowing the other three needs
|
|
20841
|
+
// per-dimension counts the aggregate does not carry today.
|
|
20823
20842
|
findings: external_exports.number().int().nonnegative(),
|
|
20824
|
-
|
|
20843
|
+
// Counts TYPES, which is the unit this read pages. The instance read's
|
|
20844
|
+
// own totals count findings; the two deliberately answer different
|
|
20845
|
+
// questions and are never summed.
|
|
20846
|
+
types: external_exports.number().int().nonnegative()
|
|
20825
20847
|
}),
|
|
20826
20848
|
facets: FindingFacets,
|
|
20827
|
-
items: external_exports.array(
|
|
20849
|
+
items: external_exports.array(FindingTypeSummary),
|
|
20828
20850
|
nextCursor: external_exports.string().nullable(),
|
|
20829
20851
|
// Present only on session-scoped queries (`sessionId` set): per ruleId, how
|
|
20830
20852
|
// many times that rule fired in the session's persisted transcript. Findings
|
|
@@ -20832,7 +20854,7 @@ var ListGroupedFindingsResponse = external_exports.object({
|
|
|
20832
20854
|
// every firing, so the two numbers legitimately differ — this map lets a
|
|
20833
20855
|
// session-scoped view show both.
|
|
20834
20856
|
sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
|
|
20835
|
-
}).meta({ id: "
|
|
20857
|
+
}).meta({ id: "ListFindingTypesResponse" });
|
|
20836
20858
|
var ApplyFindingActionRequest = external_exports.object({
|
|
20837
20859
|
// 'quarantined' is system-assigned (see FindingAction) — clients may not set
|
|
20838
20860
|
// it, so it is excluded from the request contract. The mapping helper
|
|
@@ -20862,12 +20884,13 @@ var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
|
20862
20884
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
20863
20885
|
var ListFindingInstancesQuery = external_exports.object({
|
|
20864
20886
|
severity: external_exports.array(Severity).optional(),
|
|
20865
|
-
// Rule ids, the same vocabulary the
|
|
20887
|
+
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
20888
|
+
// ONE of them is how the master/detail view scopes its right-hand panel.
|
|
20866
20889
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20867
20890
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20868
20891
|
action: external_exports.array(FindingAction).optional(),
|
|
20869
20892
|
// Matches each instance's OWN derived status (deriveFindingStatus), unlike
|
|
20870
|
-
// the
|
|
20893
|
+
// the types query's type-level fold.
|
|
20871
20894
|
status: external_exports.array(FindingStatus).optional(),
|
|
20872
20895
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20873
20896
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
@@ -20884,37 +20907,47 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20884
20907
|
});
|
|
20885
20908
|
var ListFindingInstancesResponse = external_exports.object({
|
|
20886
20909
|
// Instances matching the filters across the whole scope, not just this
|
|
20887
|
-
// page — cursor-independent, like the
|
|
20910
|
+
// page — cursor-independent, like the types list's totals.
|
|
20888
20911
|
totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
|
|
20889
|
-
// Counts in INSTANCES here, where the
|
|
20912
|
+
// Counts in INSTANCES here, where the types response counts types. Each
|
|
20890
20913
|
// dimension still excludes its own filter.
|
|
20891
20914
|
facets: FindingFacets,
|
|
20892
20915
|
items: external_exports.array(FindingInstanceDetail),
|
|
20893
20916
|
nextCursor: external_exports.string().nullable()
|
|
20894
20917
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20895
|
-
var
|
|
20896
|
-
//
|
|
20897
|
-
//
|
|
20898
|
-
|
|
20899
|
-
|
|
20900
|
-
|
|
20901
|
-
|
|
20902
|
-
// Folded from the instances' derived statuses with the same
|
|
20903
|
-
// open-dominates precedence a group uses.
|
|
20904
|
-
status: FindingStatus.optional(),
|
|
20905
|
-
// Distinct rules seen at this location, capped — the row shows them as
|
|
20906
|
-
// chips, and the count is what conveys scale.
|
|
20907
|
-
ruleIds: external_exports.array(external_exports.string())
|
|
20908
|
-
}).meta({ id: "FindingLocationFile" });
|
|
20909
|
-
var FindingLocationRepo = external_exports.object({
|
|
20918
|
+
var FindingLocationSummary = external_exports.object({
|
|
20919
|
+
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20920
|
+
// because a location's identity is two values and a URL param carries one:
|
|
20921
|
+
// `?loc=` names a location the way `?rule=` names a type. Only ever compared
|
|
20922
|
+
// for EQUALITY — the page's selection check, this read's `includeId`, the
|
|
20923
|
+
// client's page dedupe — never decoded, and never a sort key.
|
|
20924
|
+
id: external_exports.string(),
|
|
20910
20925
|
/** Empty when the instances carried no repo attribute. */
|
|
20911
20926
|
repo: external_exports.string(),
|
|
20927
|
+
// Empty when the instances carried no file path (a prompt, or a tool call
|
|
20928
|
+
// with no file attribution). Both halves empty is a real location — usually
|
|
20929
|
+
// the largest one in a store — and is selectable like any other.
|
|
20930
|
+
file: external_exports.string(),
|
|
20912
20931
|
instanceCount: external_exports.number().int().nonnegative(),
|
|
20932
|
+
// The WORST severity present, not the first row's. It is this list's primary
|
|
20933
|
+
// sort key, so it is also what explains why a row is where it is, and it is
|
|
20934
|
+
// how a reader decides what to open without opening everything.
|
|
20913
20935
|
maxSeverity: Severity,
|
|
20914
20936
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20937
|
+
// Folded from the instances' derived statuses with the same open-dominates
|
|
20938
|
+
// precedence a group uses, so it answers "is anything left to do here" and
|
|
20939
|
+
// not much more: a location holding 1 open among 40 resolved reads like one
|
|
20940
|
+
// holding 40 open. That loss is accepted — the panel beside this list
|
|
20941
|
+
// carries each finding's own status, and instanceCount sits next to the
|
|
20942
|
+
// badge.
|
|
20915
20943
|
status: FindingStatus.optional(),
|
|
20916
|
-
|
|
20917
|
-
|
|
20944
|
+
// Every distinct rule seen at this location, UNCAPPED — so the length is a
|
|
20945
|
+
// tally rather than a sample and a row can say how many there are. Bounded
|
|
20946
|
+
// by the ruleset, not by the store. The view bounds what it DISPLAYS.
|
|
20947
|
+
ruleIds: external_exports.array(external_exports.string())
|
|
20948
|
+
}).meta({ id: "FindingLocationSummary" });
|
|
20949
|
+
var DEFAULT_FINDING_LOCATIONS_LIMIT = 50;
|
|
20950
|
+
var MAX_FINDING_LOCATIONS_LIMIT = 100;
|
|
20918
20951
|
var ListFindingLocationsQuery = external_exports.object({
|
|
20919
20952
|
severity: external_exports.array(Severity).optional(),
|
|
20920
20953
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
@@ -20927,18 +20960,42 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20927
20960
|
q: external_exports.string().optional(),
|
|
20928
20961
|
sessionId: external_exports.string().optional(),
|
|
20929
20962
|
from: external_exports.iso.datetime().optional(),
|
|
20930
|
-
|
|
20963
|
+
// A LOCATION id (see FindingLocationSummary.id) that must appear in the page
|
|
20964
|
+
// even when the cursor has already advanced past its sort position — the
|
|
20965
|
+
// counterpart of ListFindingTypesQuery.includeId, and needed far more often
|
|
20966
|
+
// here. Selecting a row pushes the URL, which re-renders the server and resets
|
|
20967
|
+
// the client's page cache to page 0; with distinct (repo, file) pairs running
|
|
20968
|
+
// into the thousands, a selection sitting off page 0 is the ordinary case
|
|
20969
|
+
// rather than a deep-link corner. Never affects totals, facets or the cursor.
|
|
20970
|
+
includeId: external_exports.string().optional(),
|
|
20971
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
|
|
20972
|
+
cursor: external_exports.string().optional()
|
|
20931
20973
|
});
|
|
20932
20974
|
var ListFindingLocationsResponse = external_exports.object({
|
|
20933
20975
|
totals: external_exports.object({
|
|
20976
|
+
// Findings matching the filters across the whole scope. Unlike the types
|
|
20977
|
+
// read's same-named field this needs no caveat: the filters here narrow
|
|
20978
|
+
// per finding, so this is the sum of every row's instanceCount.
|
|
20934
20979
|
findings: external_exports.number().int().nonnegative(),
|
|
20935
|
-
|
|
20936
|
-
|
|
20980
|
+
// Counts LOCATIONS, the unit this read pages — the number the paginator
|
|
20981
|
+
// states. The facets beside it count FINDINGS (see below); a surface
|
|
20982
|
+
// showing both says which is which.
|
|
20983
|
+
locations: external_exports.number().int().nonnegative()
|
|
20937
20984
|
}),
|
|
20938
|
-
|
|
20939
|
-
|
|
20940
|
-
|
|
20941
|
-
|
|
20985
|
+
// Counts in FINDINGS, where the types response counts types, each dimension
|
|
20986
|
+
// still excluding its own filter. Deliberately not locations: counting those
|
|
20987
|
+
// needs a set of location keys per dimension per value — memory tracking the
|
|
20988
|
+
// store times the vocabulary, in a read whose scan promises flat memory —
|
|
20989
|
+
// and the cheap per-location version is not an approximation but WRONG. A
|
|
20990
|
+
// location holding {claudecode, block} and {codex, warn} would survive
|
|
20991
|
+
// provider=claudecode AND action=warn, under which no single finding
|
|
20992
|
+
// matches, so the facet would contradict the instanceCount this whole view
|
|
20993
|
+
// rests on. Findings also keep the toolbar in the same unit as the page
|
|
20994
|
+
// tally and the panel it sits above.
|
|
20995
|
+
facets: FindingFacets,
|
|
20996
|
+
/** Sorted by max severity, then most recent, then (repo, file). */
|
|
20997
|
+
items: external_exports.array(FindingLocationSummary),
|
|
20998
|
+
nextCursor: external_exports.string().nullable()
|
|
20942
20999
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
20943
21000
|
|
|
20944
21001
|
// ../../packages/schema/src/zod/meta.ts
|
|
@@ -22107,6 +22164,14 @@ var ControlPlaneErrorBody = external_exports.object({
|
|
|
22107
22164
|
message: external_exports.string().optional()
|
|
22108
22165
|
}).optional()
|
|
22109
22166
|
});
|
|
22167
|
+
var RemoteFailureKind = external_exports.enum([
|
|
22168
|
+
"unauthorized",
|
|
22169
|
+
"forbidden",
|
|
22170
|
+
"route-absent",
|
|
22171
|
+
"invalid-request",
|
|
22172
|
+
"rejected",
|
|
22173
|
+
"unreachable"
|
|
22174
|
+
]);
|
|
22110
22175
|
var AttachDeviceRequest = external_exports.object({
|
|
22111
22176
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22112
22177
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22800,139 +22865,62 @@ function deriveFindingStatus(row) {
|
|
|
22800
22865
|
if (row.latestResolutionStatus === "dismissed") return "dismissed";
|
|
22801
22866
|
return "open";
|
|
22802
22867
|
}
|
|
22803
|
-
function distinctUsers(instances) {
|
|
22804
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22805
|
-
const users = [];
|
|
22806
|
-
for (const i of instances) {
|
|
22807
|
-
if (i.user === void 0 || seen.has(i.user.id)) continue;
|
|
22808
|
-
seen.add(i.user.id);
|
|
22809
|
-
users.push(i.user);
|
|
22810
|
-
}
|
|
22811
|
-
return users;
|
|
22812
|
-
}
|
|
22813
22868
|
function sortUsers(users) {
|
|
22814
22869
|
return [...users].sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
22815
22870
|
}
|
|
22816
|
-
function
|
|
22817
|
-
const overrides = opts.overrides;
|
|
22871
|
+
function buildFindingTypes(aggregates, opts = {}) {
|
|
22818
22872
|
const packNames = opts.packNames;
|
|
22819
|
-
const
|
|
22820
|
-
const
|
|
22821
|
-
|
|
22822
|
-
const
|
|
22823
|
-
|
|
22824
|
-
else byRuleId.set(row.ruleId, [row]);
|
|
22825
|
-
}
|
|
22826
|
-
const groups = [];
|
|
22827
|
-
for (const [ruleId, ruleRows] of byRuleId) {
|
|
22828
|
-
const instances = ruleRows.map((r) => {
|
|
22829
|
-
const effectiveDbAction = overrides?.get(r.id) ?? r.actionTaken;
|
|
22830
|
-
return {
|
|
22831
|
-
id: r.id,
|
|
22832
|
-
provider: toApiProvider(r.sourceTool),
|
|
22833
|
-
repo: r.repo,
|
|
22834
|
-
file: r.file,
|
|
22835
|
-
...r.toolName === void 0 ? {} : { toolName: r.toolName },
|
|
22836
|
-
...r.eventId === void 0 ? {} : { eventId: r.eventId },
|
|
22837
|
-
...r.sessionId === void 0 ? {} : { sessionId: r.sessionId },
|
|
22838
|
-
...r.user === void 0 ? {} : { user: r.user },
|
|
22839
|
-
action: toApiAction(effectiveDbAction),
|
|
22840
|
-
detectedAt: r.occurredAt,
|
|
22841
|
-
confidence: r.confidence,
|
|
22842
|
-
status: r.status
|
|
22843
|
-
};
|
|
22844
|
-
});
|
|
22845
|
-
const agg = aggregates?.get(ruleId);
|
|
22846
|
-
const users = agg ? sortUsers(agg.users ?? []) : distinctUsers(instances);
|
|
22847
|
-
const latestDetectedAt = agg?.latestDetectedAt ?? ruleRows.reduce(
|
|
22848
|
-
(max, r) => r.occurredAt > max ? r.occurredAt : max,
|
|
22849
|
-
ruleRows[0]?.occurredAt ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
22850
|
-
);
|
|
22851
|
-
const seenProviders = /* @__PURE__ */ new Set();
|
|
22852
|
-
const providers = (agg ? [...new Set(agg.sourceTools.map(toApiProvider))].sort() : instances.map((i) => i.provider)).filter((p) => {
|
|
22853
|
-
if (seenProviders.has(p)) return false;
|
|
22854
|
-
seenProviders.add(p);
|
|
22855
|
-
return true;
|
|
22856
|
-
});
|
|
22857
|
-
const actionSet = new Set(
|
|
22858
|
-
agg ? agg.actionsTaken.map(toApiAction) : instances.map((i) => i.action)
|
|
22859
|
-
);
|
|
22873
|
+
const types = [];
|
|
22874
|
+
for (const [ruleId, agg] of aggregates) {
|
|
22875
|
+
const users = sortUsers(agg.users ?? []);
|
|
22876
|
+
const providers = [...new Set(agg.sourceTools.map(toApiProvider))].sort();
|
|
22877
|
+
const actionSet = new Set(agg.actionsTaken.map(toApiAction));
|
|
22860
22878
|
const aggregateAction = actionSet.size === 1 ? [...actionSet][0] ?? null : null;
|
|
22861
|
-
const
|
|
22862
|
-
const
|
|
22863
|
-
id: ruleId,
|
|
22864
|
-
name: packNames?.get(ruleId) ?? null
|
|
22865
|
-
};
|
|
22866
|
-
const apiCategory = toApiCategory(ruleRows[0]?.category ?? "custom");
|
|
22867
|
-
const policy = { id: `category:${apiCategory}`, name: apiCategory };
|
|
22868
|
-
const match = {
|
|
22869
|
-
maskedValue: ruleRows[0]?.maskedMatch ?? "",
|
|
22870
|
-
contextPrefix: ""
|
|
22871
|
-
// empty (pending privacy review)
|
|
22872
|
-
};
|
|
22873
|
-
const status = foldGroupStatus(
|
|
22874
|
-
agg ? agg.statusInputs.map(deriveFindingStatus) : instances.map((i) => i.status)
|
|
22875
|
-
);
|
|
22876
|
-
const group = {
|
|
22879
|
+
const apiCategory = toApiCategory(agg.category ?? "custom");
|
|
22880
|
+
const type = {
|
|
22877
22881
|
id: ruleId,
|
|
22878
22882
|
category: apiCategory,
|
|
22879
22883
|
subtype: ruleId,
|
|
22880
22884
|
// human label comes with pack metadata later
|
|
22881
|
-
severity,
|
|
22882
|
-
|
|
22883
|
-
|
|
22884
|
-
|
|
22885
|
-
instanceCount: agg?.instanceCount ?? instances.length,
|
|
22885
|
+
severity: agg.severity ?? "low",
|
|
22886
|
+
detection: { id: ruleId, name: packNames?.get(ruleId) ?? null },
|
|
22887
|
+
policy: { id: `category:${apiCategory}`, name: apiCategory },
|
|
22888
|
+
instanceCount: agg.instanceCount,
|
|
22886
22889
|
providers,
|
|
22887
22890
|
aggregateAction,
|
|
22888
|
-
latestDetectedAt,
|
|
22889
|
-
|
|
22890
|
-
status,
|
|
22891
|
+
latestDetectedAt: agg.latestDetectedAt,
|
|
22892
|
+
status: foldGroupStatus(agg.statusInputs.map(deriveFindingStatus)),
|
|
22891
22893
|
...users.length > 0 ? { users } : {}
|
|
22892
22894
|
};
|
|
22893
|
-
|
|
22894
|
-
|
|
22895
|
-
|
|
22896
|
-
haystackCache.set(group, buildHaystack(group, agg.searchText));
|
|
22897
|
-
}
|
|
22895
|
+
actionsCache.set(type, [...actionSet]);
|
|
22896
|
+
if (agg.searchText !== void 0) {
|
|
22897
|
+
haystackCache.set(type, buildHaystack(type, agg.searchText));
|
|
22898
22898
|
}
|
|
22899
|
-
|
|
22899
|
+
types.push(type);
|
|
22900
22900
|
}
|
|
22901
|
-
return
|
|
22901
|
+
return types;
|
|
22902
22902
|
}
|
|
22903
22903
|
var haystackCache = /* @__PURE__ */ new WeakMap();
|
|
22904
|
-
function buildHaystack(
|
|
22904
|
+
function buildHaystack(t, extra) {
|
|
22905
22905
|
return [
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
|
|
22909
|
-
|
|
22910
|
-
|
|
22911
|
-
...g.instances.map((i) => i.repo),
|
|
22912
|
-
...g.instances.map((i) => i.file),
|
|
22913
|
-
...g.instances.map((i) => i.toolName ? `via ${i.toolName}` : ""),
|
|
22914
|
-
...g.instances.map((i) => i.id),
|
|
22915
|
-
// The people: the whole group's list when the store folded one, plus the
|
|
22916
|
-
// preview's own — the two overlap, and a haystack does not mind.
|
|
22917
|
-
...(g.users ?? []).map((u) => u.name),
|
|
22918
|
-
...g.instances.map((i) => i.user?.name ?? ""),
|
|
22906
|
+
t.subtype,
|
|
22907
|
+
t.category,
|
|
22908
|
+
t.policy.name,
|
|
22909
|
+
t.id,
|
|
22910
|
+
...(t.users ?? []).map((u) => u.name),
|
|
22919
22911
|
...extra === void 0 ? [] : [extra]
|
|
22920
22912
|
].join(" ").toLowerCase();
|
|
22921
22913
|
}
|
|
22922
|
-
function
|
|
22923
|
-
const cached2 = haystackCache.get(
|
|
22914
|
+
function typeHaystack(t) {
|
|
22915
|
+
const cached2 = haystackCache.get(t);
|
|
22924
22916
|
if (cached2 !== void 0) return cached2;
|
|
22925
|
-
const haystack = buildHaystack(
|
|
22926
|
-
haystackCache.set(
|
|
22917
|
+
const haystack = buildHaystack(t);
|
|
22918
|
+
haystackCache.set(t, haystack);
|
|
22927
22919
|
return haystack;
|
|
22928
22920
|
}
|
|
22929
22921
|
var actionsCache = /* @__PURE__ */ new WeakMap();
|
|
22930
|
-
function
|
|
22931
|
-
|
|
22932
|
-
if (cached2 !== void 0) return cached2;
|
|
22933
|
-
const actions = [...new Set(g.instances.map((i) => i.action))];
|
|
22934
|
-
actionsCache.set(g, actions);
|
|
22935
|
-
return actions;
|
|
22922
|
+
function typeActions(t) {
|
|
22923
|
+
return actionsCache.get(t) ?? [];
|
|
22936
22924
|
}
|
|
22937
22925
|
function countInstancesByStatus(statusInputs, statuses) {
|
|
22938
22926
|
const statusSet = new Set(statuses);
|
|
@@ -22943,8 +22931,8 @@ function countInstancesByStatus(statusInputs, statuses) {
|
|
|
22943
22931
|
}
|
|
22944
22932
|
return sum;
|
|
22945
22933
|
}
|
|
22946
|
-
function applyFindingFilters(
|
|
22947
|
-
let filtered =
|
|
22934
|
+
function applyFindingFilters(types, opts) {
|
|
22935
|
+
let filtered = types;
|
|
22948
22936
|
if (opts.severity && opts.severity.length > 0) {
|
|
22949
22937
|
const sevSet = new Set(opts.severity);
|
|
22950
22938
|
filtered = filtered.filter((g) => sevSet.has(g.severity));
|
|
@@ -22955,7 +22943,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22955
22943
|
}
|
|
22956
22944
|
if (opts.actions && opts.actions.length > 0) {
|
|
22957
22945
|
const actionSet = new Set(opts.actions);
|
|
22958
|
-
filtered = filtered.filter((
|
|
22946
|
+
filtered = filtered.filter((t) => typeActions(t).some((a) => actionSet.has(a)));
|
|
22959
22947
|
}
|
|
22960
22948
|
if (opts.subtype && opts.subtype.length > 0) {
|
|
22961
22949
|
const subtypeSet = new Set(opts.subtype);
|
|
@@ -22967,7 +22955,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22967
22955
|
}
|
|
22968
22956
|
if (opts.q) {
|
|
22969
22957
|
const q = opts.q.toLowerCase();
|
|
22970
|
-
filtered = filtered.filter((
|
|
22958
|
+
filtered = filtered.filter((t) => typeHaystack(t).includes(q));
|
|
22971
22959
|
}
|
|
22972
22960
|
return filtered;
|
|
22973
22961
|
}
|
|
@@ -22982,11 +22970,11 @@ function compareFindingGroupOrder(a, b) {
|
|
|
22982
22970
|
if (recencyDiff !== 0) return recencyDiff;
|
|
22983
22971
|
return a.id.localeCompare(b.id);
|
|
22984
22972
|
}
|
|
22985
|
-
function
|
|
22986
|
-
return [...
|
|
22973
|
+
function sortFindingTypes(types) {
|
|
22974
|
+
return [...types].sort(compareFindingGroupOrder);
|
|
22987
22975
|
}
|
|
22988
|
-
function computeFindingFacets(
|
|
22989
|
-
const forSeverity = applyFindingFilters(
|
|
22976
|
+
function computeFindingFacets(allTypes, opts) {
|
|
22977
|
+
const forSeverity = applyFindingFilters(allTypes, {
|
|
22990
22978
|
providers: opts.providers,
|
|
22991
22979
|
actions: opts.actions,
|
|
22992
22980
|
statuses: opts.statuses,
|
|
@@ -22997,7 +22985,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22997
22985
|
for (const g of forSeverity) {
|
|
22998
22986
|
severityMap.set(g.severity, (severityMap.get(g.severity) ?? 0) + 1);
|
|
22999
22987
|
}
|
|
23000
|
-
const forProvider = applyFindingFilters(
|
|
22988
|
+
const forProvider = applyFindingFilters(allTypes, {
|
|
23001
22989
|
actions: opts.actions,
|
|
23002
22990
|
statuses: opts.statuses,
|
|
23003
22991
|
q: opts.q,
|
|
@@ -23008,7 +22996,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23008
22996
|
for (const g of forProvider) {
|
|
23009
22997
|
for (const p of g.providers) providerMap.set(p, (providerMap.get(p) ?? 0) + 1);
|
|
23010
22998
|
}
|
|
23011
|
-
const forAction = applyFindingFilters(
|
|
22999
|
+
const forAction = applyFindingFilters(allTypes, {
|
|
23012
23000
|
providers: opts.providers,
|
|
23013
23001
|
statuses: opts.statuses,
|
|
23014
23002
|
q: opts.q,
|
|
@@ -23017,9 +23005,9 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23017
23005
|
});
|
|
23018
23006
|
const actionMap = /* @__PURE__ */ new Map();
|
|
23019
23007
|
for (const g of forAction) {
|
|
23020
|
-
for (const a of
|
|
23008
|
+
for (const a of typeActions(g)) actionMap.set(a, (actionMap.get(a) ?? 0) + 1);
|
|
23021
23009
|
}
|
|
23022
|
-
const forSubtype = applyFindingFilters(
|
|
23010
|
+
const forSubtype = applyFindingFilters(allTypes, {
|
|
23023
23011
|
providers: opts.providers,
|
|
23024
23012
|
actions: opts.actions,
|
|
23025
23013
|
statuses: opts.statuses,
|
|
@@ -23028,7 +23016,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23028
23016
|
});
|
|
23029
23017
|
const subtypeMap = /* @__PURE__ */ new Map();
|
|
23030
23018
|
for (const g of forSubtype) subtypeMap.set(g.subtype, (subtypeMap.get(g.subtype) ?? 0) + 1);
|
|
23031
|
-
const forStatus = applyFindingFilters(
|
|
23019
|
+
const forStatus = applyFindingFilters(allTypes, {
|
|
23032
23020
|
providers: opts.providers,
|
|
23033
23021
|
actions: opts.actions,
|
|
23034
23022
|
q: opts.q,
|
|
@@ -23076,10 +23064,20 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23076
23064
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23077
23065
|
case "tools":
|
|
23078
23066
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23067
|
+
// An EMPTY value is a real filter here, not an absent one. The location
|
|
23068
|
+
// list buckets a finding whose event recorded no repo — or no file — under
|
|
23069
|
+
// the empty string, and selecting that bucket has to narrow the panel to
|
|
23070
|
+
// exactly it. Only `undefined` means "no filter"; a caller that wants every
|
|
23071
|
+
// row omits the key, which every call site already does.
|
|
23072
|
+
//
|
|
23073
|
+
// Reading '' as unset is what this replaced, and it failed in the one place
|
|
23074
|
+
// it mattered: the no-repo/no-file bucket is often the largest in a real
|
|
23075
|
+
// store, and its panel dropped both predicates and returned the WHOLE scope
|
|
23076
|
+
// — a row reading 3 findings beside a panel listing every finding there is.
|
|
23079
23077
|
case "repo":
|
|
23080
|
-
return opts.repo === void 0 ||
|
|
23078
|
+
return opts.repo === void 0 || row.repo === opts.repo;
|
|
23081
23079
|
case "file":
|
|
23082
|
-
return opts.file === void 0 ||
|
|
23080
|
+
return opts.file === void 0 || row.file === opts.file;
|
|
23083
23081
|
case "q":
|
|
23084
23082
|
return !opts.q || rowHaystack(row).includes(opts.q.toLowerCase());
|
|
23085
23083
|
}
|
|
@@ -23193,6 +23191,23 @@ function addToLocation(acc, row) {
|
|
|
23193
23191
|
acc.statuses.push(row.status);
|
|
23194
23192
|
acc.ruleIds.add(row.ruleId);
|
|
23195
23193
|
}
|
|
23194
|
+
function compareLocationOrder(a, b) {
|
|
23195
|
+
const rankA = SEVERITY_ORDER2[a.maxSeverity] ?? -1;
|
|
23196
|
+
const rankB = SEVERITY_ORDER2[b.maxSeverity] ?? -1;
|
|
23197
|
+
if (rankA !== rankB) return rankA - rankB;
|
|
23198
|
+
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23199
|
+
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23200
|
+
}
|
|
23201
|
+
if (a.repo !== b.repo) return a.repo < b.repo ? -1 : 1;
|
|
23202
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
23203
|
+
return 0;
|
|
23204
|
+
}
|
|
23205
|
+
function encodeLocationId(repo, file2) {
|
|
23206
|
+
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
23207
|
+
}
|
|
23208
|
+
function encodePart(value) {
|
|
23209
|
+
return encodeURIComponent(value.replace(/[\uD800-\uDFFF]/gu, "\uFFFD"));
|
|
23210
|
+
}
|
|
23196
23211
|
|
|
23197
23212
|
// ../../packages/schema/src/zod/installed-pack.ts
|
|
23198
23213
|
var InstalledPack = external_exports.object({
|
|
@@ -23699,11 +23714,11 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23699
23714
|
// covers the current payload and must be re-granted.
|
|
23700
23715
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23701
23716
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23702
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23703
|
-
// that covers
|
|
23704
|
-
// carry prompt/reply text in `content
|
|
23705
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23706
|
-
// payload no longer counts.
|
|
23717
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23718
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23719
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23720
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23721
|
+
// or an older payload no longer counts.
|
|
23707
23722
|
historySyncConsent: HistorySyncConsent.optional()
|
|
23708
23723
|
});
|
|
23709
23724
|
function defaultWorkspaceSettings() {
|
|
@@ -23834,6 +23849,9 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23834
23849
|
"dataSharesInPlace",
|
|
23835
23850
|
"redactFallback"
|
|
23836
23851
|
]).meta({ id: "ManagedSettingKey" });
|
|
23852
|
+
function isManagedSettingKey(value) {
|
|
23853
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
23854
|
+
}
|
|
23837
23855
|
var ManagedSettingsValues = external_exports.object({
|
|
23838
23856
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
23839
23857
|
controlPlane: external_exports.object({
|
|
@@ -23858,7 +23876,27 @@ var ManagedSettings = external_exports.object({
|
|
|
23858
23876
|
// Which of those the user may not change. A key here with no matching value
|
|
23859
23877
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23860
23878
|
// the user may still override. The two are separable on purpose.
|
|
23861
|
-
|
|
23879
|
+
//
|
|
23880
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
23881
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
23882
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
23883
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
23884
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
23885
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23886
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
23887
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23888
|
+
}).transform(({ lockedFields, ...rest }) => {
|
|
23889
|
+
const known = [];
|
|
23890
|
+
const unknown2 = [];
|
|
23891
|
+
for (const name of lockedFields) {
|
|
23892
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
23893
|
+
else unknown2.push(name);
|
|
23894
|
+
}
|
|
23895
|
+
return {
|
|
23896
|
+
...rest,
|
|
23897
|
+
lockedFields: known,
|
|
23898
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
23899
|
+
};
|
|
23862
23900
|
}).meta({ id: "ManagedSettings" });
|
|
23863
23901
|
|
|
23864
23902
|
// ../../packages/schema/src/zod/project-files.ts
|
|
@@ -23982,7 +24020,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23982
24020
|
timestamp: external_exports.iso.date(),
|
|
23983
24021
|
critical: external_exports.number().int().nonnegative(),
|
|
23984
24022
|
high: external_exports.number().int().nonnegative(),
|
|
23985
|
-
medium: external_exports.number().int().nonnegative()
|
|
24023
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24024
|
+
// Optional and additive, so a producer written against the earlier
|
|
24025
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24026
|
+
// absent case itself — the chart point requires a number.
|
|
24027
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23986
24028
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23987
24029
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23988
24030
|
range: TimeRange,
|
|
@@ -24008,6 +24050,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24008
24050
|
findingKey: external_exports.string(),
|
|
24009
24051
|
ruleId: external_exports.string(),
|
|
24010
24052
|
severity: Severity,
|
|
24053
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24054
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24055
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24056
|
+
repo: external_exports.string().optional(),
|
|
24011
24057
|
path: external_exports.string(),
|
|
24012
24058
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24013
24059
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -25581,7 +25627,8 @@ var SqliteActivityRepository = class {
|
|
|
25581
25627
|
SELECT 1 FROM audit_events d
|
|
25582
25628
|
WHERE d.root_session_id = audit_events.id
|
|
25583
25629
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25584
|
-
OR json_extract(d.attributes, '$.detail')
|
|
25630
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
25631
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25585
25632
|
);
|
|
25586
25633
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25587
25634
|
}
|
|
@@ -26919,23 +26966,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26919
26966
|
)`;
|
|
26920
26967
|
|
|
26921
26968
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26922
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26923
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26924
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26925
|
-
function compareLocationOrder(a, b) {
|
|
26926
|
-
return compareFindingGroupOrder(
|
|
26927
|
-
{
|
|
26928
|
-
severity: a.maxSeverity,
|
|
26929
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26930
|
-
id: ""
|
|
26931
|
-
},
|
|
26932
|
-
{
|
|
26933
|
-
severity: b.maxSeverity,
|
|
26934
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26935
|
-
id: ""
|
|
26936
|
-
}
|
|
26937
|
-
);
|
|
26938
|
-
}
|
|
26939
26969
|
var CONCAT_SEP = ",";
|
|
26940
26970
|
var TUPLE_SEP = "|";
|
|
26941
26971
|
function splitConcat(value) {
|
|
@@ -26987,13 +27017,48 @@ function decodeGroupCursor(cursor) {
|
|
|
26987
27017
|
return null;
|
|
26988
27018
|
}
|
|
26989
27019
|
function firstAfter(sorted, cursor) {
|
|
26990
|
-
const index = sorted.findIndex((
|
|
27020
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26991
27021
|
return index === -1 ? sorted.length : index;
|
|
26992
27022
|
}
|
|
26993
27023
|
function findDeepLinked(sorted, page, id) {
|
|
26994
|
-
if (page.some((
|
|
26995
|
-
return sorted.find((
|
|
27024
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
27025
|
+
return sorted.find((t) => t.id === id);
|
|
27026
|
+
}
|
|
27027
|
+
function encodeLocationCursor(location) {
|
|
27028
|
+
const payload = {
|
|
27029
|
+
sev: location.maxSeverity,
|
|
27030
|
+
t: location.latestDetectedAt,
|
|
27031
|
+
r: location.repo,
|
|
27032
|
+
f: location.file
|
|
27033
|
+
};
|
|
27034
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
27035
|
+
}
|
|
27036
|
+
function decodeLocationCursor(cursor) {
|
|
27037
|
+
const parsed2 = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
27038
|
+
if (parsed2 !== void 0 && typeof parsed2.sev === "string" && typeof parsed2.t === "string" && typeof parsed2.r === "string" && typeof parsed2.f === "string") {
|
|
27039
|
+
return { maxSeverity: parsed2.sev, latestDetectedAt: parsed2.t, repo: parsed2.r, file: parsed2.f };
|
|
27040
|
+
}
|
|
27041
|
+
return null;
|
|
27042
|
+
}
|
|
27043
|
+
function firstLocationAfter(sorted, cursor) {
|
|
27044
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
27045
|
+
return index === -1 ? sorted.length : index;
|
|
26996
27046
|
}
|
|
27047
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
27048
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
27049
|
+
return sorted.find((l) => l.id === id);
|
|
27050
|
+
}
|
|
27051
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
27052
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
27053
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27054
|
+
e.started_at AS occurred_at,
|
|
27055
|
+
e.source_tool AS source_tool,
|
|
27056
|
+
e.repo AS repo,
|
|
27057
|
+
e.file_path AS file,
|
|
27058
|
+
e.tool_name AS tool_name,
|
|
27059
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27060
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27061
|
+
${latestResolutionStatusSql("f")} AS latest_status`;
|
|
26997
27062
|
var DAY_MS3 = 864e5;
|
|
26998
27063
|
var SqliteFindingsRepository = class {
|
|
26999
27064
|
constructor(db) {
|
|
@@ -27114,30 +27179,26 @@ var SqliteFindingsRepository = class {
|
|
|
27114
27179
|
);
|
|
27115
27180
|
}
|
|
27116
27181
|
/**
|
|
27117
|
-
*
|
|
27118
|
-
*
|
|
27119
|
-
*
|
|
27120
|
-
*
|
|
27121
|
-
*
|
|
27122
|
-
*
|
|
27123
|
-
*
|
|
27124
|
-
*
|
|
27125
|
-
*
|
|
27126
|
-
*
|
|
27127
|
-
*
|
|
27128
|
-
*
|
|
27182
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
27183
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
27184
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
27185
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
27186
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
27187
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
27188
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
27189
|
+
* derived status was requested.
|
|
27190
|
+
*
|
|
27191
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
27192
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
27193
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
27194
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
27195
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
27129
27196
|
*
|
|
27130
|
-
* Two reads, neither of which materializes a row per finding:
|
|
27131
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
27132
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
27133
|
-
* latest, search text);
|
|
27134
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
27135
|
-
* populate `instances` for the table's expanded rows.
|
|
27136
27197
|
* The aggregates carry raw DB values and are translated by the same
|
|
27137
|
-
* @akasecurity/schema mappers
|
|
27138
|
-
* rule is ever restated in SQL.
|
|
27198
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
27199
|
+
* status rule is ever restated in SQL.
|
|
27139
27200
|
*/
|
|
27140
|
-
|
|
27201
|
+
listFindingTypes(query) {
|
|
27141
27202
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
27142
27203
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
27143
27204
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -27150,12 +27211,7 @@ var SqliteFindingsRepository = class {
|
|
|
27150
27211
|
predicate,
|
|
27151
27212
|
params: sessionParams
|
|
27152
27213
|
});
|
|
27153
|
-
const
|
|
27154
|
-
sessionId: query.sessionId,
|
|
27155
|
-
from: query.from
|
|
27156
|
-
});
|
|
27157
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27158
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
27214
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27159
27215
|
const filterOpts = {
|
|
27160
27216
|
severity: query.severity,
|
|
27161
27217
|
providers: query.provider,
|
|
@@ -27164,30 +27220,25 @@ var SqliteFindingsRepository = class {
|
|
|
27164
27220
|
subtype: query.subtype,
|
|
27165
27221
|
q: query.q
|
|
27166
27222
|
};
|
|
27167
|
-
const facets = computeFindingFacets(
|
|
27168
|
-
const sorted =
|
|
27223
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
27224
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27169
27225
|
const statusFilter = query.status ?? [];
|
|
27170
27226
|
const totals = {
|
|
27171
|
-
findings: sorted.reduce((acc,
|
|
27172
|
-
if (statusFilter.length === 0) return acc +
|
|
27173
|
-
const agg = aggregates.get(
|
|
27174
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
27227
|
+
findings: sorted.reduce((acc, t) => {
|
|
27228
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
27229
|
+
const agg = aggregates.get(t.id);
|
|
27230
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27175
27231
|
}, 0),
|
|
27176
|
-
|
|
27232
|
+
types: sorted.length
|
|
27177
27233
|
};
|
|
27178
|
-
const limit = query.limit ??
|
|
27234
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27179
27235
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27180
27236
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27181
27237
|
const page = sorted.slice(start, start + limit);
|
|
27182
27238
|
const lastOnPage = page.at(-1);
|
|
27183
27239
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27184
27240
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27185
|
-
const
|
|
27186
|
-
const narrow = (g) => statusSet ? {
|
|
27187
|
-
...g,
|
|
27188
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27189
|
-
} : g;
|
|
27190
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
27241
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27191
27242
|
return Promise.resolve({
|
|
27192
27243
|
totals,
|
|
27193
27244
|
facets,
|
|
@@ -27198,7 +27249,7 @@ var SqliteFindingsRepository = class {
|
|
|
27198
27249
|
}
|
|
27199
27250
|
/**
|
|
27200
27251
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27201
|
-
*
|
|
27252
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27202
27253
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27203
27254
|
*
|
|
27204
27255
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27292,13 +27343,25 @@ var SqliteFindingsRepository = class {
|
|
|
27292
27343
|
});
|
|
27293
27344
|
}
|
|
27294
27345
|
/**
|
|
27295
|
-
* The same findings folded by
|
|
27346
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27296
27347
|
*
|
|
27297
27348
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27298
|
-
* the local store relates a finding to
|
|
27299
|
-
*
|
|
27300
|
-
* empty-string bucket, which
|
|
27301
|
-
*
|
|
27349
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
27350
|
+
* by instead. A repo or file the event did not record folds into the
|
|
27351
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
27352
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
27353
|
+
*
|
|
27354
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
27355
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
27356
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
27357
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
27358
|
+
* place.
|
|
27359
|
+
*
|
|
27360
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
27361
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
27362
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
27363
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
27364
|
+
* its fields.
|
|
27302
27365
|
*/
|
|
27303
27366
|
listFindingLocations(query) {
|
|
27304
27367
|
const opts = {
|
|
@@ -27310,13 +27373,16 @@ var SqliteFindingsRepository = class {
|
|
|
27310
27373
|
tools: query.tool,
|
|
27311
27374
|
q: query.q
|
|
27312
27375
|
};
|
|
27313
|
-
const limit = query.limit ??
|
|
27376
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
27377
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27314
27378
|
const byRepo = /* @__PURE__ */ new Map();
|
|
27379
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27315
27380
|
let total = 0;
|
|
27316
27381
|
for (const row of this.scanFindingRows({
|
|
27317
27382
|
sessionId: query.sessionId,
|
|
27318
27383
|
from: query.from
|
|
27319
27384
|
})) {
|
|
27385
|
+
accumulator.add(row);
|
|
27320
27386
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27321
27387
|
total += 1;
|
|
27322
27388
|
let files = byRepo.get(row.repo);
|
|
@@ -27331,103 +27397,35 @@ var SqliteFindingsRepository = class {
|
|
|
27331
27397
|
}
|
|
27332
27398
|
addToLocation(acc, row);
|
|
27333
27399
|
}
|
|
27334
|
-
|
|
27335
|
-
const
|
|
27336
|
-
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
|
|
27345
|
-
|
|
27346
|
-
|
|
27347
|
-
|
|
27348
|
-
|
|
27349
|
-
|
|
27350
|
-
|
|
27351
|
-
|
|
27352
|
-
|
|
27353
|
-
|
|
27354
|
-
|
|
27355
|
-
|
|
27356
|
-
);
|
|
27357
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27358
|
-
const folded = foldGroupStatus(statuses);
|
|
27359
|
-
return {
|
|
27360
|
-
repo,
|
|
27361
|
-
instanceCount: rollup.instanceCount,
|
|
27362
|
-
maxSeverity: rollup.maxSeverity,
|
|
27363
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27364
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27365
|
-
files: fileRows
|
|
27366
|
-
};
|
|
27367
|
-
});
|
|
27368
|
-
repos.sort(compareLocationOrder);
|
|
27400
|
+
const sorted = [];
|
|
27401
|
+
for (const [repo, files] of byRepo) {
|
|
27402
|
+
for (const [file2, acc] of files) {
|
|
27403
|
+
const status = foldGroupStatus(acc.statuses);
|
|
27404
|
+
sorted.push({
|
|
27405
|
+
id: encodeLocationId(repo, file2),
|
|
27406
|
+
repo,
|
|
27407
|
+
file: file2,
|
|
27408
|
+
instanceCount: acc.instanceCount,
|
|
27409
|
+
maxSeverity: acc.maxSeverity,
|
|
27410
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
27411
|
+
...status === void 0 ? {} : { status },
|
|
27412
|
+
ruleIds: [...acc.ruleIds]
|
|
27413
|
+
});
|
|
27414
|
+
}
|
|
27415
|
+
}
|
|
27416
|
+
sorted.sort(compareLocationOrder);
|
|
27417
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
27418
|
+
const page = sorted.slice(start, start + limit);
|
|
27419
|
+
const lastOnPage = page.at(-1);
|
|
27420
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
27421
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27369
27422
|
return Promise.resolve({
|
|
27370
|
-
totals: { findings: total,
|
|
27371
|
-
|
|
27372
|
-
|
|
27423
|
+
totals: { findings: total, locations: sorted.length },
|
|
27424
|
+
facets: accumulator.facets(),
|
|
27425
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
27426
|
+
nextCursor
|
|
27373
27427
|
});
|
|
27374
27428
|
}
|
|
27375
|
-
/**
|
|
27376
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27377
|
-
*
|
|
27378
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27379
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27380
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27381
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27382
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27383
|
-
* store while the answer does not.
|
|
27384
|
-
*
|
|
27385
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27386
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27387
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27388
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27389
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27390
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27391
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27392
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27393
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27394
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27395
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27396
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27397
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27398
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27399
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27400
|
-
* sort of the scope, which is still that floor.
|
|
27401
|
-
*
|
|
27402
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27403
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27404
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27405
|
-
* built from.
|
|
27406
|
-
*/
|
|
27407
|
-
previewRows(aggregates, scope) {
|
|
27408
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27409
|
-
let remaining = 0;
|
|
27410
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27411
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27412
|
-
wanted.set(ruleId, n);
|
|
27413
|
-
remaining += n;
|
|
27414
|
-
}
|
|
27415
|
-
const rows = [];
|
|
27416
|
-
if (remaining === 0) return rows;
|
|
27417
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27418
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27419
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27420
|
-
const want = wanted.get(r.rule_id);
|
|
27421
|
-
if (want === void 0) continue;
|
|
27422
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27423
|
-
if (have >= want) continue;
|
|
27424
|
-
taken.set(r.rule_id, have + 1);
|
|
27425
|
-
rows.push(r);
|
|
27426
|
-
remaining -= 1;
|
|
27427
|
-
if (remaining === 0) break;
|
|
27428
|
-
}
|
|
27429
|
-
return rows;
|
|
27430
|
-
}
|
|
27431
27429
|
/**
|
|
27432
27430
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27433
27431
|
*
|
|
@@ -27454,6 +27452,33 @@ var SqliteFindingsRepository = class {
|
|
|
27454
27452
|
yield toFlatFindingRow(r);
|
|
27455
27453
|
}
|
|
27456
27454
|
}
|
|
27455
|
+
/**
|
|
27456
|
+
* One finding by its own id, or null when no such row exists.
|
|
27457
|
+
*
|
|
27458
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
27459
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
27460
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
27461
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
27462
|
+
* older than anything a first page holds.
|
|
27463
|
+
*
|
|
27464
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
27465
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
27466
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
27467
|
+
* worse than showing it.
|
|
27468
|
+
*
|
|
27469
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
27470
|
+
* type should the list select?" and "what does the drawer show?".
|
|
27471
|
+
*/
|
|
27472
|
+
findingInstance(id) {
|
|
27473
|
+
const row = this.db.prepare(
|
|
27474
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27475
|
+
FROM inspection_findings f
|
|
27476
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
27477
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27478
|
+
WHERE f.id = ?`
|
|
27479
|
+
).get(id);
|
|
27480
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
27481
|
+
}
|
|
27457
27482
|
/**
|
|
27458
27483
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27459
27484
|
* joined to its event and definition, newest first.
|
|
@@ -27487,17 +27512,7 @@ var SqliteFindingsRepository = class {
|
|
|
27487
27512
|
conditions.push("e.started_at >= ?");
|
|
27488
27513
|
params.push(isoToEpochMillis(scope.from));
|
|
27489
27514
|
}
|
|
27490
|
-
const sql = `SELECT
|
|
27491
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27492
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27493
|
-
e.started_at AS occurred_at,
|
|
27494
|
-
e.source_tool AS source_tool,
|
|
27495
|
-
e.repo AS repo,
|
|
27496
|
-
e.file_path AS file,
|
|
27497
|
-
e.tool_name AS tool_name,
|
|
27498
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27499
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27500
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
27515
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27501
27516
|
FROM audit_events e
|
|
27502
27517
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27503
27518
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27511,6 +27526,26 @@ var SqliteFindingsRepository = class {
|
|
|
27511
27526
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27512
27527
|
const rows = this.db.prepare(
|
|
27513
27528
|
`SELECT rule_id,
|
|
27529
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
27530
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
27531
|
+
-- in an aggregate query, every bare column takes its value from
|
|
27532
|
+
-- the row that produced the extremum. So these are the severity
|
|
27533
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
27534
|
+
-- is what the row-based build they replaced read off its first
|
|
27535
|
+
-- (newest-first) row.
|
|
27536
|
+
--
|
|
27537
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
27538
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
27539
|
+
-- mints a new row), so a rule whose severity moved between
|
|
27540
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
27541
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
27542
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
27543
|
+
-- filter, the facet counts and the primary sort key.
|
|
27544
|
+
--
|
|
27545
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
27546
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
27547
|
+
severity,
|
|
27548
|
+
category,
|
|
27514
27549
|
sum(tuple_count) AS instance_count,
|
|
27515
27550
|
max(latest_at) AS latest_at,
|
|
27516
27551
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27521,6 +27556,14 @@ var SqliteFindingsRepository = class {
|
|
|
27521
27556
|
group_concat(tool_names) AS tool_names
|
|
27522
27557
|
FROM (
|
|
27523
27558
|
SELECT d.rule_id AS rule_id,
|
|
27559
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
27560
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
27561
|
+
-- these are grouped on below and resolved to the newest
|
|
27562
|
+
-- firing version by the outer query's bare-column select.
|
|
27563
|
+
-- They ride the aggregate because the type build has no rows
|
|
27564
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
27565
|
+
d.severity AS severity,
|
|
27566
|
+
d.category AS category,
|
|
27524
27567
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27525
27568
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27526
27569
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27535,7 +27578,7 @@ var SqliteFindingsRepository = class {
|
|
|
27535
27578
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27536
27579
|
ON latest.finding_key = f.finding_key
|
|
27537
27580
|
${scope.predicate}
|
|
27538
|
-
GROUP BY d.rule_id, status_tuple
|
|
27581
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27539
27582
|
)
|
|
27540
27583
|
GROUP BY rule_id`
|
|
27541
27584
|
).all(scope.params);
|
|
@@ -27544,6 +27587,8 @@ var SqliteFindingsRepository = class {
|
|
|
27544
27587
|
r.rule_id,
|
|
27545
27588
|
{
|
|
27546
27589
|
instanceCount: r.instance_count,
|
|
27590
|
+
severity: r.severity,
|
|
27591
|
+
category: r.category,
|
|
27547
27592
|
sourceTools: splitConcat(r.source_tools),
|
|
27548
27593
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27549
27594
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27560,7 +27605,7 @@ var SqliteFindingsRepository = class {
|
|
|
27560
27605
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27561
27606
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27562
27607
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27563
|
-
// Left undefined (not '') when unfetched, so
|
|
27608
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27564
27609
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27565
27610
|
// and skip priming a haystack nothing will read.
|
|
27566
27611
|
...withSearchText ? {
|
|
@@ -27712,6 +27757,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
27712
27757
|
this.markOwedStmt = db.prepare(
|
|
27713
27758
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27714
27759
|
);
|
|
27760
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27761
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
27762
|
+
WHERE synced_at IS NULL
|
|
27763
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27764
|
+
AND started_at < :before`
|
|
27765
|
+
);
|
|
27715
27766
|
this.stampStmt = db.prepare(
|
|
27716
27767
|
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27717
27768
|
);
|
|
@@ -27760,7 +27811,9 @@ var SqliteHistorySyncRepository = class {
|
|
|
27760
27811
|
);
|
|
27761
27812
|
this.disownCapturesStmt = db.prepare(
|
|
27762
27813
|
`UPDATE audit_events SET outbox_owed = NULL
|
|
27763
|
-
WHERE outbox_owed IS NOT NULL
|
|
27814
|
+
WHERE outbox_owed IS NOT NULL
|
|
27815
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27816
|
+
AND started_at < :attachedAt`
|
|
27764
27817
|
);
|
|
27765
27818
|
this.rearmStmt = db.prepare(
|
|
27766
27819
|
`UPDATE audit_events SET synced_at = NULL
|
|
@@ -27836,6 +27889,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27836
27889
|
freezeBoundaryStmt;
|
|
27837
27890
|
captureRowsStmt;
|
|
27838
27891
|
markOwedStmt;
|
|
27892
|
+
markCaptureBacklogOwedStmt;
|
|
27839
27893
|
captureSkipCountStmt;
|
|
27840
27894
|
disownCapturesStmt;
|
|
27841
27895
|
partitionStmt;
|
|
@@ -27899,6 +27953,23 @@ var SqliteHistorySyncRepository = class {
|
|
|
27899
27953
|
markCaptureOwed(id) {
|
|
27900
27954
|
this.markOwedStmt.run({ id });
|
|
27901
27955
|
}
|
|
27956
|
+
/**
|
|
27957
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
27958
|
+
*
|
|
27959
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
27960
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27961
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
27962
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27963
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27964
|
+
* later re-attach or key rotation might widen it to.
|
|
27965
|
+
*
|
|
27966
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27967
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27968
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27969
|
+
*/
|
|
27970
|
+
markCaptureBacklogOwed(before) {
|
|
27971
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27972
|
+
}
|
|
27902
27973
|
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27903
27974
|
markSynced(ids, atMs) {
|
|
27904
27975
|
this.stampAll(ids, atMs);
|
|
@@ -28015,15 +28086,42 @@ var SqliteHistorySyncRepository = class {
|
|
|
28015
28086
|
*
|
|
28016
28087
|
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
28017
28088
|
* machine has just left are undelivered as far as the new one is concerned.
|
|
28018
|
-
* All
|
|
28019
|
-
* attributed to the wrong deployment,
|
|
28089
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
28090
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
28091
|
+
* a disown with no re-mark to follow it.
|
|
28020
28092
|
*
|
|
28021
28093
|
* The boundary is written HERE and only here, which is what freezes it: a
|
|
28022
28094
|
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
28023
28095
|
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
28024
28096
|
* the live path has since delivered.
|
|
28097
|
+
*
|
|
28098
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
28099
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
28100
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
28101
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
28102
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
28103
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
28104
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
28105
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
28106
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
28107
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
28108
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
28109
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
28110
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
28111
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
28112
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
28113
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
28114
|
+
*
|
|
28115
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
28116
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
28117
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
28118
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
28119
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
28120
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
28121
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
28122
|
+
* transaction above.
|
|
28025
28123
|
*/
|
|
28026
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
28124
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
28027
28125
|
this.ensureRowStmt.run();
|
|
28028
28126
|
withTransaction(
|
|
28029
28127
|
this.db,
|
|
@@ -28031,7 +28129,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
28031
28129
|
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
28032
28130
|
this.rearmStmt.run();
|
|
28033
28131
|
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
28034
|
-
this.disownCapturesStmt.run();
|
|
28132
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
28133
|
+
}
|
|
28134
|
+
if (backfillCapturesBefore !== void 0) {
|
|
28135
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
28035
28136
|
}
|
|
28036
28137
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
28037
28138
|
},
|
|
@@ -28308,7 +28409,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28308
28409
|
}
|
|
28309
28410
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28310
28411
|
}
|
|
28311
|
-
|
|
28412
|
+
var testOnlyManagedPaths = null;
|
|
28413
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28312
28414
|
for (const path of paths) {
|
|
28313
28415
|
let text;
|
|
28314
28416
|
try {
|
|
@@ -30788,7 +30890,7 @@ function toUtcDateString(ms) {
|
|
|
30788
30890
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30789
30891
|
}
|
|
30790
30892
|
function isTimeseriesSeverity(s) {
|
|
30791
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
30893
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30792
30894
|
}
|
|
30793
30895
|
var SqliteSecurityRepository = class {
|
|
30794
30896
|
constructor(db, now = () => Date.now()) {
|
|
@@ -30917,12 +31019,16 @@ var SqliteSecurityRepository = class {
|
|
|
30917
31019
|
const now = this.now();
|
|
30918
31020
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
30919
31021
|
const rows = this.findingsInRange(windowStart, now);
|
|
30920
|
-
const points = Array.from(
|
|
30921
|
-
|
|
30922
|
-
|
|
30923
|
-
|
|
30924
|
-
|
|
30925
|
-
|
|
31022
|
+
const points = Array.from(
|
|
31023
|
+
{ length: numBuckets },
|
|
31024
|
+
(_, i) => ({
|
|
31025
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
31026
|
+
critical: 0,
|
|
31027
|
+
high: 0,
|
|
31028
|
+
medium: 0,
|
|
31029
|
+
low: 0
|
|
31030
|
+
})
|
|
31031
|
+
);
|
|
30926
31032
|
for (const r of rows) {
|
|
30927
31033
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
30928
31034
|
const bucket = points[idx];
|
|
@@ -31140,6 +31246,7 @@ var SqliteSecurityRepository = class {
|
|
|
31140
31246
|
`SELECT f.finding_key AS finding_key,
|
|
31141
31247
|
d.rule_id AS rule_id,
|
|
31142
31248
|
d.severity AS severity,
|
|
31249
|
+
e.repo AS repo,
|
|
31143
31250
|
e.file_path AS path,
|
|
31144
31251
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31145
31252
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31159,6 +31266,7 @@ var SqliteSecurityRepository = class {
|
|
|
31159
31266
|
const items = rows.map((r) => ({
|
|
31160
31267
|
findingKey: r.finding_key,
|
|
31161
31268
|
ruleId: r.rule_id,
|
|
31269
|
+
repo: r.repo ?? "",
|
|
31162
31270
|
severity: r.severity,
|
|
31163
31271
|
path: r.path ?? "",
|
|
31164
31272
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31168,13 +31276,66 @@ var SqliteSecurityRepository = class {
|
|
|
31168
31276
|
}));
|
|
31169
31277
|
return Promise.resolve({ items });
|
|
31170
31278
|
}
|
|
31279
|
+
/**
|
|
31280
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31281
|
+
*
|
|
31282
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31283
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31284
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31285
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31286
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31287
|
+
*
|
|
31288
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31289
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31290
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31291
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31292
|
+
* The two answer different questions and only this one has to match a link.
|
|
31293
|
+
*
|
|
31294
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31295
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31296
|
+
*/
|
|
31297
|
+
recommendationInputs() {
|
|
31298
|
+
const rows = allRows(
|
|
31299
|
+
this.db.prepare(
|
|
31300
|
+
`SELECT d.rule_id AS rule_id,
|
|
31301
|
+
d.category AS category,
|
|
31302
|
+
d.severity AS severity,
|
|
31303
|
+
COUNT(*) AS count
|
|
31304
|
+
FROM inspection_findings f
|
|
31305
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31306
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31307
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31308
|
+
ON latest.finding_key = f.finding_key
|
|
31309
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31310
|
+
AND e.event_type = 'code_change'
|
|
31311
|
+
AND (
|
|
31312
|
+
f.finding_key IS NULL
|
|
31313
|
+
OR latest.status IS NULL
|
|
31314
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31315
|
+
)
|
|
31316
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31317
|
+
)
|
|
31318
|
+
);
|
|
31319
|
+
return Promise.resolve(
|
|
31320
|
+
rows.map((r) => ({
|
|
31321
|
+
ruleId: r.rule_id,
|
|
31322
|
+
category: r.category,
|
|
31323
|
+
severity: r.severity,
|
|
31324
|
+
count: r.count
|
|
31325
|
+
}))
|
|
31326
|
+
);
|
|
31327
|
+
}
|
|
31171
31328
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31172
31329
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31173
31330
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31174
31331
|
findingsInRange(fromMs, toMs) {
|
|
31175
31332
|
const rows = allRows(
|
|
31176
31333
|
this.db.prepare(
|
|
31177
|
-
`
|
|
31334
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31335
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31336
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31337
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31338
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31178
31339
|
FROM inspection_findings f
|
|
31179
31340
|
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31180
31341
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -31187,7 +31348,9 @@ var SqliteSecurityRepository = class {
|
|
|
31187
31348
|
return rows.map((r) => ({
|
|
31188
31349
|
occurredAt: r.occurred_at,
|
|
31189
31350
|
severity: r.severity,
|
|
31190
|
-
actionTaken: r.action_taken
|
|
31351
|
+
actionTaken: r.action_taken,
|
|
31352
|
+
ruleId: r.rule_id,
|
|
31353
|
+
category: r.category
|
|
31191
31354
|
}));
|
|
31192
31355
|
}
|
|
31193
31356
|
};
|
|
@@ -32357,14 +32520,51 @@ function openLocalDatabase(dir) {
|
|
|
32357
32520
|
};
|
|
32358
32521
|
}
|
|
32359
32522
|
|
|
32360
|
-
// ../../packages/persistence/src/
|
|
32523
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32361
32524
|
import { createHash as createHash3 } from "crypto";
|
|
32525
|
+
function hashProjectKey(projectKey) {
|
|
32526
|
+
return createHash3("sha256").update(projectKey, "utf8").digest("hex");
|
|
32527
|
+
}
|
|
32528
|
+
function toIngestHit(hit) {
|
|
32529
|
+
return {
|
|
32530
|
+
host: hit.host,
|
|
32531
|
+
kind: hit.kind,
|
|
32532
|
+
name: hit.name,
|
|
32533
|
+
category: hit.category,
|
|
32534
|
+
trust: hit.trust,
|
|
32535
|
+
network: hit.network,
|
|
32536
|
+
method: hit.method,
|
|
32537
|
+
transport: hit.transport,
|
|
32538
|
+
url: hit.url,
|
|
32539
|
+
template: hit.template,
|
|
32540
|
+
dataClass: hit.dataClass,
|
|
32541
|
+
site: {
|
|
32542
|
+
file: hit.site.file,
|
|
32543
|
+
line: hit.site.line,
|
|
32544
|
+
dynamic: hit.site.dynamic,
|
|
32545
|
+
vendored: hit.site.vendored
|
|
32546
|
+
}
|
|
32547
|
+
};
|
|
32548
|
+
}
|
|
32549
|
+
function toEgressIngestRequest(input2) {
|
|
32550
|
+
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
32551
|
+
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
32552
|
+
return {
|
|
32553
|
+
projectKey: hashProjectKey(input2.projectKey),
|
|
32554
|
+
project: input2.project,
|
|
32555
|
+
reconcile,
|
|
32556
|
+
hits: hits.map(toIngestHit)
|
|
32557
|
+
};
|
|
32558
|
+
}
|
|
32559
|
+
|
|
32560
|
+
// ../../packages/persistence/src/finding-key.ts
|
|
32561
|
+
import { createHash as createHash4 } from "crypto";
|
|
32362
32562
|
function normalizeFilePath(filePath) {
|
|
32363
32563
|
return filePath.replaceAll("\\", "/");
|
|
32364
32564
|
}
|
|
32365
32565
|
function computeFindingKey(input2) {
|
|
32366
32566
|
const normalizedPath = normalizeFilePath(input2.filePath);
|
|
32367
|
-
return
|
|
32567
|
+
return createHash4("sha256").update(`${input2.ruleId}\0${normalizedPath}\0${input2.valueFingerprint}`).digest("hex");
|
|
32368
32568
|
}
|
|
32369
32569
|
|
|
32370
32570
|
// ../../packages/persistence/src/fingerprint.ts
|
|
@@ -32490,14 +32690,18 @@ function fingerprintValue(key, raw) {
|
|
|
32490
32690
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
32491
32691
|
}
|
|
32492
32692
|
|
|
32493
|
-
// ../../packages/persistence/src/history-
|
|
32693
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
32494
32694
|
import { existsSync as existsSync4 } from "fs";
|
|
32495
32695
|
import { join as join9 } from "path";
|
|
32696
|
+
|
|
32697
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
32698
|
+
import { existsSync as existsSync5 } from "fs";
|
|
32699
|
+
import { join as join10 } from "path";
|
|
32496
32700
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32497
32701
|
|
|
32498
32702
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32499
|
-
import { existsSync as
|
|
32500
|
-
import { dirname as dirname3, join as
|
|
32703
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32704
|
+
import { dirname as dirname3, join as join11, resolve } from "path";
|
|
32501
32705
|
|
|
32502
32706
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32503
32707
|
import {
|
|
@@ -32512,19 +32716,19 @@ import {
|
|
|
32512
32716
|
import { execFileSync } from "child_process";
|
|
32513
32717
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32514
32718
|
import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
32515
|
-
import { join as
|
|
32719
|
+
import { join as join12 } from "path";
|
|
32516
32720
|
|
|
32517
32721
|
// ../../packages/persistence/src/vault/vault.ts
|
|
32518
32722
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
32519
32723
|
|
|
32520
32724
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
32521
|
-
import { existsSync as
|
|
32522
|
-
import { join as
|
|
32725
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
32726
|
+
import { join as join13 } from "path";
|
|
32523
32727
|
var MARKER = "warn-era-capped";
|
|
32524
32728
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
32525
32729
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
32526
|
-
const marker =
|
|
32527
|
-
if (
|
|
32730
|
+
const marker = join13(dataDir2, MARKER);
|
|
32731
|
+
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
32528
32732
|
const capped = db.policies.capCategoryActions();
|
|
32529
32733
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
32530
32734
|
`, { mode: DATA_FILE_MODE });
|
|
@@ -32583,8 +32787,8 @@ function resolveProvider() {
|
|
|
32583
32787
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
32584
32788
|
try {
|
|
32585
32789
|
ensureLayoutDirSync(base);
|
|
32586
|
-
const settingsFile =
|
|
32587
|
-
if (
|
|
32790
|
+
const settingsFile = join14(settingsDir(base), "settings.json");
|
|
32791
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
32588
32792
|
} catch {
|
|
32589
32793
|
}
|
|
32590
32794
|
migrateLegacyLayout(base);
|
|
@@ -32609,7 +32813,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
32609
32813
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
32610
32814
|
import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
32611
32815
|
import { homedir as homedir2 } from "os";
|
|
32612
|
-
import { basename as basename3, join as
|
|
32816
|
+
import { basename as basename3, join as join16 } from "path";
|
|
32613
32817
|
|
|
32614
32818
|
// ../../packages/detections/src/egress/registry.ts
|
|
32615
32819
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -35740,8 +35944,8 @@ function scanText(text, ruleVersions) {
|
|
|
35740
35944
|
}
|
|
35741
35945
|
|
|
35742
35946
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
35743
|
-
import { existsSync as
|
|
35744
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
35947
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
|
|
35948
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join15, sep as sep2 } from "path";
|
|
35745
35949
|
function resolveRepoIdentity(cwd) {
|
|
35746
35950
|
try {
|
|
35747
35951
|
const root = findGitRoot(cwd);
|
|
@@ -35763,32 +35967,32 @@ function resolveRepoIdentity(cwd) {
|
|
|
35763
35967
|
function findGitRoot(start) {
|
|
35764
35968
|
let dir = start;
|
|
35765
35969
|
for (; ; ) {
|
|
35766
|
-
if (
|
|
35970
|
+
if (existsSync9(join15(dir, ".git"))) return dir;
|
|
35767
35971
|
const parent = dirname4(dir);
|
|
35768
35972
|
if (parent === dir) return void 0;
|
|
35769
35973
|
dir = parent;
|
|
35770
35974
|
}
|
|
35771
35975
|
}
|
|
35772
35976
|
function resolveGitContext(root) {
|
|
35773
|
-
const dotGit =
|
|
35977
|
+
const dotGit = join15(root, ".git");
|
|
35774
35978
|
try {
|
|
35775
35979
|
if (statSync6(dotGit).isDirectory()) {
|
|
35776
|
-
return { configPath:
|
|
35980
|
+
return { configPath: join15(dotGit, "config"), headRoot: root };
|
|
35777
35981
|
}
|
|
35778
35982
|
} catch {
|
|
35779
35983
|
return void 0;
|
|
35780
35984
|
}
|
|
35781
35985
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
35782
35986
|
if (!target) return void 0;
|
|
35783
|
-
const gitdir = isAbsolute(target) ? target :
|
|
35784
|
-
if (
|
|
35785
|
-
return { configPath:
|
|
35987
|
+
const gitdir = isAbsolute(target) ? target : join15(root, target);
|
|
35988
|
+
if (existsSync9(join15(gitdir, "config"))) {
|
|
35989
|
+
return { configPath: join15(gitdir, "config"), headRoot: root };
|
|
35786
35990
|
}
|
|
35787
|
-
const commonRaw = safeRead(
|
|
35991
|
+
const commonRaw = safeRead(join15(gitdir, "commondir"))?.trim();
|
|
35788
35992
|
if (!commonRaw) return void 0;
|
|
35789
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
35993
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join15(gitdir, commonRaw);
|
|
35790
35994
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
35791
|
-
return { configPath:
|
|
35995
|
+
return { configPath: join15(commonGitDir, "config"), headRoot };
|
|
35792
35996
|
}
|
|
35793
35997
|
function safeRead(path) {
|
|
35794
35998
|
try {
|
|
@@ -35830,9 +36034,9 @@ function slugFromUrl(url2) {
|
|
|
35830
36034
|
}
|
|
35831
36035
|
|
|
35832
36036
|
// ../../packages/plugin-sdk/src/events.ts
|
|
35833
|
-
import { createHash as
|
|
36037
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
35834
36038
|
function contentHashOf(text) {
|
|
35835
|
-
return
|
|
36039
|
+
return createHash5("sha256").update(text).digest("hex");
|
|
35836
36040
|
}
|
|
35837
36041
|
function buildIngestEvent(input2) {
|
|
35838
36042
|
const contentHash = input2.contentHash ?? contentHashOf(input2.content);
|
|
@@ -35858,7 +36062,7 @@ function buildIngestEvent(input2) {
|
|
|
35858
36062
|
}
|
|
35859
36063
|
|
|
35860
36064
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
35861
|
-
import { existsSync as
|
|
36065
|
+
import { existsSync as existsSync10 } from "fs";
|
|
35862
36066
|
import { fileURLToPath } from "url";
|
|
35863
36067
|
import { Worker } from "worker_threads";
|
|
35864
36068
|
var ISOLATED_SCAN_BUDGET_MS = 2e3;
|
|
@@ -35872,7 +36076,7 @@ function resolveWorkerUrl() {
|
|
|
35872
36076
|
for (const name of ["scan-worker.js", "scan-worker.ts"]) {
|
|
35873
36077
|
const candidate = new URL(name, import.meta.url);
|
|
35874
36078
|
try {
|
|
35875
|
-
if (
|
|
36079
|
+
if (existsSync10(fileURLToPath(candidate))) {
|
|
35876
36080
|
resolvedWorkerUrl = candidate;
|
|
35877
36081
|
return candidate;
|
|
35878
36082
|
}
|
|
@@ -36335,10 +36539,45 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
36335
36539
|
};
|
|
36336
36540
|
}
|
|
36337
36541
|
|
|
36542
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
36543
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
36544
|
+
import { join as join18 } from "path";
|
|
36545
|
+
|
|
36546
|
+
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
36547
|
+
import {
|
|
36548
|
+
closeSync as closeSync2,
|
|
36549
|
+
fstatSync,
|
|
36550
|
+
mkdirSync as mkdirSync2,
|
|
36551
|
+
openSync as openSync2,
|
|
36552
|
+
readFileSync as readFileSync10,
|
|
36553
|
+
readSync,
|
|
36554
|
+
writeFileSync as writeFileSync5
|
|
36555
|
+
} from "fs";
|
|
36556
|
+
import { join as join17 } from "path";
|
|
36557
|
+
var TAIL_BYTES = 256 * 1024;
|
|
36558
|
+
|
|
36559
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
36560
|
+
var HOST_FEATURE = {
|
|
36561
|
+
ModelSwitch: "model-switch",
|
|
36562
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
36563
|
+
};
|
|
36564
|
+
var HOST_FLOORS = {
|
|
36565
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
36566
|
+
label: "model-switch protection",
|
|
36567
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
36568
|
+
since: "2.1.251"
|
|
36569
|
+
},
|
|
36570
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
36571
|
+
label: "vault pointer display",
|
|
36572
|
+
hookEvents: ["MessageDisplay"],
|
|
36573
|
+
since: "2.1.152"
|
|
36574
|
+
}
|
|
36575
|
+
};
|
|
36576
|
+
|
|
36338
36577
|
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
36339
36578
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
36340
|
-
import { readFileSync as
|
|
36341
|
-
import { join as
|
|
36579
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
36580
|
+
import { join as join19 } from "path";
|
|
36342
36581
|
|
|
36343
36582
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
36344
36583
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
@@ -36369,22 +36608,9 @@ function resolveInventoryContext(input2) {
|
|
|
36369
36608
|
return ctx;
|
|
36370
36609
|
}
|
|
36371
36610
|
|
|
36372
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
36373
|
-
import {
|
|
36374
|
-
closeSync as closeSync2,
|
|
36375
|
-
fstatSync,
|
|
36376
|
-
mkdirSync as mkdirSync2,
|
|
36377
|
-
openSync as openSync2,
|
|
36378
|
-
readFileSync as readFileSync11,
|
|
36379
|
-
readSync,
|
|
36380
|
-
writeFileSync as writeFileSync5
|
|
36381
|
-
} from "fs";
|
|
36382
|
-
import { join as join17 } from "path";
|
|
36383
|
-
var TAIL_BYTES = 256 * 1024;
|
|
36384
|
-
|
|
36385
36611
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
36386
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
36387
|
-
import { join as
|
|
36612
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
36613
|
+
import { join as join20 } from "path";
|
|
36388
36614
|
|
|
36389
36615
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
36390
36616
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
@@ -36426,8 +36652,8 @@ function createPolicyResolver(bundle) {
|
|
|
36426
36652
|
}
|
|
36427
36653
|
|
|
36428
36654
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
36429
|
-
import { existsSync as
|
|
36430
|
-
import { basename as basename5, join as
|
|
36655
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
36656
|
+
import { basename as basename5, join as join21 } from "path";
|
|
36431
36657
|
|
|
36432
36658
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
36433
36659
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -36508,6 +36734,14 @@ function safeMaskedMatch(rawMatch) {
|
|
|
36508
36734
|
// ../../packages/plugin-sdk/src/runtime.ts
|
|
36509
36735
|
import { randomUUID as randomUUID14 } from "crypto";
|
|
36510
36736
|
var ENFORCEMENT_CEILING_ENABLED = false;
|
|
36737
|
+
function applyEnforcementCeiling(action, policyMode, enabled) {
|
|
36738
|
+
if (!enabled || policyMode !== "warn") return action;
|
|
36739
|
+
return action === "block" || action === "redact" ? "warn" : action;
|
|
36740
|
+
}
|
|
36741
|
+
function resolveEnforcedAction(action, opts) {
|
|
36742
|
+
const degraded = !opts.rewritable && action === "redact" ? builtinPolicyToAction(opts.redactFallback) : action;
|
|
36743
|
+
return applyEnforcementCeiling(degraded, opts.policyMode, opts.ceilingEnabled);
|
|
36744
|
+
}
|
|
36511
36745
|
function startTiming() {
|
|
36512
36746
|
try {
|
|
36513
36747
|
return performance.now();
|
|
@@ -36616,12 +36850,12 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
36616
36850
|
}
|
|
36617
36851
|
function actionForFinding(finding, excepted, rewritable = true) {
|
|
36618
36852
|
if (excepted?.has(finding)) return "allow";
|
|
36619
|
-
|
|
36620
|
-
|
|
36621
|
-
|
|
36622
|
-
|
|
36623
|
-
|
|
36624
|
-
|
|
36853
|
+
return resolveEnforcedAction(resolveAction(finding.ruleId, finding.category), {
|
|
36854
|
+
policyMode,
|
|
36855
|
+
redactFallback,
|
|
36856
|
+
rewritable,
|
|
36857
|
+
ceilingEnabled: ENFORCEMENT_CEILING_ENABLED
|
|
36858
|
+
});
|
|
36625
36859
|
}
|
|
36626
36860
|
function decide(findings, text, excepted, rewritable = true) {
|
|
36627
36861
|
if (findings.length === 0) return { action: "log", text, findings: [] };
|
|
@@ -36870,11 +37104,11 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
36870
37104
|
|
|
36871
37105
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
36872
37106
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
36873
|
-
import { join as
|
|
37107
|
+
import { join as join22 } from "path";
|
|
36874
37108
|
|
|
36875
37109
|
// ../../packages/setup-wizard/src/remediation/rotation-checklist.ts
|
|
36876
37110
|
import { writeFileSync as writeFileSync8 } from "fs";
|
|
36877
|
-
import { join as
|
|
37111
|
+
import { join as join23 } from "path";
|
|
36878
37112
|
|
|
36879
37113
|
// ../../packages/setup-wizard/src/triage/merge.ts
|
|
36880
37114
|
var RANK = Object.fromEntries(
|
|
@@ -36882,9 +37116,9 @@ var RANK = Object.fromEntries(
|
|
|
36882
37116
|
);
|
|
36883
37117
|
|
|
36884
37118
|
// ../../packages/setup-wizard/src/triage/plan-file.ts
|
|
36885
|
-
import { mkdtempSync, readFileSync as
|
|
37119
|
+
import { mkdtempSync, readFileSync as readFileSync14, rmdirSync, rmSync as rmSync7, writeFileSync as writeFileSync9 } from "fs";
|
|
36886
37120
|
import { tmpdir } from "os";
|
|
36887
|
-
import { basename as basename6, dirname as dirname6, join as
|
|
37121
|
+
import { basename as basename6, dirname as dirname6, join as join24 } from "path";
|
|
36888
37122
|
var SuppressionEntrySchema = external_exports.object({
|
|
36889
37123
|
ruleId: external_exports.string(),
|
|
36890
37124
|
category: DetectionCategory,
|
|
@@ -36928,43 +37162,6 @@ var PersistedPlanSchema = external_exports.object({
|
|
|
36928
37162
|
// ../../packages/setup-wizard/src/triage/writeback.ts
|
|
36929
37163
|
var TRIAGE_STATUSES = ["complete", "complete:no-history", "skipped:no-consent"];
|
|
36930
37164
|
|
|
36931
|
-
// ../../packages/plugin-runtime/src/attached/egress-wire.ts
|
|
36932
|
-
import { createHash as createHash5 } from "crypto";
|
|
36933
|
-
function hashProjectKey(projectKey) {
|
|
36934
|
-
return createHash5("sha256").update(projectKey, "utf8").digest("hex");
|
|
36935
|
-
}
|
|
36936
|
-
function toIngestHit(hit) {
|
|
36937
|
-
return {
|
|
36938
|
-
host: hit.host,
|
|
36939
|
-
kind: hit.kind,
|
|
36940
|
-
name: hit.name,
|
|
36941
|
-
category: hit.category,
|
|
36942
|
-
trust: hit.trust,
|
|
36943
|
-
network: hit.network,
|
|
36944
|
-
method: hit.method,
|
|
36945
|
-
transport: hit.transport,
|
|
36946
|
-
url: hit.url,
|
|
36947
|
-
template: hit.template,
|
|
36948
|
-
dataClass: hit.dataClass,
|
|
36949
|
-
site: {
|
|
36950
|
-
file: hit.site.file,
|
|
36951
|
-
line: hit.site.line,
|
|
36952
|
-
dynamic: hit.site.dynamic,
|
|
36953
|
-
vendored: hit.site.vendored
|
|
36954
|
-
}
|
|
36955
|
-
};
|
|
36956
|
-
}
|
|
36957
|
-
function toEgressIngestRequest(input2) {
|
|
36958
|
-
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
36959
|
-
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
36960
|
-
return {
|
|
36961
|
-
projectKey: hashProjectKey(input2.projectKey),
|
|
36962
|
-
project: input2.project,
|
|
36963
|
-
reconcile,
|
|
36964
|
-
hits: hits.map(toIngestHit)
|
|
36965
|
-
};
|
|
36966
|
-
}
|
|
36967
|
-
|
|
36968
37165
|
// ../../packages/remote/src/http.ts
|
|
36969
37166
|
import { request as httpRequest } from "http";
|
|
36970
37167
|
import { request as httpsRequest } from "https";
|
|
@@ -37244,6 +37441,7 @@ function createRemoteClient(options) {
|
|
|
37244
37441
|
url: url2(ROUTES.shares),
|
|
37245
37442
|
body: JSON.stringify(validated.data)
|
|
37246
37443
|
});
|
|
37444
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
37247
37445
|
okBody(response);
|
|
37248
37446
|
},
|
|
37249
37447
|
async pollCommand() {
|
|
@@ -37266,19 +37464,51 @@ function createRemoteClient(options) {
|
|
|
37266
37464
|
};
|
|
37267
37465
|
}
|
|
37268
37466
|
|
|
37269
|
-
// ../../packages/
|
|
37467
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
37270
37468
|
function statusOf(err) {
|
|
37271
37469
|
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
37272
37470
|
const { status } = err;
|
|
37273
37471
|
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
37274
37472
|
return status >= 100 && status <= 599 ? status : null;
|
|
37275
37473
|
}
|
|
37276
|
-
function
|
|
37277
|
-
|
|
37474
|
+
function nameOf(err) {
|
|
37475
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
37476
|
+
return typeof err.name === "string" ? err.name : null;
|
|
37477
|
+
}
|
|
37478
|
+
function classifyRemoteFailure(err) {
|
|
37479
|
+
switch (nameOf(err)) {
|
|
37480
|
+
case "RemoteRouteAbsent":
|
|
37481
|
+
return "route-absent";
|
|
37482
|
+
case "RemoteRequestInvalid":
|
|
37483
|
+
return "invalid-request";
|
|
37484
|
+
case "RemoteResponseInvalid":
|
|
37485
|
+
return "rejected";
|
|
37486
|
+
default:
|
|
37487
|
+
break;
|
|
37488
|
+
}
|
|
37489
|
+
const status = statusOf(err);
|
|
37490
|
+
if (status === null) return "unreachable";
|
|
37491
|
+
switch (status) {
|
|
37278
37492
|
case 401:
|
|
37279
37493
|
return "unauthorized";
|
|
37280
37494
|
case 403:
|
|
37281
37495
|
return "forbidden";
|
|
37496
|
+
case 429:
|
|
37497
|
+
return "unreachable";
|
|
37498
|
+
case 404:
|
|
37499
|
+
return "unreachable";
|
|
37500
|
+
default:
|
|
37501
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
37502
|
+
}
|
|
37503
|
+
}
|
|
37504
|
+
|
|
37505
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
37506
|
+
function classifyFailure(err) {
|
|
37507
|
+
switch (classifyRemoteFailure(err)) {
|
|
37508
|
+
case "unauthorized":
|
|
37509
|
+
return "unauthorized";
|
|
37510
|
+
case "forbidden":
|
|
37511
|
+
return "forbidden";
|
|
37282
37512
|
default:
|
|
37283
37513
|
return "unreachable";
|
|
37284
37514
|
}
|
|
@@ -37300,11 +37530,11 @@ function withTimeout(promise2, ms) {
|
|
|
37300
37530
|
}
|
|
37301
37531
|
|
|
37302
37532
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
37303
|
-
import { readFileSync as
|
|
37304
|
-
import { join as
|
|
37533
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
37534
|
+
import { join as join25 } from "path";
|
|
37305
37535
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
37306
37536
|
function forwardDropsPath(dataDir2) {
|
|
37307
|
-
return
|
|
37537
|
+
return join25(dataDir2, FORWARD_DROPS_FILENAME);
|
|
37308
37538
|
}
|
|
37309
37539
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
37310
37540
|
if (count <= 0) return;
|
|
@@ -37322,7 +37552,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
37322
37552
|
}
|
|
37323
37553
|
function readForwardDrops(dataDir2) {
|
|
37324
37554
|
try {
|
|
37325
|
-
const parsed2 = JSON.parse(
|
|
37555
|
+
const parsed2 = JSON.parse(readFileSync15(forwardDropsPath(dataDir2), "utf8"));
|
|
37326
37556
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
37327
37557
|
const record2 = parsed2;
|
|
37328
37558
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -37340,9 +37570,9 @@ function readForwardDrops(dataDir2) {
|
|
|
37340
37570
|
|
|
37341
37571
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
37342
37572
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
37343
|
-
import { readFileSync as
|
|
37573
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
37344
37574
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
37345
|
-
import { join as
|
|
37575
|
+
import { join as join26 } from "path";
|
|
37346
37576
|
function isInvalidRequest(err) {
|
|
37347
37577
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
37348
37578
|
}
|
|
@@ -37380,7 +37610,7 @@ function parseBreakerState(raw, nowMs) {
|
|
|
37380
37610
|
}
|
|
37381
37611
|
function createForwardPolicy(deps) {
|
|
37382
37612
|
const now = deps.now ?? (() => Date.now());
|
|
37383
|
-
const file2 =
|
|
37613
|
+
const file2 = join26(deps.dir, STATE_FILENAME);
|
|
37384
37614
|
let state = null;
|
|
37385
37615
|
let loading = null;
|
|
37386
37616
|
async function readState() {
|
|
@@ -38102,8 +38332,8 @@ function toolAuditEvent(input2) {
|
|
|
38102
38332
|
}
|
|
38103
38333
|
|
|
38104
38334
|
// ../../packages/plugin-runtime/src/attached/history-state.ts
|
|
38105
|
-
import { readFileSync as
|
|
38106
|
-
import { join as
|
|
38335
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
38336
|
+
import { join as join27 } from "path";
|
|
38107
38337
|
|
|
38108
38338
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
38109
38339
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -38120,14 +38350,14 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
38120
38350
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
38121
38351
|
|
|
38122
38352
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
38123
|
-
import { readFileSync as
|
|
38353
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
38124
38354
|
var manifestBuildCache = /* @__PURE__ */ new Map();
|
|
38125
38355
|
function readManifestBuild(manifestUrl, packageName) {
|
|
38126
38356
|
const key = manifestUrl.href;
|
|
38127
38357
|
if (!manifestBuildCache.has(key)) {
|
|
38128
38358
|
let build;
|
|
38129
38359
|
try {
|
|
38130
|
-
const manifest = JSON.parse(
|
|
38360
|
+
const manifest = JSON.parse(readFileSync18(manifestUrl, "utf8"));
|
|
38131
38361
|
build = typeof manifest.version === "string" && manifest.version.length > 0 ? { package: packageName, version: manifest.version } : void 0;
|
|
38132
38362
|
} catch {
|
|
38133
38363
|
build = void 0;
|
|
@@ -38154,7 +38384,7 @@ function createPluginBlock(build, policyStore) {
|
|
|
38154
38384
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
38155
38385
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
38156
38386
|
import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
38157
|
-
import { join as
|
|
38387
|
+
import { join as join28 } from "path";
|
|
38158
38388
|
|
|
38159
38389
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
38160
38390
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -38178,7 +38408,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
38178
38408
|
|
|
38179
38409
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
38180
38410
|
function createPolicyStore(dir = dataDir()) {
|
|
38181
|
-
const file2 =
|
|
38411
|
+
const file2 = join28(dir, "policy-cache.json");
|
|
38182
38412
|
async function read() {
|
|
38183
38413
|
try {
|
|
38184
38414
|
const raw = await readFile2(file2, "utf8");
|
|
@@ -38409,11 +38639,11 @@ function readStorePosture(dbPath2) {
|
|
|
38409
38639
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
38410
38640
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
38411
38641
|
import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
38412
|
-
import { join as
|
|
38642
|
+
import { join as join29 } from "path";
|
|
38413
38643
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
38414
38644
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
38415
|
-
const file2 =
|
|
38416
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
38645
|
+
const file2 = join29(dir, "posture-state.json");
|
|
38646
|
+
const legacyFile = legacyDir === void 0 ? null : join29(legacyDir, "posture-state.json");
|
|
38417
38647
|
async function persist(state) {
|
|
38418
38648
|
await ensureDataDir(dir);
|
|
38419
38649
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -38481,8 +38711,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
38481
38711
|
}
|
|
38482
38712
|
|
|
38483
38713
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
38484
|
-
import { readFileSync as
|
|
38485
|
-
import { join as
|
|
38714
|
+
import { readFileSync as readFileSync19 } from "fs";
|
|
38715
|
+
import { join as join30 } from "path";
|
|
38486
38716
|
|
|
38487
38717
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
38488
38718
|
var REFUSAL_LINES = {
|
|
@@ -38953,11 +39183,11 @@ import { randomUUID as randomUUID19 } from "crypto";
|
|
|
38953
39183
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
38954
39184
|
|
|
38955
39185
|
// src/history/transcripts.ts
|
|
38956
|
-
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readFileSync as
|
|
39186
|
+
import { closeSync as closeSync3, openSync as openSync3, readdirSync as readdirSync5, readFileSync as readFileSync20, readSync as readSync2, statSync as statSync10 } from "fs";
|
|
38957
39187
|
import { homedir as homedir3 } from "os";
|
|
38958
|
-
import { join as
|
|
39188
|
+
import { join as join31 } from "path";
|
|
38959
39189
|
function transcriptsDir(home) {
|
|
38960
|
-
return
|
|
39190
|
+
return join31(home ?? homedir3(), ".codex", "sessions");
|
|
38961
39191
|
}
|
|
38962
39192
|
function isRecord(value) {
|
|
38963
39193
|
return typeof value === "object" && value !== null;
|
|
@@ -39196,7 +39426,7 @@ function* walkJsonlFiles(dir, depth = 0) {
|
|
|
39196
39426
|
return;
|
|
39197
39427
|
}
|
|
39198
39428
|
for (const entry of entries) {
|
|
39199
|
-
const full =
|
|
39429
|
+
const full = join31(dir, entry.name);
|
|
39200
39430
|
if (entry.isDirectory()) {
|
|
39201
39431
|
yield* walkJsonlFiles(full, depth + 1);
|
|
39202
39432
|
} else if (entry.isFile() && entry.name.endsWith(".jsonl")) {
|
|
@@ -39208,7 +39438,7 @@ function* iterateFileContents(dir) {
|
|
|
39208
39438
|
for (const filePath of walkJsonlFiles(dir)) {
|
|
39209
39439
|
try {
|
|
39210
39440
|
statSync10(filePath);
|
|
39211
|
-
yield { content:
|
|
39441
|
+
yield { content: readFileSync20(filePath, "utf8"), filePath };
|
|
39212
39442
|
} catch {
|
|
39213
39443
|
}
|
|
39214
39444
|
}
|
|
@@ -39329,11 +39559,11 @@ import {
|
|
|
39329
39559
|
fstatSync as fstatSync2,
|
|
39330
39560
|
mkdirSync as mkdirSync5,
|
|
39331
39561
|
openSync as openSync4,
|
|
39332
|
-
readFileSync as
|
|
39562
|
+
readFileSync as readFileSync21,
|
|
39333
39563
|
readSync as readSync3,
|
|
39334
39564
|
writeFileSync as writeFileSync10
|
|
39335
39565
|
} from "fs";
|
|
39336
|
-
import { join as
|
|
39566
|
+
import { join as join32 } from "path";
|
|
39337
39567
|
|
|
39338
39568
|
// src/history/usage.ts
|
|
39339
39569
|
var NO_PROJECT_CWD = "/nonexistent/aka-reconciler/no-project";
|