@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/reconcile.js
CHANGED
|
@@ -492,8 +492,8 @@ var require_ignore = __commonJS({
|
|
|
492
492
|
});
|
|
493
493
|
|
|
494
494
|
// ../../packages/plugin-sdk/src/config.ts
|
|
495
|
-
import { existsSync as
|
|
496
|
-
import { join as
|
|
495
|
+
import { existsSync as existsSync8 } from "fs";
|
|
496
|
+
import { join as join14 } from "path";
|
|
497
497
|
|
|
498
498
|
// ../../packages/persistence/src/attached-derived.ts
|
|
499
499
|
import { rmSync } from "fs";
|
|
@@ -20746,13 +20746,11 @@ var FindingGroup = external_exports.object({
|
|
|
20746
20746
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20747
20747
|
instances: external_exports.array(FindingInstance),
|
|
20748
20748
|
// Derived from instances' statuses with open-dominates precedence (see
|
|
20749
|
-
//
|
|
20749
|
+
// foldGroupStatus). Undefined only when no instance carries a status.
|
|
20750
20750
|
status: FindingStatus.optional(),
|
|
20751
|
-
// The distinct people across the WHOLE group, not just the
|
|
20752
|
-
//
|
|
20753
|
-
//
|
|
20754
|
-
// instance carries a user, or when the store supplied whole-group folds
|
|
20755
|
-
// without one.
|
|
20751
|
+
// The distinct people across the WHOLE group, not just the instances
|
|
20752
|
+
// carried here. Undefined when no instance carries a user, or when the
|
|
20753
|
+
// store supplied whole-group folds without one.
|
|
20756
20754
|
users: external_exports.array(FindingUser).optional()
|
|
20757
20755
|
}).meta({ id: "FindingGroup" });
|
|
20758
20756
|
var FindingStats = external_exports.object({
|
|
@@ -20781,21 +20779,31 @@ var FindingFacets = external_exports.object({
|
|
|
20781
20779
|
// counted under no value.
|
|
20782
20780
|
status: external_exports.array(FindingFacetItem),
|
|
20783
20781
|
// Host tool (attributes.tool_name). Present only on the instance-level
|
|
20784
|
-
// reads, which can filter by it; the
|
|
20782
|
+
// reads, which can filter by it; the type-level read omits the dimension
|
|
20785
20783
|
// because a group spans tools.
|
|
20786
20784
|
tool: external_exports.array(FindingFacetItem).optional()
|
|
20787
20785
|
}).meta({ id: "FindingFacets" });
|
|
20788
|
-
var
|
|
20789
|
-
|
|
20786
|
+
var FindingTypeSummary = FindingGroup.omit({ instances: true, match: true }).meta({
|
|
20787
|
+
id: "FindingTypeSummary"
|
|
20788
|
+
});
|
|
20789
|
+
var DEFAULT_FINDING_TYPES_LIMIT = 50;
|
|
20790
|
+
var MAX_FINDING_TYPES_LIMIT = 100;
|
|
20791
|
+
var ListFindingTypesQuery = external_exports.object({
|
|
20790
20792
|
// NOTE: severity filters by Severity (critical/high/medium/low), not by
|
|
20791
|
-
// FindingAction.
|
|
20793
|
+
// FindingAction. It narrows TYPES: a type's severity is the one its newest
|
|
20794
|
+
// firing version carries, and this list pages types.
|
|
20795
|
+
//
|
|
20796
|
+
// That is NOT a claim the findings of a type share it. A rule can hold several
|
|
20797
|
+
// definition versions at different severities, so a type kept by this filter
|
|
20798
|
+
// can hold findings that individually do not match — see totals.findings on
|
|
20799
|
+
// ListFindingTypesResponse, which counts them all.
|
|
20792
20800
|
severity: external_exports.array(Severity).optional(),
|
|
20793
20801
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20794
20802
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20795
20803
|
action: external_exports.array(FindingAction).optional(),
|
|
20796
|
-
// Matches a
|
|
20797
|
-
// individual
|
|
20798
|
-
//
|
|
20804
|
+
// Matches a type's DERIVED status (see FindingGroup.status), not its
|
|
20805
|
+
// individual findings' — so a filtered row's status always reads one of the
|
|
20806
|
+
// requested values.
|
|
20799
20807
|
status: external_exports.array(FindingStatus).optional(),
|
|
20800
20808
|
q: external_exports.string().optional(),
|
|
20801
20809
|
// Scope to findings whose event carries this session id (the Activity page's
|
|
@@ -20805,23 +20813,37 @@ var ListGroupedFindingsQuery = external_exports.object({
|
|
|
20805
20813
|
// from a time-scoped page (Activity's range) can carry that scope. Absent
|
|
20806
20814
|
// means all time — this list has no default window.
|
|
20807
20815
|
from: external_exports.iso.datetime().optional(),
|
|
20808
|
-
// A
|
|
20809
|
-
//
|
|
20810
|
-
//
|
|
20811
|
-
//
|
|
20812
|
-
//
|
|
20816
|
+
// A RULE id that must appear in the page even when the cursor has already
|
|
20817
|
+
// advanced past its sort position. This is what keeps the selected type
|
|
20818
|
+
// visible in the list once it paginates: the target is appended out of sort
|
|
20819
|
+
// order rather than scanned forward for. Never affects totals, facets or the
|
|
20820
|
+
// cursor. Unlike the grouped read this replaces, it names a rule only — an
|
|
20821
|
+
// instance id is resolved by `findingInstance`, which is a primary-key seek
|
|
20822
|
+
// and so is not bounded by what any page happens to hold.
|
|
20813
20823
|
includeId: external_exports.string().optional(),
|
|
20814
|
-
|
|
20815
|
-
limit: external_exports.coerce.number().int().min(1).max(100).optional(),
|
|
20824
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_TYPES_LIMIT).optional(),
|
|
20816
20825
|
cursor: external_exports.string().optional()
|
|
20817
20826
|
});
|
|
20818
|
-
var
|
|
20827
|
+
var ListFindingTypesResponse = external_exports.object({
|
|
20819
20828
|
totals: external_exports.object({
|
|
20829
|
+
// Findings belonging to the matching TYPES — not findings that each match
|
|
20830
|
+
// the filters. The filters here select types, so a type that survives
|
|
20831
|
+
// contributes its whole instanceCount.
|
|
20832
|
+
//
|
|
20833
|
+
// `status` is the one exception, narrowed per finding via
|
|
20834
|
+
// countInstancesByStatus. `severity`, `provider` and `action` are not, so
|
|
20835
|
+
// this can exceed what the instance read reports for the same filters: a
|
|
20836
|
+
// rule whose severity moved between versions is kept on its newest and
|
|
20837
|
+
// still counts its older findings. Narrowing the other three needs
|
|
20838
|
+
// per-dimension counts the aggregate does not carry today.
|
|
20820
20839
|
findings: external_exports.number().int().nonnegative(),
|
|
20821
|
-
|
|
20840
|
+
// Counts TYPES, which is the unit this read pages. The instance read's
|
|
20841
|
+
// own totals count findings; the two deliberately answer different
|
|
20842
|
+
// questions and are never summed.
|
|
20843
|
+
types: external_exports.number().int().nonnegative()
|
|
20822
20844
|
}),
|
|
20823
20845
|
facets: FindingFacets,
|
|
20824
|
-
items: external_exports.array(
|
|
20846
|
+
items: external_exports.array(FindingTypeSummary),
|
|
20825
20847
|
nextCursor: external_exports.string().nullable(),
|
|
20826
20848
|
// Present only on session-scoped queries (`sessionId` set): per ruleId, how
|
|
20827
20849
|
// many times that rule fired in the session's persisted transcript. Findings
|
|
@@ -20829,7 +20851,7 @@ var ListGroupedFindingsResponse = external_exports.object({
|
|
|
20829
20851
|
// every firing, so the two numbers legitimately differ — this map lets a
|
|
20830
20852
|
// session-scoped view show both.
|
|
20831
20853
|
sessionFirings: external_exports.record(external_exports.string(), external_exports.number().int().nonnegative()).optional()
|
|
20832
|
-
}).meta({ id: "
|
|
20854
|
+
}).meta({ id: "ListFindingTypesResponse" });
|
|
20833
20855
|
var ApplyFindingActionRequest = external_exports.object({
|
|
20834
20856
|
// 'quarantined' is system-assigned (see FindingAction) — clients may not set
|
|
20835
20857
|
// it, so it is excluded from the request contract. The mapping helper
|
|
@@ -20859,12 +20881,13 @@ var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
|
20859
20881
|
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
20860
20882
|
var ListFindingInstancesQuery = external_exports.object({
|
|
20861
20883
|
severity: external_exports.array(Severity).optional(),
|
|
20862
|
-
// Rule ids, the same vocabulary the
|
|
20884
|
+
// Rule ids, the same vocabulary the types list's `subtype` carries. Pinning
|
|
20885
|
+
// ONE of them is how the master/detail view scopes its right-hand panel.
|
|
20863
20886
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
20864
20887
|
provider: external_exports.array(FindingProvider).optional(),
|
|
20865
20888
|
action: external_exports.array(FindingAction).optional(),
|
|
20866
20889
|
// Matches each instance's OWN derived status (deriveFindingStatus), unlike
|
|
20867
|
-
// the
|
|
20890
|
+
// the types query's type-level fold.
|
|
20868
20891
|
status: external_exports.array(FindingStatus).optional(),
|
|
20869
20892
|
// Exact host-tool names (attributes.tool_name, e.g. 'Bash'). A real filter,
|
|
20870
20893
|
// where the free-text `q` can only match the rendered "via Bash" label.
|
|
@@ -20881,37 +20904,47 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
20881
20904
|
});
|
|
20882
20905
|
var ListFindingInstancesResponse = external_exports.object({
|
|
20883
20906
|
// Instances matching the filters across the whole scope, not just this
|
|
20884
|
-
// page — cursor-independent, like the
|
|
20907
|
+
// page — cursor-independent, like the types list's totals.
|
|
20885
20908
|
totals: external_exports.object({ findings: external_exports.number().int().nonnegative() }),
|
|
20886
|
-
// Counts in INSTANCES here, where the
|
|
20909
|
+
// Counts in INSTANCES here, where the types response counts types. Each
|
|
20887
20910
|
// dimension still excludes its own filter.
|
|
20888
20911
|
facets: FindingFacets,
|
|
20889
20912
|
items: external_exports.array(FindingInstanceDetail),
|
|
20890
20913
|
nextCursor: external_exports.string().nullable()
|
|
20891
20914
|
}).meta({ id: "ListFindingInstancesResponse" });
|
|
20892
|
-
var
|
|
20893
|
-
//
|
|
20894
|
-
//
|
|
20895
|
-
|
|
20896
|
-
|
|
20897
|
-
|
|
20898
|
-
|
|
20899
|
-
// Folded from the instances' derived statuses with the same
|
|
20900
|
-
// open-dominates precedence a group uses.
|
|
20901
|
-
status: FindingStatus.optional(),
|
|
20902
|
-
// Distinct rules seen at this location, capped — the row shows them as
|
|
20903
|
-
// chips, and the count is what conveys scale.
|
|
20904
|
-
ruleIds: external_exports.array(external_exports.string())
|
|
20905
|
-
}).meta({ id: "FindingLocationFile" });
|
|
20906
|
-
var FindingLocationRepo = external_exports.object({
|
|
20915
|
+
var FindingLocationSummary = external_exports.object({
|
|
20916
|
+
// Opaque, stable, minted from the pair by encodeLocationId. It exists
|
|
20917
|
+
// because a location's identity is two values and a URL param carries one:
|
|
20918
|
+
// `?loc=` names a location the way `?rule=` names a type. Only ever compared
|
|
20919
|
+
// for EQUALITY — the page's selection check, this read's `includeId`, the
|
|
20920
|
+
// client's page dedupe — never decoded, and never a sort key.
|
|
20921
|
+
id: external_exports.string(),
|
|
20907
20922
|
/** Empty when the instances carried no repo attribute. */
|
|
20908
20923
|
repo: external_exports.string(),
|
|
20924
|
+
// Empty when the instances carried no file path (a prompt, or a tool call
|
|
20925
|
+
// with no file attribution). Both halves empty is a real location — usually
|
|
20926
|
+
// the largest one in a store — and is selectable like any other.
|
|
20927
|
+
file: external_exports.string(),
|
|
20909
20928
|
instanceCount: external_exports.number().int().nonnegative(),
|
|
20929
|
+
// The WORST severity present, not the first row's. It is this list's primary
|
|
20930
|
+
// sort key, so it is also what explains why a row is where it is, and it is
|
|
20931
|
+
// how a reader decides what to open without opening everything.
|
|
20910
20932
|
maxSeverity: Severity,
|
|
20911
20933
|
latestDetectedAt: external_exports.iso.datetime(),
|
|
20934
|
+
// Folded from the instances' derived statuses with the same open-dominates
|
|
20935
|
+
// precedence a group uses, so it answers "is anything left to do here" and
|
|
20936
|
+
// not much more: a location holding 1 open among 40 resolved reads like one
|
|
20937
|
+
// holding 40 open. That loss is accepted — the panel beside this list
|
|
20938
|
+
// carries each finding's own status, and instanceCount sits next to the
|
|
20939
|
+
// badge.
|
|
20912
20940
|
status: FindingStatus.optional(),
|
|
20913
|
-
|
|
20914
|
-
|
|
20941
|
+
// Every distinct rule seen at this location, UNCAPPED — so the length is a
|
|
20942
|
+
// tally rather than a sample and a row can say how many there are. Bounded
|
|
20943
|
+
// by the ruleset, not by the store. The view bounds what it DISPLAYS.
|
|
20944
|
+
ruleIds: external_exports.array(external_exports.string())
|
|
20945
|
+
}).meta({ id: "FindingLocationSummary" });
|
|
20946
|
+
var DEFAULT_FINDING_LOCATIONS_LIMIT = 50;
|
|
20947
|
+
var MAX_FINDING_LOCATIONS_LIMIT = 100;
|
|
20915
20948
|
var ListFindingLocationsQuery = external_exports.object({
|
|
20916
20949
|
severity: external_exports.array(Severity).optional(),
|
|
20917
20950
|
subtype: external_exports.array(external_exports.string()).optional(),
|
|
@@ -20924,18 +20957,42 @@ var ListFindingLocationsQuery = external_exports.object({
|
|
|
20924
20957
|
q: external_exports.string().optional(),
|
|
20925
20958
|
sessionId: external_exports.string().optional(),
|
|
20926
20959
|
from: external_exports.iso.datetime().optional(),
|
|
20927
|
-
|
|
20960
|
+
// A LOCATION id (see FindingLocationSummary.id) that must appear in the page
|
|
20961
|
+
// even when the cursor has already advanced past its sort position — the
|
|
20962
|
+
// counterpart of ListFindingTypesQuery.includeId, and needed far more often
|
|
20963
|
+
// here. Selecting a row pushes the URL, which re-renders the server and resets
|
|
20964
|
+
// the client's page cache to page 0; with distinct (repo, file) pairs running
|
|
20965
|
+
// into the thousands, a selection sitting off page 0 is the ordinary case
|
|
20966
|
+
// rather than a deep-link corner. Never affects totals, facets or the cursor.
|
|
20967
|
+
includeId: external_exports.string().optional(),
|
|
20968
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FINDING_LOCATIONS_LIMIT).optional(),
|
|
20969
|
+
cursor: external_exports.string().optional()
|
|
20928
20970
|
});
|
|
20929
20971
|
var ListFindingLocationsResponse = external_exports.object({
|
|
20930
20972
|
totals: external_exports.object({
|
|
20973
|
+
// Findings matching the filters across the whole scope. Unlike the types
|
|
20974
|
+
// read's same-named field this needs no caveat: the filters here narrow
|
|
20975
|
+
// per finding, so this is the sum of every row's instanceCount.
|
|
20931
20976
|
findings: external_exports.number().int().nonnegative(),
|
|
20932
|
-
|
|
20933
|
-
|
|
20977
|
+
// Counts LOCATIONS, the unit this read pages — the number the paginator
|
|
20978
|
+
// states. The facets beside it count FINDINGS (see below); a surface
|
|
20979
|
+
// showing both says which is which.
|
|
20980
|
+
locations: external_exports.number().int().nonnegative()
|
|
20934
20981
|
}),
|
|
20935
|
-
|
|
20936
|
-
|
|
20937
|
-
|
|
20938
|
-
|
|
20982
|
+
// Counts in FINDINGS, where the types response counts types, each dimension
|
|
20983
|
+
// still excluding its own filter. Deliberately not locations: counting those
|
|
20984
|
+
// needs a set of location keys per dimension per value — memory tracking the
|
|
20985
|
+
// store times the vocabulary, in a read whose scan promises flat memory —
|
|
20986
|
+
// and the cheap per-location version is not an approximation but WRONG. A
|
|
20987
|
+
// location holding {claudecode, block} and {codex, warn} would survive
|
|
20988
|
+
// provider=claudecode AND action=warn, under which no single finding
|
|
20989
|
+
// matches, so the facet would contradict the instanceCount this whole view
|
|
20990
|
+
// rests on. Findings also keep the toolbar in the same unit as the page
|
|
20991
|
+
// tally and the panel it sits above.
|
|
20992
|
+
facets: FindingFacets,
|
|
20993
|
+
/** Sorted by max severity, then most recent, then (repo, file). */
|
|
20994
|
+
items: external_exports.array(FindingLocationSummary),
|
|
20995
|
+
nextCursor: external_exports.string().nullable()
|
|
20939
20996
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
20940
20997
|
|
|
20941
20998
|
// ../../packages/schema/src/zod/meta.ts
|
|
@@ -22104,6 +22161,14 @@ var ControlPlaneErrorBody = external_exports.object({
|
|
|
22104
22161
|
message: external_exports.string().optional()
|
|
22105
22162
|
}).optional()
|
|
22106
22163
|
});
|
|
22164
|
+
var RemoteFailureKind = external_exports.enum([
|
|
22165
|
+
"unauthorized",
|
|
22166
|
+
"forbidden",
|
|
22167
|
+
"route-absent",
|
|
22168
|
+
"invalid-request",
|
|
22169
|
+
"rejected",
|
|
22170
|
+
"unreachable"
|
|
22171
|
+
]);
|
|
22107
22172
|
var AttachDeviceRequest = external_exports.object({
|
|
22108
22173
|
// This machine's own continuity id, so re-attaching ROTATES the credential
|
|
22109
22174
|
// on one machine record instead of producing a second one. Client-minted
|
|
@@ -22797,139 +22862,62 @@ function deriveFindingStatus(row) {
|
|
|
22797
22862
|
if (row.latestResolutionStatus === "dismissed") return "dismissed";
|
|
22798
22863
|
return "open";
|
|
22799
22864
|
}
|
|
22800
|
-
function distinctUsers(instances) {
|
|
22801
|
-
const seen = /* @__PURE__ */ new Set();
|
|
22802
|
-
const users = [];
|
|
22803
|
-
for (const i of instances) {
|
|
22804
|
-
if (i.user === void 0 || seen.has(i.user.id)) continue;
|
|
22805
|
-
seen.add(i.user.id);
|
|
22806
|
-
users.push(i.user);
|
|
22807
|
-
}
|
|
22808
|
-
return users;
|
|
22809
|
-
}
|
|
22810
22865
|
function sortUsers(users) {
|
|
22811
22866
|
return [...users].sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
22812
22867
|
}
|
|
22813
|
-
function
|
|
22814
|
-
const overrides = opts.overrides;
|
|
22868
|
+
function buildFindingTypes(aggregates, opts = {}) {
|
|
22815
22869
|
const packNames = opts.packNames;
|
|
22816
|
-
const
|
|
22817
|
-
const
|
|
22818
|
-
|
|
22819
|
-
const
|
|
22820
|
-
|
|
22821
|
-
else byRuleId.set(row.ruleId, [row]);
|
|
22822
|
-
}
|
|
22823
|
-
const groups = [];
|
|
22824
|
-
for (const [ruleId, ruleRows] of byRuleId) {
|
|
22825
|
-
const instances = ruleRows.map((r) => {
|
|
22826
|
-
const effectiveDbAction = overrides?.get(r.id) ?? r.actionTaken;
|
|
22827
|
-
return {
|
|
22828
|
-
id: r.id,
|
|
22829
|
-
provider: toApiProvider(r.sourceTool),
|
|
22830
|
-
repo: r.repo,
|
|
22831
|
-
file: r.file,
|
|
22832
|
-
...r.toolName === void 0 ? {} : { toolName: r.toolName },
|
|
22833
|
-
...r.eventId === void 0 ? {} : { eventId: r.eventId },
|
|
22834
|
-
...r.sessionId === void 0 ? {} : { sessionId: r.sessionId },
|
|
22835
|
-
...r.user === void 0 ? {} : { user: r.user },
|
|
22836
|
-
action: toApiAction(effectiveDbAction),
|
|
22837
|
-
detectedAt: r.occurredAt,
|
|
22838
|
-
confidence: r.confidence,
|
|
22839
|
-
status: r.status
|
|
22840
|
-
};
|
|
22841
|
-
});
|
|
22842
|
-
const agg = aggregates?.get(ruleId);
|
|
22843
|
-
const users = agg ? sortUsers(agg.users ?? []) : distinctUsers(instances);
|
|
22844
|
-
const latestDetectedAt = agg?.latestDetectedAt ?? ruleRows.reduce(
|
|
22845
|
-
(max, r) => r.occurredAt > max ? r.occurredAt : max,
|
|
22846
|
-
ruleRows[0]?.occurredAt ?? (/* @__PURE__ */ new Date(0)).toISOString()
|
|
22847
|
-
);
|
|
22848
|
-
const seenProviders = /* @__PURE__ */ new Set();
|
|
22849
|
-
const providers = (agg ? [...new Set(agg.sourceTools.map(toApiProvider))].sort() : instances.map((i) => i.provider)).filter((p) => {
|
|
22850
|
-
if (seenProviders.has(p)) return false;
|
|
22851
|
-
seenProviders.add(p);
|
|
22852
|
-
return true;
|
|
22853
|
-
});
|
|
22854
|
-
const actionSet = new Set(
|
|
22855
|
-
agg ? agg.actionsTaken.map(toApiAction) : instances.map((i) => i.action)
|
|
22856
|
-
);
|
|
22870
|
+
const types = [];
|
|
22871
|
+
for (const [ruleId, agg] of aggregates) {
|
|
22872
|
+
const users = sortUsers(agg.users ?? []);
|
|
22873
|
+
const providers = [...new Set(agg.sourceTools.map(toApiProvider))].sort();
|
|
22874
|
+
const actionSet = new Set(agg.actionsTaken.map(toApiAction));
|
|
22857
22875
|
const aggregateAction = actionSet.size === 1 ? [...actionSet][0] ?? null : null;
|
|
22858
|
-
const
|
|
22859
|
-
const
|
|
22860
|
-
id: ruleId,
|
|
22861
|
-
name: packNames?.get(ruleId) ?? null
|
|
22862
|
-
};
|
|
22863
|
-
const apiCategory = toApiCategory(ruleRows[0]?.category ?? "custom");
|
|
22864
|
-
const policy = { id: `category:${apiCategory}`, name: apiCategory };
|
|
22865
|
-
const match = {
|
|
22866
|
-
maskedValue: ruleRows[0]?.maskedMatch ?? "",
|
|
22867
|
-
contextPrefix: ""
|
|
22868
|
-
// empty (pending privacy review)
|
|
22869
|
-
};
|
|
22870
|
-
const status = foldGroupStatus(
|
|
22871
|
-
agg ? agg.statusInputs.map(deriveFindingStatus) : instances.map((i) => i.status)
|
|
22872
|
-
);
|
|
22873
|
-
const group = {
|
|
22876
|
+
const apiCategory = toApiCategory(agg.category ?? "custom");
|
|
22877
|
+
const type = {
|
|
22874
22878
|
id: ruleId,
|
|
22875
22879
|
category: apiCategory,
|
|
22876
22880
|
subtype: ruleId,
|
|
22877
22881
|
// human label comes with pack metadata later
|
|
22878
|
-
severity,
|
|
22879
|
-
|
|
22880
|
-
|
|
22881
|
-
|
|
22882
|
-
instanceCount: agg?.instanceCount ?? instances.length,
|
|
22882
|
+
severity: agg.severity ?? "low",
|
|
22883
|
+
detection: { id: ruleId, name: packNames?.get(ruleId) ?? null },
|
|
22884
|
+
policy: { id: `category:${apiCategory}`, name: apiCategory },
|
|
22885
|
+
instanceCount: agg.instanceCount,
|
|
22883
22886
|
providers,
|
|
22884
22887
|
aggregateAction,
|
|
22885
|
-
latestDetectedAt,
|
|
22886
|
-
|
|
22887
|
-
status,
|
|
22888
|
+
latestDetectedAt: agg.latestDetectedAt,
|
|
22889
|
+
status: foldGroupStatus(agg.statusInputs.map(deriveFindingStatus)),
|
|
22888
22890
|
...users.length > 0 ? { users } : {}
|
|
22889
22891
|
};
|
|
22890
|
-
|
|
22891
|
-
|
|
22892
|
-
|
|
22893
|
-
haystackCache.set(group, buildHaystack(group, agg.searchText));
|
|
22894
|
-
}
|
|
22892
|
+
actionsCache.set(type, [...actionSet]);
|
|
22893
|
+
if (agg.searchText !== void 0) {
|
|
22894
|
+
haystackCache.set(type, buildHaystack(type, agg.searchText));
|
|
22895
22895
|
}
|
|
22896
|
-
|
|
22896
|
+
types.push(type);
|
|
22897
22897
|
}
|
|
22898
|
-
return
|
|
22898
|
+
return types;
|
|
22899
22899
|
}
|
|
22900
22900
|
var haystackCache = /* @__PURE__ */ new WeakMap();
|
|
22901
|
-
function buildHaystack(
|
|
22901
|
+
function buildHaystack(t, extra) {
|
|
22902
22902
|
return [
|
|
22903
|
-
|
|
22904
|
-
|
|
22905
|
-
|
|
22906
|
-
|
|
22907
|
-
|
|
22908
|
-
...g.instances.map((i) => i.repo),
|
|
22909
|
-
...g.instances.map((i) => i.file),
|
|
22910
|
-
...g.instances.map((i) => i.toolName ? `via ${i.toolName}` : ""),
|
|
22911
|
-
...g.instances.map((i) => i.id),
|
|
22912
|
-
// The people: the whole group's list when the store folded one, plus the
|
|
22913
|
-
// preview's own — the two overlap, and a haystack does not mind.
|
|
22914
|
-
...(g.users ?? []).map((u) => u.name),
|
|
22915
|
-
...g.instances.map((i) => i.user?.name ?? ""),
|
|
22903
|
+
t.subtype,
|
|
22904
|
+
t.category,
|
|
22905
|
+
t.policy.name,
|
|
22906
|
+
t.id,
|
|
22907
|
+
...(t.users ?? []).map((u) => u.name),
|
|
22916
22908
|
...extra === void 0 ? [] : [extra]
|
|
22917
22909
|
].join(" ").toLowerCase();
|
|
22918
22910
|
}
|
|
22919
|
-
function
|
|
22920
|
-
const cached2 = haystackCache.get(
|
|
22911
|
+
function typeHaystack(t) {
|
|
22912
|
+
const cached2 = haystackCache.get(t);
|
|
22921
22913
|
if (cached2 !== void 0) return cached2;
|
|
22922
|
-
const haystack = buildHaystack(
|
|
22923
|
-
haystackCache.set(
|
|
22914
|
+
const haystack = buildHaystack(t);
|
|
22915
|
+
haystackCache.set(t, haystack);
|
|
22924
22916
|
return haystack;
|
|
22925
22917
|
}
|
|
22926
22918
|
var actionsCache = /* @__PURE__ */ new WeakMap();
|
|
22927
|
-
function
|
|
22928
|
-
|
|
22929
|
-
if (cached2 !== void 0) return cached2;
|
|
22930
|
-
const actions = [...new Set(g.instances.map((i) => i.action))];
|
|
22931
|
-
actionsCache.set(g, actions);
|
|
22932
|
-
return actions;
|
|
22919
|
+
function typeActions(t) {
|
|
22920
|
+
return actionsCache.get(t) ?? [];
|
|
22933
22921
|
}
|
|
22934
22922
|
function countInstancesByStatus(statusInputs, statuses) {
|
|
22935
22923
|
const statusSet = new Set(statuses);
|
|
@@ -22940,8 +22928,8 @@ function countInstancesByStatus(statusInputs, statuses) {
|
|
|
22940
22928
|
}
|
|
22941
22929
|
return sum;
|
|
22942
22930
|
}
|
|
22943
|
-
function applyFindingFilters(
|
|
22944
|
-
let filtered =
|
|
22931
|
+
function applyFindingFilters(types, opts) {
|
|
22932
|
+
let filtered = types;
|
|
22945
22933
|
if (opts.severity && opts.severity.length > 0) {
|
|
22946
22934
|
const sevSet = new Set(opts.severity);
|
|
22947
22935
|
filtered = filtered.filter((g) => sevSet.has(g.severity));
|
|
@@ -22952,7 +22940,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22952
22940
|
}
|
|
22953
22941
|
if (opts.actions && opts.actions.length > 0) {
|
|
22954
22942
|
const actionSet = new Set(opts.actions);
|
|
22955
|
-
filtered = filtered.filter((
|
|
22943
|
+
filtered = filtered.filter((t) => typeActions(t).some((a) => actionSet.has(a)));
|
|
22956
22944
|
}
|
|
22957
22945
|
if (opts.subtype && opts.subtype.length > 0) {
|
|
22958
22946
|
const subtypeSet = new Set(opts.subtype);
|
|
@@ -22964,7 +22952,7 @@ function applyFindingFilters(groups, opts) {
|
|
|
22964
22952
|
}
|
|
22965
22953
|
if (opts.q) {
|
|
22966
22954
|
const q = opts.q.toLowerCase();
|
|
22967
|
-
filtered = filtered.filter((
|
|
22955
|
+
filtered = filtered.filter((t) => typeHaystack(t).includes(q));
|
|
22968
22956
|
}
|
|
22969
22957
|
return filtered;
|
|
22970
22958
|
}
|
|
@@ -22979,11 +22967,11 @@ function compareFindingGroupOrder(a, b) {
|
|
|
22979
22967
|
if (recencyDiff !== 0) return recencyDiff;
|
|
22980
22968
|
return a.id.localeCompare(b.id);
|
|
22981
22969
|
}
|
|
22982
|
-
function
|
|
22983
|
-
return [...
|
|
22970
|
+
function sortFindingTypes(types) {
|
|
22971
|
+
return [...types].sort(compareFindingGroupOrder);
|
|
22984
22972
|
}
|
|
22985
|
-
function computeFindingFacets(
|
|
22986
|
-
const forSeverity = applyFindingFilters(
|
|
22973
|
+
function computeFindingFacets(allTypes, opts) {
|
|
22974
|
+
const forSeverity = applyFindingFilters(allTypes, {
|
|
22987
22975
|
providers: opts.providers,
|
|
22988
22976
|
actions: opts.actions,
|
|
22989
22977
|
statuses: opts.statuses,
|
|
@@ -22994,7 +22982,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
22994
22982
|
for (const g of forSeverity) {
|
|
22995
22983
|
severityMap.set(g.severity, (severityMap.get(g.severity) ?? 0) + 1);
|
|
22996
22984
|
}
|
|
22997
|
-
const forProvider = applyFindingFilters(
|
|
22985
|
+
const forProvider = applyFindingFilters(allTypes, {
|
|
22998
22986
|
actions: opts.actions,
|
|
22999
22987
|
statuses: opts.statuses,
|
|
23000
22988
|
q: opts.q,
|
|
@@ -23005,7 +22993,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23005
22993
|
for (const g of forProvider) {
|
|
23006
22994
|
for (const p of g.providers) providerMap.set(p, (providerMap.get(p) ?? 0) + 1);
|
|
23007
22995
|
}
|
|
23008
|
-
const forAction = applyFindingFilters(
|
|
22996
|
+
const forAction = applyFindingFilters(allTypes, {
|
|
23009
22997
|
providers: opts.providers,
|
|
23010
22998
|
statuses: opts.statuses,
|
|
23011
22999
|
q: opts.q,
|
|
@@ -23014,9 +23002,9 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23014
23002
|
});
|
|
23015
23003
|
const actionMap = /* @__PURE__ */ new Map();
|
|
23016
23004
|
for (const g of forAction) {
|
|
23017
|
-
for (const a of
|
|
23005
|
+
for (const a of typeActions(g)) actionMap.set(a, (actionMap.get(a) ?? 0) + 1);
|
|
23018
23006
|
}
|
|
23019
|
-
const forSubtype = applyFindingFilters(
|
|
23007
|
+
const forSubtype = applyFindingFilters(allTypes, {
|
|
23020
23008
|
providers: opts.providers,
|
|
23021
23009
|
actions: opts.actions,
|
|
23022
23010
|
statuses: opts.statuses,
|
|
@@ -23025,7 +23013,7 @@ function computeFindingFacets(allGroups, opts) {
|
|
|
23025
23013
|
});
|
|
23026
23014
|
const subtypeMap = /* @__PURE__ */ new Map();
|
|
23027
23015
|
for (const g of forSubtype) subtypeMap.set(g.subtype, (subtypeMap.get(g.subtype) ?? 0) + 1);
|
|
23028
|
-
const forStatus = applyFindingFilters(
|
|
23016
|
+
const forStatus = applyFindingFilters(allTypes, {
|
|
23029
23017
|
providers: opts.providers,
|
|
23030
23018
|
actions: opts.actions,
|
|
23031
23019
|
q: opts.q,
|
|
@@ -23073,10 +23061,20 @@ function matchesDimension(row, opts, dimension) {
|
|
|
23073
23061
|
return !opts.statuses?.length || row.status !== void 0 && opts.statuses.includes(row.status);
|
|
23074
23062
|
case "tools":
|
|
23075
23063
|
return !opts.tools?.length || row.toolName !== void 0 && opts.tools.includes(row.toolName);
|
|
23064
|
+
// An EMPTY value is a real filter here, not an absent one. The location
|
|
23065
|
+
// list buckets a finding whose event recorded no repo — or no file — under
|
|
23066
|
+
// the empty string, and selecting that bucket has to narrow the panel to
|
|
23067
|
+
// exactly it. Only `undefined` means "no filter"; a caller that wants every
|
|
23068
|
+
// row omits the key, which every call site already does.
|
|
23069
|
+
//
|
|
23070
|
+
// Reading '' as unset is what this replaced, and it failed in the one place
|
|
23071
|
+
// it mattered: the no-repo/no-file bucket is often the largest in a real
|
|
23072
|
+
// store, and its panel dropped both predicates and returned the WHOLE scope
|
|
23073
|
+
// — a row reading 3 findings beside a panel listing every finding there is.
|
|
23076
23074
|
case "repo":
|
|
23077
|
-
return opts.repo === void 0 ||
|
|
23075
|
+
return opts.repo === void 0 || row.repo === opts.repo;
|
|
23078
23076
|
case "file":
|
|
23079
|
-
return opts.file === void 0 ||
|
|
23077
|
+
return opts.file === void 0 || row.file === opts.file;
|
|
23080
23078
|
case "q":
|
|
23081
23079
|
return !opts.q || rowHaystack(row).includes(opts.q.toLowerCase());
|
|
23082
23080
|
}
|
|
@@ -23190,6 +23188,23 @@ function addToLocation(acc, row) {
|
|
|
23190
23188
|
acc.statuses.push(row.status);
|
|
23191
23189
|
acc.ruleIds.add(row.ruleId);
|
|
23192
23190
|
}
|
|
23191
|
+
function compareLocationOrder(a, b) {
|
|
23192
|
+
const rankA = SEVERITY_ORDER2[a.maxSeverity] ?? -1;
|
|
23193
|
+
const rankB = SEVERITY_ORDER2[b.maxSeverity] ?? -1;
|
|
23194
|
+
if (rankA !== rankB) return rankA - rankB;
|
|
23195
|
+
if (a.latestDetectedAt !== b.latestDetectedAt) {
|
|
23196
|
+
return a.latestDetectedAt < b.latestDetectedAt ? 1 : -1;
|
|
23197
|
+
}
|
|
23198
|
+
if (a.repo !== b.repo) return a.repo < b.repo ? -1 : 1;
|
|
23199
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
23200
|
+
return 0;
|
|
23201
|
+
}
|
|
23202
|
+
function encodeLocationId(repo, file2) {
|
|
23203
|
+
return `${encodePart(repo)}/${encodePart(file2)}`;
|
|
23204
|
+
}
|
|
23205
|
+
function encodePart(value) {
|
|
23206
|
+
return encodeURIComponent(value.replace(/[\uD800-\uDFFF]/gu, "\uFFFD"));
|
|
23207
|
+
}
|
|
23193
23208
|
|
|
23194
23209
|
// ../../packages/schema/src/zod/installed-pack.ts
|
|
23195
23210
|
var InstalledPack = external_exports.object({
|
|
@@ -23696,11 +23711,11 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23696
23711
|
// covers the current payload and must be re-granted.
|
|
23697
23712
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23698
23713
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23699
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23700
|
-
// that covers
|
|
23701
|
-
// carry prompt/reply text in `content
|
|
23702
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23703
|
-
// payload no longer counts.
|
|
23714
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23715
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23716
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23717
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23718
|
+
// or an older payload no longer counts.
|
|
23704
23719
|
historySyncConsent: HistorySyncConsent.optional()
|
|
23705
23720
|
});
|
|
23706
23721
|
function defaultWorkspaceSettings() {
|
|
@@ -23831,6 +23846,9 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23831
23846
|
"dataSharesInPlace",
|
|
23832
23847
|
"redactFallback"
|
|
23833
23848
|
]).meta({ id: "ManagedSettingKey" });
|
|
23849
|
+
function isManagedSettingKey(value) {
|
|
23850
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
23851
|
+
}
|
|
23834
23852
|
var ManagedSettingsValues = external_exports.object({
|
|
23835
23853
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
23836
23854
|
controlPlane: external_exports.object({
|
|
@@ -23855,7 +23873,27 @@ var ManagedSettings = external_exports.object({
|
|
|
23855
23873
|
// Which of those the user may not change. A key here with no matching value
|
|
23856
23874
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23857
23875
|
// the user may still override. The two are separable on purpose.
|
|
23858
|
-
|
|
23876
|
+
//
|
|
23877
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
23878
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
23879
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
23880
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
23881
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
23882
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23883
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
23884
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23885
|
+
}).transform(({ lockedFields, ...rest }) => {
|
|
23886
|
+
const known = [];
|
|
23887
|
+
const unknown2 = [];
|
|
23888
|
+
for (const name of lockedFields) {
|
|
23889
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
23890
|
+
else unknown2.push(name);
|
|
23891
|
+
}
|
|
23892
|
+
return {
|
|
23893
|
+
...rest,
|
|
23894
|
+
lockedFields: known,
|
|
23895
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
23896
|
+
};
|
|
23859
23897
|
}).meta({ id: "ManagedSettings" });
|
|
23860
23898
|
|
|
23861
23899
|
// ../../packages/schema/src/zod/project-files.ts
|
|
@@ -23979,7 +24017,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23979
24017
|
timestamp: external_exports.iso.date(),
|
|
23980
24018
|
critical: external_exports.number().int().nonnegative(),
|
|
23981
24019
|
high: external_exports.number().int().nonnegative(),
|
|
23982
|
-
medium: external_exports.number().int().nonnegative()
|
|
24020
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24021
|
+
// Optional and additive, so a producer written against the earlier
|
|
24022
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24023
|
+
// absent case itself — the chart point requires a number.
|
|
24024
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23983
24025
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23984
24026
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23985
24027
|
range: TimeRange,
|
|
@@ -24005,6 +24047,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24005
24047
|
findingKey: external_exports.string(),
|
|
24006
24048
|
ruleId: external_exports.string(),
|
|
24007
24049
|
severity: Severity,
|
|
24050
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24051
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24052
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24053
|
+
repo: external_exports.string().optional(),
|
|
24008
24054
|
path: external_exports.string(),
|
|
24009
24055
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24010
24056
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -25548,7 +25594,8 @@ var SqliteActivityRepository = class {
|
|
|
25548
25594
|
SELECT 1 FROM audit_events d
|
|
25549
25595
|
WHERE d.root_session_id = audit_events.id
|
|
25550
25596
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25551
|
-
OR json_extract(d.attributes, '$.detail')
|
|
25597
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
25598
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25552
25599
|
);
|
|
25553
25600
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25554
25601
|
}
|
|
@@ -26886,23 +26933,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26886
26933
|
)`;
|
|
26887
26934
|
|
|
26888
26935
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26889
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26890
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26891
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26892
|
-
function compareLocationOrder(a, b) {
|
|
26893
|
-
return compareFindingGroupOrder(
|
|
26894
|
-
{
|
|
26895
|
-
severity: a.maxSeverity,
|
|
26896
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26897
|
-
id: ""
|
|
26898
|
-
},
|
|
26899
|
-
{
|
|
26900
|
-
severity: b.maxSeverity,
|
|
26901
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26902
|
-
id: ""
|
|
26903
|
-
}
|
|
26904
|
-
);
|
|
26905
|
-
}
|
|
26906
26936
|
var CONCAT_SEP = ",";
|
|
26907
26937
|
var TUPLE_SEP = "|";
|
|
26908
26938
|
function splitConcat(value) {
|
|
@@ -26954,13 +26984,48 @@ function decodeGroupCursor(cursor) {
|
|
|
26954
26984
|
return null;
|
|
26955
26985
|
}
|
|
26956
26986
|
function firstAfter(sorted, cursor) {
|
|
26957
|
-
const index = sorted.findIndex((
|
|
26987
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26958
26988
|
return index === -1 ? sorted.length : index;
|
|
26959
26989
|
}
|
|
26960
26990
|
function findDeepLinked(sorted, page, id) {
|
|
26961
|
-
if (page.some((
|
|
26962
|
-
return sorted.find((
|
|
26991
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
26992
|
+
return sorted.find((t) => t.id === id);
|
|
26993
|
+
}
|
|
26994
|
+
function encodeLocationCursor(location) {
|
|
26995
|
+
const payload = {
|
|
26996
|
+
sev: location.maxSeverity,
|
|
26997
|
+
t: location.latestDetectedAt,
|
|
26998
|
+
r: location.repo,
|
|
26999
|
+
f: location.file
|
|
27000
|
+
};
|
|
27001
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
27002
|
+
}
|
|
27003
|
+
function decodeLocationCursor(cursor) {
|
|
27004
|
+
const parsed2 = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
27005
|
+
if (parsed2 !== void 0 && typeof parsed2.sev === "string" && typeof parsed2.t === "string" && typeof parsed2.r === "string" && typeof parsed2.f === "string") {
|
|
27006
|
+
return { maxSeverity: parsed2.sev, latestDetectedAt: parsed2.t, repo: parsed2.r, file: parsed2.f };
|
|
27007
|
+
}
|
|
27008
|
+
return null;
|
|
27009
|
+
}
|
|
27010
|
+
function firstLocationAfter(sorted, cursor) {
|
|
27011
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
27012
|
+
return index === -1 ? sorted.length : index;
|
|
27013
|
+
}
|
|
27014
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
27015
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
27016
|
+
return sorted.find((l) => l.id === id);
|
|
26963
27017
|
}
|
|
27018
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
27019
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
27020
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27021
|
+
e.started_at AS occurred_at,
|
|
27022
|
+
e.source_tool AS source_tool,
|
|
27023
|
+
e.repo AS repo,
|
|
27024
|
+
e.file_path AS file,
|
|
27025
|
+
e.tool_name AS tool_name,
|
|
27026
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27027
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27028
|
+
${latestResolutionStatusSql("f")} AS latest_status`;
|
|
26964
27029
|
var DAY_MS3 = 864e5;
|
|
26965
27030
|
var SqliteFindingsRepository = class {
|
|
26966
27031
|
constructor(db) {
|
|
@@ -27081,30 +27146,26 @@ var SqliteFindingsRepository = class {
|
|
|
27081
27146
|
);
|
|
27082
27147
|
}
|
|
27083
27148
|
/**
|
|
27084
|
-
*
|
|
27085
|
-
*
|
|
27086
|
-
*
|
|
27087
|
-
*
|
|
27088
|
-
*
|
|
27089
|
-
*
|
|
27090
|
-
*
|
|
27091
|
-
*
|
|
27092
|
-
*
|
|
27093
|
-
*
|
|
27094
|
-
*
|
|
27095
|
-
*
|
|
27149
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
27150
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
27151
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
27152
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
27153
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
27154
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
27155
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
27156
|
+
* derived status was requested.
|
|
27157
|
+
*
|
|
27158
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
27159
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
27160
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
27161
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
27162
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
27096
27163
|
*
|
|
27097
|
-
* Two reads, neither of which materializes a row per finding:
|
|
27098
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
27099
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
27100
|
-
* latest, search text);
|
|
27101
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
27102
|
-
* populate `instances` for the table's expanded rows.
|
|
27103
27164
|
* The aggregates carry raw DB values and are translated by the same
|
|
27104
|
-
* @akasecurity/schema mappers
|
|
27105
|
-
* rule is ever restated in SQL.
|
|
27165
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
27166
|
+
* status rule is ever restated in SQL.
|
|
27106
27167
|
*/
|
|
27107
|
-
|
|
27168
|
+
listFindingTypes(query) {
|
|
27108
27169
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
27109
27170
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
27110
27171
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -27117,12 +27178,7 @@ var SqliteFindingsRepository = class {
|
|
|
27117
27178
|
predicate,
|
|
27118
27179
|
params: sessionParams
|
|
27119
27180
|
});
|
|
27120
|
-
const
|
|
27121
|
-
sessionId: query.sessionId,
|
|
27122
|
-
from: query.from
|
|
27123
|
-
});
|
|
27124
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27125
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
27181
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27126
27182
|
const filterOpts = {
|
|
27127
27183
|
severity: query.severity,
|
|
27128
27184
|
providers: query.provider,
|
|
@@ -27131,30 +27187,25 @@ var SqliteFindingsRepository = class {
|
|
|
27131
27187
|
subtype: query.subtype,
|
|
27132
27188
|
q: query.q
|
|
27133
27189
|
};
|
|
27134
|
-
const facets = computeFindingFacets(
|
|
27135
|
-
const sorted =
|
|
27190
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
27191
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27136
27192
|
const statusFilter = query.status ?? [];
|
|
27137
27193
|
const totals = {
|
|
27138
|
-
findings: sorted.reduce((acc,
|
|
27139
|
-
if (statusFilter.length === 0) return acc +
|
|
27140
|
-
const agg = aggregates.get(
|
|
27141
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
27194
|
+
findings: sorted.reduce((acc, t) => {
|
|
27195
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
27196
|
+
const agg = aggregates.get(t.id);
|
|
27197
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27142
27198
|
}, 0),
|
|
27143
|
-
|
|
27199
|
+
types: sorted.length
|
|
27144
27200
|
};
|
|
27145
|
-
const limit = query.limit ??
|
|
27201
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27146
27202
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27147
27203
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27148
27204
|
const page = sorted.slice(start, start + limit);
|
|
27149
27205
|
const lastOnPage = page.at(-1);
|
|
27150
27206
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27151
27207
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27152
|
-
const
|
|
27153
|
-
const narrow = (g) => statusSet ? {
|
|
27154
|
-
...g,
|
|
27155
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27156
|
-
} : g;
|
|
27157
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
27208
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27158
27209
|
return Promise.resolve({
|
|
27159
27210
|
totals,
|
|
27160
27211
|
facets,
|
|
@@ -27165,7 +27216,7 @@ var SqliteFindingsRepository = class {
|
|
|
27165
27216
|
}
|
|
27166
27217
|
/**
|
|
27167
27218
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27168
|
-
*
|
|
27219
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27169
27220
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27170
27221
|
*
|
|
27171
27222
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27259,13 +27310,25 @@ var SqliteFindingsRepository = class {
|
|
|
27259
27310
|
});
|
|
27260
27311
|
}
|
|
27261
27312
|
/**
|
|
27262
|
-
* The same findings folded by
|
|
27313
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27263
27314
|
*
|
|
27264
27315
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27265
|
-
* the local store relates a finding to
|
|
27266
|
-
*
|
|
27267
|
-
* empty-string bucket, which
|
|
27268
|
-
*
|
|
27316
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
27317
|
+
* by instead. A repo or file the event did not record folds into the
|
|
27318
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
27319
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
27320
|
+
*
|
|
27321
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
27322
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
27323
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
27324
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
27325
|
+
* place.
|
|
27326
|
+
*
|
|
27327
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
27328
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
27329
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
27330
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
27331
|
+
* its fields.
|
|
27269
27332
|
*/
|
|
27270
27333
|
listFindingLocations(query) {
|
|
27271
27334
|
const opts = {
|
|
@@ -27277,13 +27340,16 @@ var SqliteFindingsRepository = class {
|
|
|
27277
27340
|
tools: query.tool,
|
|
27278
27341
|
q: query.q
|
|
27279
27342
|
};
|
|
27280
|
-
const limit = query.limit ??
|
|
27343
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
27344
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27281
27345
|
const byRepo = /* @__PURE__ */ new Map();
|
|
27346
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27282
27347
|
let total = 0;
|
|
27283
27348
|
for (const row of this.scanFindingRows({
|
|
27284
27349
|
sessionId: query.sessionId,
|
|
27285
27350
|
from: query.from
|
|
27286
27351
|
})) {
|
|
27352
|
+
accumulator.add(row);
|
|
27287
27353
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27288
27354
|
total += 1;
|
|
27289
27355
|
let files = byRepo.get(row.repo);
|
|
@@ -27298,103 +27364,35 @@ var SqliteFindingsRepository = class {
|
|
|
27298
27364
|
}
|
|
27299
27365
|
addToLocation(acc, row);
|
|
27300
27366
|
}
|
|
27301
|
-
|
|
27302
|
-
const
|
|
27303
|
-
|
|
27304
|
-
|
|
27305
|
-
|
|
27306
|
-
|
|
27307
|
-
|
|
27308
|
-
|
|
27309
|
-
|
|
27310
|
-
|
|
27311
|
-
|
|
27312
|
-
|
|
27313
|
-
|
|
27314
|
-
|
|
27315
|
-
|
|
27316
|
-
|
|
27317
|
-
|
|
27318
|
-
|
|
27319
|
-
|
|
27320
|
-
|
|
27321
|
-
|
|
27322
|
-
|
|
27323
|
-
);
|
|
27324
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27325
|
-
const folded = foldGroupStatus(statuses);
|
|
27326
|
-
return {
|
|
27327
|
-
repo,
|
|
27328
|
-
instanceCount: rollup.instanceCount,
|
|
27329
|
-
maxSeverity: rollup.maxSeverity,
|
|
27330
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27331
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27332
|
-
files: fileRows
|
|
27333
|
-
};
|
|
27334
|
-
});
|
|
27335
|
-
repos.sort(compareLocationOrder);
|
|
27367
|
+
const sorted = [];
|
|
27368
|
+
for (const [repo, files] of byRepo) {
|
|
27369
|
+
for (const [file2, acc] of files) {
|
|
27370
|
+
const status = foldGroupStatus(acc.statuses);
|
|
27371
|
+
sorted.push({
|
|
27372
|
+
id: encodeLocationId(repo, file2),
|
|
27373
|
+
repo,
|
|
27374
|
+
file: file2,
|
|
27375
|
+
instanceCount: acc.instanceCount,
|
|
27376
|
+
maxSeverity: acc.maxSeverity,
|
|
27377
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
27378
|
+
...status === void 0 ? {} : { status },
|
|
27379
|
+
ruleIds: [...acc.ruleIds]
|
|
27380
|
+
});
|
|
27381
|
+
}
|
|
27382
|
+
}
|
|
27383
|
+
sorted.sort(compareLocationOrder);
|
|
27384
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
27385
|
+
const page = sorted.slice(start, start + limit);
|
|
27386
|
+
const lastOnPage = page.at(-1);
|
|
27387
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
27388
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27336
27389
|
return Promise.resolve({
|
|
27337
|
-
totals: { findings: total,
|
|
27338
|
-
|
|
27339
|
-
|
|
27390
|
+
totals: { findings: total, locations: sorted.length },
|
|
27391
|
+
facets: accumulator.facets(),
|
|
27392
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
27393
|
+
nextCursor
|
|
27340
27394
|
});
|
|
27341
27395
|
}
|
|
27342
|
-
/**
|
|
27343
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27344
|
-
*
|
|
27345
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27346
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27347
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27348
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27349
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27350
|
-
* store while the answer does not.
|
|
27351
|
-
*
|
|
27352
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27353
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27354
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27355
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27356
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27357
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27358
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27359
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27360
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27361
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27362
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27363
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27364
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27365
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27366
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27367
|
-
* sort of the scope, which is still that floor.
|
|
27368
|
-
*
|
|
27369
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27370
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27371
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27372
|
-
* built from.
|
|
27373
|
-
*/
|
|
27374
|
-
previewRows(aggregates, scope) {
|
|
27375
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27376
|
-
let remaining = 0;
|
|
27377
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27378
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27379
|
-
wanted.set(ruleId, n);
|
|
27380
|
-
remaining += n;
|
|
27381
|
-
}
|
|
27382
|
-
const rows = [];
|
|
27383
|
-
if (remaining === 0) return rows;
|
|
27384
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27385
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27386
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27387
|
-
const want = wanted.get(r.rule_id);
|
|
27388
|
-
if (want === void 0) continue;
|
|
27389
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27390
|
-
if (have >= want) continue;
|
|
27391
|
-
taken.set(r.rule_id, have + 1);
|
|
27392
|
-
rows.push(r);
|
|
27393
|
-
remaining -= 1;
|
|
27394
|
-
if (remaining === 0) break;
|
|
27395
|
-
}
|
|
27396
|
-
return rows;
|
|
27397
|
-
}
|
|
27398
27396
|
/**
|
|
27399
27397
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27400
27398
|
*
|
|
@@ -27421,6 +27419,33 @@ var SqliteFindingsRepository = class {
|
|
|
27421
27419
|
yield toFlatFindingRow(r);
|
|
27422
27420
|
}
|
|
27423
27421
|
}
|
|
27422
|
+
/**
|
|
27423
|
+
* One finding by its own id, or null when no such row exists.
|
|
27424
|
+
*
|
|
27425
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
27426
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
27427
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
27428
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
27429
|
+
* older than anything a first page holds.
|
|
27430
|
+
*
|
|
27431
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
27432
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
27433
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
27434
|
+
* worse than showing it.
|
|
27435
|
+
*
|
|
27436
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
27437
|
+
* type should the list select?" and "what does the drawer show?".
|
|
27438
|
+
*/
|
|
27439
|
+
findingInstance(id) {
|
|
27440
|
+
const row = this.db.prepare(
|
|
27441
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27442
|
+
FROM inspection_findings f
|
|
27443
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
27444
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27445
|
+
WHERE f.id = ?`
|
|
27446
|
+
).get(id);
|
|
27447
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
27448
|
+
}
|
|
27424
27449
|
/**
|
|
27425
27450
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27426
27451
|
* joined to its event and definition, newest first.
|
|
@@ -27454,17 +27479,7 @@ var SqliteFindingsRepository = class {
|
|
|
27454
27479
|
conditions.push("e.started_at >= ?");
|
|
27455
27480
|
params.push(isoToEpochMillis(scope.from));
|
|
27456
27481
|
}
|
|
27457
|
-
const sql = `SELECT
|
|
27458
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27459
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27460
|
-
e.started_at AS occurred_at,
|
|
27461
|
-
e.source_tool AS source_tool,
|
|
27462
|
-
e.repo AS repo,
|
|
27463
|
-
e.file_path AS file,
|
|
27464
|
-
e.tool_name AS tool_name,
|
|
27465
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27466
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27467
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
27482
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27468
27483
|
FROM audit_events e
|
|
27469
27484
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27470
27485
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27478,6 +27493,26 @@ var SqliteFindingsRepository = class {
|
|
|
27478
27493
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27479
27494
|
const rows = this.db.prepare(
|
|
27480
27495
|
`SELECT rule_id,
|
|
27496
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
27497
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
27498
|
+
-- in an aggregate query, every bare column takes its value from
|
|
27499
|
+
-- the row that produced the extremum. So these are the severity
|
|
27500
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
27501
|
+
-- is what the row-based build they replaced read off its first
|
|
27502
|
+
-- (newest-first) row.
|
|
27503
|
+
--
|
|
27504
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
27505
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
27506
|
+
-- mints a new row), so a rule whose severity moved between
|
|
27507
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
27508
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
27509
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
27510
|
+
-- filter, the facet counts and the primary sort key.
|
|
27511
|
+
--
|
|
27512
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
27513
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
27514
|
+
severity,
|
|
27515
|
+
category,
|
|
27481
27516
|
sum(tuple_count) AS instance_count,
|
|
27482
27517
|
max(latest_at) AS latest_at,
|
|
27483
27518
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27488,6 +27523,14 @@ var SqliteFindingsRepository = class {
|
|
|
27488
27523
|
group_concat(tool_names) AS tool_names
|
|
27489
27524
|
FROM (
|
|
27490
27525
|
SELECT d.rule_id AS rule_id,
|
|
27526
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
27527
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
27528
|
+
-- these are grouped on below and resolved to the newest
|
|
27529
|
+
-- firing version by the outer query's bare-column select.
|
|
27530
|
+
-- They ride the aggregate because the type build has no rows
|
|
27531
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
27532
|
+
d.severity AS severity,
|
|
27533
|
+
d.category AS category,
|
|
27491
27534
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27492
27535
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27493
27536
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27502,7 +27545,7 @@ var SqliteFindingsRepository = class {
|
|
|
27502
27545
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27503
27546
|
ON latest.finding_key = f.finding_key
|
|
27504
27547
|
${scope.predicate}
|
|
27505
|
-
GROUP BY d.rule_id, status_tuple
|
|
27548
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27506
27549
|
)
|
|
27507
27550
|
GROUP BY rule_id`
|
|
27508
27551
|
).all(scope.params);
|
|
@@ -27511,6 +27554,8 @@ var SqliteFindingsRepository = class {
|
|
|
27511
27554
|
r.rule_id,
|
|
27512
27555
|
{
|
|
27513
27556
|
instanceCount: r.instance_count,
|
|
27557
|
+
severity: r.severity,
|
|
27558
|
+
category: r.category,
|
|
27514
27559
|
sourceTools: splitConcat(r.source_tools),
|
|
27515
27560
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27516
27561
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27527,7 +27572,7 @@ var SqliteFindingsRepository = class {
|
|
|
27527
27572
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27528
27573
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27529
27574
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27530
|
-
// Left undefined (not '') when unfetched, so
|
|
27575
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27531
27576
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27532
27577
|
// and skip priming a haystack nothing will read.
|
|
27533
27578
|
...withSearchText ? {
|
|
@@ -27679,6 +27724,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
27679
27724
|
this.markOwedStmt = db.prepare(
|
|
27680
27725
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27681
27726
|
);
|
|
27727
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27728
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
27729
|
+
WHERE synced_at IS NULL
|
|
27730
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27731
|
+
AND started_at < :before`
|
|
27732
|
+
);
|
|
27682
27733
|
this.stampStmt = db.prepare(
|
|
27683
27734
|
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27684
27735
|
);
|
|
@@ -27727,7 +27778,9 @@ var SqliteHistorySyncRepository = class {
|
|
|
27727
27778
|
);
|
|
27728
27779
|
this.disownCapturesStmt = db.prepare(
|
|
27729
27780
|
`UPDATE audit_events SET outbox_owed = NULL
|
|
27730
|
-
WHERE outbox_owed IS NOT NULL
|
|
27781
|
+
WHERE outbox_owed IS NOT NULL
|
|
27782
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27783
|
+
AND started_at < :attachedAt`
|
|
27731
27784
|
);
|
|
27732
27785
|
this.rearmStmt = db.prepare(
|
|
27733
27786
|
`UPDATE audit_events SET synced_at = NULL
|
|
@@ -27803,6 +27856,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27803
27856
|
freezeBoundaryStmt;
|
|
27804
27857
|
captureRowsStmt;
|
|
27805
27858
|
markOwedStmt;
|
|
27859
|
+
markCaptureBacklogOwedStmt;
|
|
27806
27860
|
captureSkipCountStmt;
|
|
27807
27861
|
disownCapturesStmt;
|
|
27808
27862
|
partitionStmt;
|
|
@@ -27866,6 +27920,23 @@ var SqliteHistorySyncRepository = class {
|
|
|
27866
27920
|
markCaptureOwed(id) {
|
|
27867
27921
|
this.markOwedStmt.run({ id });
|
|
27868
27922
|
}
|
|
27923
|
+
/**
|
|
27924
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
27925
|
+
*
|
|
27926
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
27927
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27928
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
27929
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27930
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27931
|
+
* later re-attach or key rotation might widen it to.
|
|
27932
|
+
*
|
|
27933
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27934
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27935
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27936
|
+
*/
|
|
27937
|
+
markCaptureBacklogOwed(before) {
|
|
27938
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27939
|
+
}
|
|
27869
27940
|
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27870
27941
|
markSynced(ids, atMs) {
|
|
27871
27942
|
this.stampAll(ids, atMs);
|
|
@@ -27982,15 +28053,42 @@ var SqliteHistorySyncRepository = class {
|
|
|
27982
28053
|
*
|
|
27983
28054
|
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
27984
28055
|
* machine has just left are undelivered as far as the new one is concerned.
|
|
27985
|
-
* All
|
|
27986
|
-
* attributed to the wrong deployment,
|
|
28056
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
28057
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
28058
|
+
* a disown with no re-mark to follow it.
|
|
27987
28059
|
*
|
|
27988
28060
|
* The boundary is written HERE and only here, which is what freezes it: a
|
|
27989
28061
|
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
27990
28062
|
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
27991
28063
|
* the live path has since delivered.
|
|
28064
|
+
*
|
|
28065
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
28066
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
28067
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
28068
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
28069
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
28070
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
28071
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
28072
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
28073
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
28074
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
28075
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
28076
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
28077
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
28078
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
28079
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
28080
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
28081
|
+
*
|
|
28082
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
28083
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
28084
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
28085
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
28086
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
28087
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
28088
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
28089
|
+
* transaction above.
|
|
27992
28090
|
*/
|
|
27993
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
28091
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
27994
28092
|
this.ensureRowStmt.run();
|
|
27995
28093
|
withTransaction(
|
|
27996
28094
|
this.db,
|
|
@@ -27998,7 +28096,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27998
28096
|
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
27999
28097
|
this.rearmStmt.run();
|
|
28000
28098
|
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
28001
|
-
this.disownCapturesStmt.run();
|
|
28099
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
28100
|
+
}
|
|
28101
|
+
if (backfillCapturesBefore !== void 0) {
|
|
28102
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
28002
28103
|
}
|
|
28003
28104
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
28004
28105
|
},
|
|
@@ -28275,7 +28376,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28275
28376
|
}
|
|
28276
28377
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28277
28378
|
}
|
|
28278
|
-
|
|
28379
|
+
var testOnlyManagedPaths = null;
|
|
28380
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28279
28381
|
for (const path of paths) {
|
|
28280
28382
|
let text;
|
|
28281
28383
|
try {
|
|
@@ -30755,7 +30857,7 @@ function toUtcDateString(ms) {
|
|
|
30755
30857
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30756
30858
|
}
|
|
30757
30859
|
function isTimeseriesSeverity(s) {
|
|
30758
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
30860
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30759
30861
|
}
|
|
30760
30862
|
var SqliteSecurityRepository = class {
|
|
30761
30863
|
constructor(db, now = () => Date.now()) {
|
|
@@ -30884,12 +30986,16 @@ var SqliteSecurityRepository = class {
|
|
|
30884
30986
|
const now = this.now();
|
|
30885
30987
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
30886
30988
|
const rows = this.findingsInRange(windowStart, now);
|
|
30887
|
-
const points = Array.from(
|
|
30888
|
-
|
|
30889
|
-
|
|
30890
|
-
|
|
30891
|
-
|
|
30892
|
-
|
|
30989
|
+
const points = Array.from(
|
|
30990
|
+
{ length: numBuckets },
|
|
30991
|
+
(_, i) => ({
|
|
30992
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
30993
|
+
critical: 0,
|
|
30994
|
+
high: 0,
|
|
30995
|
+
medium: 0,
|
|
30996
|
+
low: 0
|
|
30997
|
+
})
|
|
30998
|
+
);
|
|
30893
30999
|
for (const r of rows) {
|
|
30894
31000
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
30895
31001
|
const bucket = points[idx];
|
|
@@ -31107,6 +31213,7 @@ var SqliteSecurityRepository = class {
|
|
|
31107
31213
|
`SELECT f.finding_key AS finding_key,
|
|
31108
31214
|
d.rule_id AS rule_id,
|
|
31109
31215
|
d.severity AS severity,
|
|
31216
|
+
e.repo AS repo,
|
|
31110
31217
|
e.file_path AS path,
|
|
31111
31218
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31112
31219
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31126,6 +31233,7 @@ var SqliteSecurityRepository = class {
|
|
|
31126
31233
|
const items = rows.map((r) => ({
|
|
31127
31234
|
findingKey: r.finding_key,
|
|
31128
31235
|
ruleId: r.rule_id,
|
|
31236
|
+
repo: r.repo ?? "",
|
|
31129
31237
|
severity: r.severity,
|
|
31130
31238
|
path: r.path ?? "",
|
|
31131
31239
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31135,13 +31243,66 @@ var SqliteSecurityRepository = class {
|
|
|
31135
31243
|
}));
|
|
31136
31244
|
return Promise.resolve({ items });
|
|
31137
31245
|
}
|
|
31246
|
+
/**
|
|
31247
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31248
|
+
*
|
|
31249
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31250
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31251
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31252
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31253
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31254
|
+
*
|
|
31255
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31256
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31257
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31258
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31259
|
+
* The two answer different questions and only this one has to match a link.
|
|
31260
|
+
*
|
|
31261
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31262
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31263
|
+
*/
|
|
31264
|
+
recommendationInputs() {
|
|
31265
|
+
const rows = allRows(
|
|
31266
|
+
this.db.prepare(
|
|
31267
|
+
`SELECT d.rule_id AS rule_id,
|
|
31268
|
+
d.category AS category,
|
|
31269
|
+
d.severity AS severity,
|
|
31270
|
+
COUNT(*) AS count
|
|
31271
|
+
FROM inspection_findings f
|
|
31272
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31273
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31274
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31275
|
+
ON latest.finding_key = f.finding_key
|
|
31276
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31277
|
+
AND e.event_type = 'code_change'
|
|
31278
|
+
AND (
|
|
31279
|
+
f.finding_key IS NULL
|
|
31280
|
+
OR latest.status IS NULL
|
|
31281
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31282
|
+
)
|
|
31283
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31284
|
+
)
|
|
31285
|
+
);
|
|
31286
|
+
return Promise.resolve(
|
|
31287
|
+
rows.map((r) => ({
|
|
31288
|
+
ruleId: r.rule_id,
|
|
31289
|
+
category: r.category,
|
|
31290
|
+
severity: r.severity,
|
|
31291
|
+
count: r.count
|
|
31292
|
+
}))
|
|
31293
|
+
);
|
|
31294
|
+
}
|
|
31138
31295
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31139
31296
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31140
31297
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31141
31298
|
findingsInRange(fromMs, toMs) {
|
|
31142
31299
|
const rows = allRows(
|
|
31143
31300
|
this.db.prepare(
|
|
31144
|
-
`
|
|
31301
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31302
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31303
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31304
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31305
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31145
31306
|
FROM inspection_findings f
|
|
31146
31307
|
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31147
31308
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -31154,7 +31315,9 @@ var SqliteSecurityRepository = class {
|
|
|
31154
31315
|
return rows.map((r) => ({
|
|
31155
31316
|
occurredAt: r.occurred_at,
|
|
31156
31317
|
severity: r.severity,
|
|
31157
|
-
actionTaken: r.action_taken
|
|
31318
|
+
actionTaken: r.action_taken,
|
|
31319
|
+
ruleId: r.rule_id,
|
|
31320
|
+
category: r.category
|
|
31158
31321
|
}));
|
|
31159
31322
|
}
|
|
31160
31323
|
};
|
|
@@ -32324,8 +32487,45 @@ function openLocalDatabase(dir) {
|
|
|
32324
32487
|
};
|
|
32325
32488
|
}
|
|
32326
32489
|
|
|
32327
|
-
// ../../packages/persistence/src/
|
|
32490
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32328
32491
|
import { createHash as createHash3 } from "crypto";
|
|
32492
|
+
function hashProjectKey(projectKey) {
|
|
32493
|
+
return createHash3("sha256").update(projectKey, "utf8").digest("hex");
|
|
32494
|
+
}
|
|
32495
|
+
function toIngestHit(hit) {
|
|
32496
|
+
return {
|
|
32497
|
+
host: hit.host,
|
|
32498
|
+
kind: hit.kind,
|
|
32499
|
+
name: hit.name,
|
|
32500
|
+
category: hit.category,
|
|
32501
|
+
trust: hit.trust,
|
|
32502
|
+
network: hit.network,
|
|
32503
|
+
method: hit.method,
|
|
32504
|
+
transport: hit.transport,
|
|
32505
|
+
url: hit.url,
|
|
32506
|
+
template: hit.template,
|
|
32507
|
+
dataClass: hit.dataClass,
|
|
32508
|
+
site: {
|
|
32509
|
+
file: hit.site.file,
|
|
32510
|
+
line: hit.site.line,
|
|
32511
|
+
dynamic: hit.site.dynamic,
|
|
32512
|
+
vendored: hit.site.vendored
|
|
32513
|
+
}
|
|
32514
|
+
};
|
|
32515
|
+
}
|
|
32516
|
+
function toEgressIngestRequest(input2) {
|
|
32517
|
+
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
32518
|
+
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
32519
|
+
return {
|
|
32520
|
+
projectKey: hashProjectKey(input2.projectKey),
|
|
32521
|
+
project: input2.project,
|
|
32522
|
+
reconcile,
|
|
32523
|
+
hits: hits.map(toIngestHit)
|
|
32524
|
+
};
|
|
32525
|
+
}
|
|
32526
|
+
|
|
32527
|
+
// ../../packages/persistence/src/finding-key.ts
|
|
32528
|
+
import { createHash as createHash4 } from "crypto";
|
|
32329
32529
|
|
|
32330
32530
|
// ../../packages/persistence/src/fingerprint.ts
|
|
32331
32531
|
import { createHmac, randomBytes } from "crypto";
|
|
@@ -32366,14 +32566,18 @@ function readFingerprintKey(dataDir2) {
|
|
|
32366
32566
|
return parseKeyFile(raw);
|
|
32367
32567
|
}
|
|
32368
32568
|
|
|
32369
|
-
// ../../packages/persistence/src/history-
|
|
32569
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
32370
32570
|
import { existsSync as existsSync4 } from "fs";
|
|
32371
32571
|
import { join as join9 } from "path";
|
|
32572
|
+
|
|
32573
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
32574
|
+
import { existsSync as existsSync5 } from "fs";
|
|
32575
|
+
import { join as join10 } from "path";
|
|
32372
32576
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32373
32577
|
|
|
32374
32578
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32375
|
-
import { existsSync as
|
|
32376
|
-
import { dirname as dirname3, join as
|
|
32579
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32580
|
+
import { dirname as dirname3, join as join11, resolve } from "path";
|
|
32377
32581
|
|
|
32378
32582
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32379
32583
|
import {
|
|
@@ -32388,19 +32592,19 @@ import {
|
|
|
32388
32592
|
import { execFileSync } from "child_process";
|
|
32389
32593
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32390
32594
|
import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
32391
|
-
import { join as
|
|
32595
|
+
import { join as join12 } from "path";
|
|
32392
32596
|
|
|
32393
32597
|
// ../../packages/persistence/src/vault/vault.ts
|
|
32394
32598
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
32395
32599
|
|
|
32396
32600
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
32397
|
-
import { existsSync as
|
|
32398
|
-
import { join as
|
|
32601
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
32602
|
+
import { join as join13 } from "path";
|
|
32399
32603
|
var MARKER = "warn-era-capped";
|
|
32400
32604
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
32401
32605
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
32402
|
-
const marker =
|
|
32403
|
-
if (
|
|
32606
|
+
const marker = join13(dataDir2, MARKER);
|
|
32607
|
+
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
32404
32608
|
const capped = db.policies.capCategoryActions();
|
|
32405
32609
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
32406
32610
|
`, { mode: DATA_FILE_MODE });
|
|
@@ -32459,8 +32663,8 @@ function resolveProvider() {
|
|
|
32459
32663
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
32460
32664
|
try {
|
|
32461
32665
|
ensureLayoutDirSync(base);
|
|
32462
|
-
const settingsFile =
|
|
32463
|
-
if (
|
|
32666
|
+
const settingsFile = join14(settingsDir(base), "settings.json");
|
|
32667
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
32464
32668
|
} catch {
|
|
32465
32669
|
}
|
|
32466
32670
|
migrateLegacyLayout(base);
|
|
@@ -32485,7 +32689,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
32485
32689
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
32486
32690
|
import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
32487
32691
|
import { homedir as homedir2 } from "os";
|
|
32488
|
-
import { basename as basename3, join as
|
|
32692
|
+
import { basename as basename3, join as join16 } from "path";
|
|
32489
32693
|
|
|
32490
32694
|
// ../../packages/detections/src/egress/registry.ts
|
|
32491
32695
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -35529,8 +35733,8 @@ function scanText(text, ruleVersions) {
|
|
|
35529
35733
|
}
|
|
35530
35734
|
|
|
35531
35735
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
35532
|
-
import { existsSync as
|
|
35533
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
35736
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
|
|
35737
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join15, sep as sep2 } from "path";
|
|
35534
35738
|
function resolveRepoIdentity(cwd) {
|
|
35535
35739
|
try {
|
|
35536
35740
|
const root = findGitRoot(cwd);
|
|
@@ -35552,32 +35756,32 @@ function resolveRepoIdentity(cwd) {
|
|
|
35552
35756
|
function findGitRoot(start) {
|
|
35553
35757
|
let dir = start;
|
|
35554
35758
|
for (; ; ) {
|
|
35555
|
-
if (
|
|
35759
|
+
if (existsSync9(join15(dir, ".git"))) return dir;
|
|
35556
35760
|
const parent = dirname4(dir);
|
|
35557
35761
|
if (parent === dir) return void 0;
|
|
35558
35762
|
dir = parent;
|
|
35559
35763
|
}
|
|
35560
35764
|
}
|
|
35561
35765
|
function resolveGitContext(root) {
|
|
35562
|
-
const dotGit =
|
|
35766
|
+
const dotGit = join15(root, ".git");
|
|
35563
35767
|
try {
|
|
35564
35768
|
if (statSync6(dotGit).isDirectory()) {
|
|
35565
|
-
return { configPath:
|
|
35769
|
+
return { configPath: join15(dotGit, "config"), headRoot: root };
|
|
35566
35770
|
}
|
|
35567
35771
|
} catch {
|
|
35568
35772
|
return void 0;
|
|
35569
35773
|
}
|
|
35570
35774
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
35571
35775
|
if (!target) return void 0;
|
|
35572
|
-
const gitdir = isAbsolute(target) ? target :
|
|
35573
|
-
if (
|
|
35574
|
-
return { configPath:
|
|
35776
|
+
const gitdir = isAbsolute(target) ? target : join15(root, target);
|
|
35777
|
+
if (existsSync9(join15(gitdir, "config"))) {
|
|
35778
|
+
return { configPath: join15(gitdir, "config"), headRoot: root };
|
|
35575
35779
|
}
|
|
35576
|
-
const commonRaw = safeRead(
|
|
35780
|
+
const commonRaw = safeRead(join15(gitdir, "commondir"))?.trim();
|
|
35577
35781
|
if (!commonRaw) return void 0;
|
|
35578
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
35782
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join15(gitdir, commonRaw);
|
|
35579
35783
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
35580
|
-
return { configPath:
|
|
35784
|
+
return { configPath: join15(commonGitDir, "config"), headRoot };
|
|
35581
35785
|
}
|
|
35582
35786
|
function safeRead(path) {
|
|
35583
35787
|
try {
|
|
@@ -35619,17 +35823,52 @@ function slugFromUrl(url2) {
|
|
|
35619
35823
|
}
|
|
35620
35824
|
|
|
35621
35825
|
// ../../packages/plugin-sdk/src/events.ts
|
|
35622
|
-
import { createHash as
|
|
35826
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
35623
35827
|
|
|
35624
35828
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
35625
|
-
import { existsSync as
|
|
35829
|
+
import { existsSync as existsSync10 } from "fs";
|
|
35626
35830
|
import { fileURLToPath } from "url";
|
|
35627
35831
|
import { Worker } from "worker_threads";
|
|
35628
35832
|
|
|
35833
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
35834
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
35835
|
+
import { join as join18 } from "path";
|
|
35836
|
+
|
|
35837
|
+
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
35838
|
+
import {
|
|
35839
|
+
closeSync as closeSync2,
|
|
35840
|
+
fstatSync,
|
|
35841
|
+
mkdirSync as mkdirSync2,
|
|
35842
|
+
openSync as openSync2,
|
|
35843
|
+
readFileSync as readFileSync10,
|
|
35844
|
+
readSync,
|
|
35845
|
+
writeFileSync as writeFileSync5
|
|
35846
|
+
} from "fs";
|
|
35847
|
+
import { join as join17 } from "path";
|
|
35848
|
+
var TAIL_BYTES = 256 * 1024;
|
|
35849
|
+
|
|
35850
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
35851
|
+
var HOST_FEATURE = {
|
|
35852
|
+
ModelSwitch: "model-switch",
|
|
35853
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
35854
|
+
};
|
|
35855
|
+
var HOST_FLOORS = {
|
|
35856
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
35857
|
+
label: "model-switch protection",
|
|
35858
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
35859
|
+
since: "2.1.251"
|
|
35860
|
+
},
|
|
35861
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
35862
|
+
label: "vault pointer display",
|
|
35863
|
+
hookEvents: ["MessageDisplay"],
|
|
35864
|
+
since: "2.1.152"
|
|
35865
|
+
}
|
|
35866
|
+
};
|
|
35867
|
+
|
|
35629
35868
|
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
35630
35869
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
35631
|
-
import { readFileSync as
|
|
35632
|
-
import { join as
|
|
35870
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
35871
|
+
import { join as join19 } from "path";
|
|
35633
35872
|
|
|
35634
35873
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
35635
35874
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
@@ -35660,30 +35899,17 @@ function resolveInventoryContext(input2) {
|
|
|
35660
35899
|
return ctx;
|
|
35661
35900
|
}
|
|
35662
35901
|
|
|
35663
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
35664
|
-
import {
|
|
35665
|
-
closeSync as closeSync2,
|
|
35666
|
-
fstatSync,
|
|
35667
|
-
mkdirSync as mkdirSync2,
|
|
35668
|
-
openSync as openSync2,
|
|
35669
|
-
readFileSync as readFileSync11,
|
|
35670
|
-
readSync,
|
|
35671
|
-
writeFileSync as writeFileSync5
|
|
35672
|
-
} from "fs";
|
|
35673
|
-
import { join as join17 } from "path";
|
|
35674
|
-
var TAIL_BYTES = 256 * 1024;
|
|
35675
|
-
|
|
35676
35902
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
35677
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
35678
|
-
import { join as
|
|
35903
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
35904
|
+
import { join as join20 } from "path";
|
|
35679
35905
|
|
|
35680
35906
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
35681
35907
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
35682
35908
|
import { basename as basename4, dirname as dirname5, sep as sep3 } from "path";
|
|
35683
35909
|
|
|
35684
35910
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
35685
|
-
import { existsSync as
|
|
35686
|
-
import { basename as basename5, join as
|
|
35911
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
35912
|
+
import { basename as basename5, join as join21 } from "path";
|
|
35687
35913
|
|
|
35688
35914
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
35689
35915
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -35729,44 +35955,7 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
35729
35955
|
|
|
35730
35956
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
35731
35957
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
35732
|
-
import { join as
|
|
35733
|
-
|
|
35734
|
-
// ../../packages/plugin-runtime/src/attached/egress-wire.ts
|
|
35735
|
-
import { createHash as createHash5 } from "crypto";
|
|
35736
|
-
function hashProjectKey(projectKey) {
|
|
35737
|
-
return createHash5("sha256").update(projectKey, "utf8").digest("hex");
|
|
35738
|
-
}
|
|
35739
|
-
function toIngestHit(hit) {
|
|
35740
|
-
return {
|
|
35741
|
-
host: hit.host,
|
|
35742
|
-
kind: hit.kind,
|
|
35743
|
-
name: hit.name,
|
|
35744
|
-
category: hit.category,
|
|
35745
|
-
trust: hit.trust,
|
|
35746
|
-
network: hit.network,
|
|
35747
|
-
method: hit.method,
|
|
35748
|
-
transport: hit.transport,
|
|
35749
|
-
url: hit.url,
|
|
35750
|
-
template: hit.template,
|
|
35751
|
-
dataClass: hit.dataClass,
|
|
35752
|
-
site: {
|
|
35753
|
-
file: hit.site.file,
|
|
35754
|
-
line: hit.site.line,
|
|
35755
|
-
dynamic: hit.site.dynamic,
|
|
35756
|
-
vendored: hit.site.vendored
|
|
35757
|
-
}
|
|
35758
|
-
};
|
|
35759
|
-
}
|
|
35760
|
-
function toEgressIngestRequest(input2) {
|
|
35761
|
-
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
35762
|
-
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
35763
|
-
return {
|
|
35764
|
-
projectKey: hashProjectKey(input2.projectKey),
|
|
35765
|
-
project: input2.project,
|
|
35766
|
-
reconcile,
|
|
35767
|
-
hits: hits.map(toIngestHit)
|
|
35768
|
-
};
|
|
35769
|
-
}
|
|
35958
|
+
import { join as join22 } from "path";
|
|
35770
35959
|
|
|
35771
35960
|
// ../../packages/remote/src/http.ts
|
|
35772
35961
|
import { request as httpRequest } from "http";
|
|
@@ -36047,6 +36236,7 @@ function createRemoteClient(options) {
|
|
|
36047
36236
|
url: url2(ROUTES.shares),
|
|
36048
36237
|
body: JSON.stringify(validated.data)
|
|
36049
36238
|
});
|
|
36239
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
36050
36240
|
okBody(response);
|
|
36051
36241
|
},
|
|
36052
36242
|
async pollCommand() {
|
|
@@ -36069,19 +36259,51 @@ function createRemoteClient(options) {
|
|
|
36069
36259
|
};
|
|
36070
36260
|
}
|
|
36071
36261
|
|
|
36072
|
-
// ../../packages/
|
|
36262
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
36073
36263
|
function statusOf(err) {
|
|
36074
36264
|
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
36075
36265
|
const { status } = err;
|
|
36076
36266
|
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
36077
36267
|
return status >= 100 && status <= 599 ? status : null;
|
|
36078
36268
|
}
|
|
36079
|
-
function
|
|
36080
|
-
|
|
36269
|
+
function nameOf(err) {
|
|
36270
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
36271
|
+
return typeof err.name === "string" ? err.name : null;
|
|
36272
|
+
}
|
|
36273
|
+
function classifyRemoteFailure(err) {
|
|
36274
|
+
switch (nameOf(err)) {
|
|
36275
|
+
case "RemoteRouteAbsent":
|
|
36276
|
+
return "route-absent";
|
|
36277
|
+
case "RemoteRequestInvalid":
|
|
36278
|
+
return "invalid-request";
|
|
36279
|
+
case "RemoteResponseInvalid":
|
|
36280
|
+
return "rejected";
|
|
36281
|
+
default:
|
|
36282
|
+
break;
|
|
36283
|
+
}
|
|
36284
|
+
const status = statusOf(err);
|
|
36285
|
+
if (status === null) return "unreachable";
|
|
36286
|
+
switch (status) {
|
|
36081
36287
|
case 401:
|
|
36082
36288
|
return "unauthorized";
|
|
36083
36289
|
case 403:
|
|
36084
36290
|
return "forbidden";
|
|
36291
|
+
case 429:
|
|
36292
|
+
return "unreachable";
|
|
36293
|
+
case 404:
|
|
36294
|
+
return "unreachable";
|
|
36295
|
+
default:
|
|
36296
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
36297
|
+
}
|
|
36298
|
+
}
|
|
36299
|
+
|
|
36300
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
36301
|
+
function classifyFailure(err) {
|
|
36302
|
+
switch (classifyRemoteFailure(err)) {
|
|
36303
|
+
case "unauthorized":
|
|
36304
|
+
return "unauthorized";
|
|
36305
|
+
case "forbidden":
|
|
36306
|
+
return "forbidden";
|
|
36085
36307
|
default:
|
|
36086
36308
|
return "unreachable";
|
|
36087
36309
|
}
|
|
@@ -36103,11 +36325,11 @@ function withTimeout(promise2, ms) {
|
|
|
36103
36325
|
}
|
|
36104
36326
|
|
|
36105
36327
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
36106
|
-
import { readFileSync as
|
|
36107
|
-
import { join as
|
|
36328
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
36329
|
+
import { join as join23 } from "path";
|
|
36108
36330
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
36109
36331
|
function forwardDropsPath(dataDir2) {
|
|
36110
|
-
return
|
|
36332
|
+
return join23(dataDir2, FORWARD_DROPS_FILENAME);
|
|
36111
36333
|
}
|
|
36112
36334
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
36113
36335
|
if (count <= 0) return;
|
|
@@ -36125,7 +36347,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
36125
36347
|
}
|
|
36126
36348
|
function readForwardDrops(dataDir2) {
|
|
36127
36349
|
try {
|
|
36128
|
-
const parsed2 = JSON.parse(
|
|
36350
|
+
const parsed2 = JSON.parse(readFileSync14(forwardDropsPath(dataDir2), "utf8"));
|
|
36129
36351
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
36130
36352
|
const record2 = parsed2;
|
|
36131
36353
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -36143,9 +36365,9 @@ function readForwardDrops(dataDir2) {
|
|
|
36143
36365
|
|
|
36144
36366
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
36145
36367
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
36146
|
-
import { readFileSync as
|
|
36368
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
36147
36369
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
36148
|
-
import { join as
|
|
36370
|
+
import { join as join24 } from "path";
|
|
36149
36371
|
function isInvalidRequest(err) {
|
|
36150
36372
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
36151
36373
|
}
|
|
@@ -36183,7 +36405,7 @@ function parseBreakerState(raw, nowMs) {
|
|
|
36183
36405
|
}
|
|
36184
36406
|
function createForwardPolicy(deps) {
|
|
36185
36407
|
const now = deps.now ?? (() => Date.now());
|
|
36186
|
-
const file2 =
|
|
36408
|
+
const file2 = join24(deps.dir, STATE_FILENAME);
|
|
36187
36409
|
let state = null;
|
|
36188
36410
|
let loading = null;
|
|
36189
36411
|
async function readState() {
|
|
@@ -36905,8 +37127,8 @@ function toolAuditEvent(input2) {
|
|
|
36905
37127
|
}
|
|
36906
37128
|
|
|
36907
37129
|
// ../../packages/plugin-runtime/src/attached/history-state.ts
|
|
36908
|
-
import { readFileSync as
|
|
36909
|
-
import { join as
|
|
37130
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
37131
|
+
import { join as join25 } from "path";
|
|
36910
37132
|
|
|
36911
37133
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
36912
37134
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -36923,14 +37145,14 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
36923
37145
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
36924
37146
|
|
|
36925
37147
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
36926
|
-
import { readFileSync as
|
|
37148
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
36927
37149
|
var manifestBuildCache = /* @__PURE__ */ new Map();
|
|
36928
37150
|
function readManifestBuild(manifestUrl, packageName) {
|
|
36929
37151
|
const key = manifestUrl.href;
|
|
36930
37152
|
if (!manifestBuildCache.has(key)) {
|
|
36931
37153
|
let build;
|
|
36932
37154
|
try {
|
|
36933
|
-
const manifest = JSON.parse(
|
|
37155
|
+
const manifest = JSON.parse(readFileSync17(manifestUrl, "utf8"));
|
|
36934
37156
|
build = typeof manifest.version === "string" && manifest.version.length > 0 ? { package: packageName, version: manifest.version } : void 0;
|
|
36935
37157
|
} catch {
|
|
36936
37158
|
build = void 0;
|
|
@@ -36957,7 +37179,7 @@ function createPluginBlock(build, policyStore) {
|
|
|
36957
37179
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
36958
37180
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
36959
37181
|
import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
36960
|
-
import { join as
|
|
37182
|
+
import { join as join26 } from "path";
|
|
36961
37183
|
|
|
36962
37184
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
36963
37185
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -36981,7 +37203,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
36981
37203
|
|
|
36982
37204
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
36983
37205
|
function createPolicyStore(dir = dataDir()) {
|
|
36984
|
-
const file2 =
|
|
37206
|
+
const file2 = join26(dir, "policy-cache.json");
|
|
36985
37207
|
async function read() {
|
|
36986
37208
|
try {
|
|
36987
37209
|
const raw = await readFile2(file2, "utf8");
|
|
@@ -37212,11 +37434,11 @@ function readStorePosture(dbPath2) {
|
|
|
37212
37434
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
37213
37435
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
37214
37436
|
import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
37215
|
-
import { join as
|
|
37437
|
+
import { join as join27 } from "path";
|
|
37216
37438
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
37217
37439
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
37218
|
-
const file2 =
|
|
37219
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
37440
|
+
const file2 = join27(dir, "posture-state.json");
|
|
37441
|
+
const legacyFile = legacyDir === void 0 ? null : join27(legacyDir, "posture-state.json");
|
|
37220
37442
|
async function persist(state) {
|
|
37221
37443
|
await ensureDataDir(dir);
|
|
37222
37444
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -37284,8 +37506,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
37284
37506
|
}
|
|
37285
37507
|
|
|
37286
37508
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
37287
|
-
import { readFileSync as
|
|
37288
|
-
import { join as
|
|
37509
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
37510
|
+
import { join as join28 } from "path";
|
|
37289
37511
|
|
|
37290
37512
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
37291
37513
|
var REFUSAL_LINES = {
|
|
@@ -37769,13 +37991,13 @@ import {
|
|
|
37769
37991
|
fstatSync as fstatSync2,
|
|
37770
37992
|
mkdirSync as mkdirSync5,
|
|
37771
37993
|
openSync as openSync3,
|
|
37772
|
-
readFileSync as
|
|
37994
|
+
readFileSync as readFileSync19,
|
|
37773
37995
|
readSync as readSync2,
|
|
37774
37996
|
writeFileSync as writeFileSync8
|
|
37775
37997
|
} from "fs";
|
|
37776
|
-
import { join as
|
|
37998
|
+
import { join as join29 } from "path";
|
|
37777
37999
|
function offsetsDir(dataDir2) {
|
|
37778
|
-
return
|
|
38000
|
+
return join29(dataDir2, "usage-offsets");
|
|
37779
38001
|
}
|
|
37780
38002
|
var SAFE_SESSION_ID = /^[A-Za-z0-9._-]+$/;
|
|
37781
38003
|
function safeSessionId(sessionId) {
|
|
@@ -37785,11 +38007,11 @@ function safeSessionId(sessionId) {
|
|
|
37785
38007
|
return createHash7("sha256").update(sessionId).digest("hex");
|
|
37786
38008
|
}
|
|
37787
38009
|
function offsetPath(dataDir2, sessionId) {
|
|
37788
|
-
return
|
|
38010
|
+
return join29(offsetsDir(dataDir2), safeSessionId(sessionId));
|
|
37789
38011
|
}
|
|
37790
38012
|
function readOffset(dataDir2, sessionId) {
|
|
37791
38013
|
try {
|
|
37792
|
-
const raw =
|
|
38014
|
+
const raw = readFileSync19(offsetPath(dataDir2, sessionId), "utf8");
|
|
37793
38015
|
const parsed2 = JSON.parse(raw);
|
|
37794
38016
|
if (typeof parsed2 === "object" && parsed2 !== null) {
|
|
37795
38017
|
const rec = parsed2;
|
|
@@ -37847,9 +38069,9 @@ function readTail(transcriptPath, startOffset) {
|
|
|
37847
38069
|
}
|
|
37848
38070
|
|
|
37849
38071
|
// src/history/transcripts.ts
|
|
37850
|
-
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as
|
|
38072
|
+
import { closeSync as closeSync4, openSync as openSync4, readdirSync as readdirSync5, readFileSync as readFileSync20, readSync as readSync3, statSync as statSync10 } from "fs";
|
|
37851
38073
|
import { homedir as homedir3 } from "os";
|
|
37852
|
-
import { join as
|
|
38074
|
+
import { join as join30 } from "path";
|
|
37853
38075
|
function isRecord(value) {
|
|
37854
38076
|
return typeof value === "object" && value !== null;
|
|
37855
38077
|
}
|