@akasecurity/ai-tc-claude-code 0.9.10 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/package.json +5 -5
- package/scripts/apply-suppressions.js +622 -430
- package/scripts/backfill.js +732 -504
- package/scripts/filescan.js +726 -496
- package/scripts/firstrun.js +772 -516
- package/scripts/history-sync.js +611 -418
- package/scripts/intro.js +240 -90
- package/scripts/message-display.js +604 -412
- package/scripts/onboard.js +601 -408
- package/scripts/post-model-switch.js +258 -110
- package/scripts/post-tool-use.js +880 -493
- package/scripts/pre-model-switch.js +691 -469
- package/scripts/pre-tool-use.js +728 -498
- package/scripts/query.js +845 -526
- package/scripts/reconcile.js +716 -494
- package/scripts/remediate.js +728 -498
- package/scripts/scan-worker.js +153 -58
- package/scripts/session-start.js +783 -558
- package/scripts/start-light.js +238 -88
- package/scripts/statusline.js +697 -475
- package/scripts/stop.js +490 -121
- package/scripts/sync.js +722 -494
- package/scripts/user-prompt-submit.js +725 -495
package/scripts/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({
|
|
@@ -23703,11 +23718,11 @@ var WorkspaceSettings = external_exports.object({
|
|
|
23703
23718
|
// covers the current payload and must be re-granted.
|
|
23704
23719
|
modelJudgeConsent: ModelJudgeConsent.optional(),
|
|
23705
23720
|
// Records that the user consented to the DEFERRED send — the outbox — along
|
|
23706
|
-
// with the payload shape and the endpoint they agreed to. Since payload
|
|
23707
|
-
// that covers
|
|
23708
|
-
// carry prompt/reply text in `content
|
|
23709
|
-
// Absent until granted, and a grant for a different endpoint
|
|
23710
|
-
// payload no longer counts.
|
|
23721
|
+
// with the payload shape and the endpoint they agreed to. Since payload v3
|
|
23722
|
+
// that covers the pre-attach backlog AND undelivered captures alike, and both
|
|
23723
|
+
// carry prompt/reply/tool-output text in `content`; the key name predates
|
|
23724
|
+
// both widenings. Absent until granted, and a grant for a different endpoint
|
|
23725
|
+
// or an older payload no longer counts.
|
|
23711
23726
|
historySyncConsent: HistorySyncConsent.optional()
|
|
23712
23727
|
});
|
|
23713
23728
|
function defaultWorkspaceSettings() {
|
|
@@ -23838,6 +23853,9 @@ var ManagedSettingKey = external_exports.enum([
|
|
|
23838
23853
|
"dataSharesInPlace",
|
|
23839
23854
|
"redactFallback"
|
|
23840
23855
|
]).meta({ id: "ManagedSettingKey" });
|
|
23856
|
+
function isManagedSettingKey(value) {
|
|
23857
|
+
return ManagedSettingKey.safeParse(value).success;
|
|
23858
|
+
}
|
|
23841
23859
|
var ManagedSettingsValues = external_exports.object({
|
|
23842
23860
|
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
23843
23861
|
controlPlane: external_exports.object({
|
|
@@ -23862,7 +23880,27 @@ var ManagedSettings = external_exports.object({
|
|
|
23862
23880
|
// Which of those the user may not change. A key here with no matching value
|
|
23863
23881
|
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
23864
23882
|
// the user may still override. The two are separable on purpose.
|
|
23865
|
-
|
|
23883
|
+
//
|
|
23884
|
+
// Parsed as NAMES rather than as the enum, and split below: a name this
|
|
23885
|
+
// build does not know is dropped from the locked set and reported, never a
|
|
23886
|
+
// reason to refuse the file. The same shape reaches an older build whenever
|
|
23887
|
+
// an administrator locks a key a newer build added, and refusing it there
|
|
23888
|
+
// ran that build entirely unmanaged — every pin and lock gone — on exactly
|
|
23889
|
+
// the fleets most likely to carry a version skew. A name outside the enum
|
|
23890
|
+
// is still never HONOURED: the lockable set stays explicit above.
|
|
23891
|
+
lockedFields: external_exports.array(external_exports.string()).default([])
|
|
23892
|
+
}).transform(({ lockedFields, ...rest }) => {
|
|
23893
|
+
const known = [];
|
|
23894
|
+
const unknown2 = [];
|
|
23895
|
+
for (const name of lockedFields) {
|
|
23896
|
+
if (isManagedSettingKey(name)) known.push(name);
|
|
23897
|
+
else unknown2.push(name);
|
|
23898
|
+
}
|
|
23899
|
+
return {
|
|
23900
|
+
...rest,
|
|
23901
|
+
lockedFields: known,
|
|
23902
|
+
...unknown2.length > 0 ? { unknownLockedFields: unknown2 } : {}
|
|
23903
|
+
};
|
|
23866
23904
|
}).meta({ id: "ManagedSettings" });
|
|
23867
23905
|
|
|
23868
23906
|
// ../../packages/schema/src/zod/project-files.ts
|
|
@@ -23986,7 +24024,11 @@ var FindingsTimeseriesPoint = external_exports.object({
|
|
|
23986
24024
|
timestamp: external_exports.iso.date(),
|
|
23987
24025
|
critical: external_exports.number().int().nonnegative(),
|
|
23988
24026
|
high: external_exports.number().int().nonnegative(),
|
|
23989
|
-
medium: external_exports.number().int().nonnegative()
|
|
24027
|
+
medium: external_exports.number().int().nonnegative(),
|
|
24028
|
+
// Optional and additive, so a producer written against the earlier
|
|
24029
|
+
// three-series contract keeps validating. A consumer plotting it resolves the
|
|
24030
|
+
// absent case itself — the chart point requires a number.
|
|
24031
|
+
low: external_exports.number().int().nonnegative().optional()
|
|
23990
24032
|
}).meta({ id: "FindingsTimeseriesPoint" });
|
|
23991
24033
|
var FindingsTimeseriesResponse = external_exports.object({
|
|
23992
24034
|
range: TimeRange,
|
|
@@ -24012,6 +24054,10 @@ var ResolvedFeedItem = external_exports.object({
|
|
|
24012
24054
|
findingKey: external_exports.string(),
|
|
24013
24055
|
ruleId: external_exports.string(),
|
|
24014
24056
|
severity: Severity,
|
|
24057
|
+
// Repository slug, and the file path RELATIVE to it. The pair is what
|
|
24058
|
+
// identifies the file: a bare path matches the same name in every repo.
|
|
24059
|
+
// Optional and additive; empty when the event carried no repo.
|
|
24060
|
+
repo: external_exports.string().optional(),
|
|
24015
24061
|
path: external_exports.string(),
|
|
24016
24062
|
// ISO-8601 datetime (matches FindingInstance.detectedAt / the rest of the
|
|
24017
24063
|
// findings domain). The reader `.toISOString()`s the DB epoch-ms values.
|
|
@@ -25575,7 +25621,8 @@ var SqliteActivityRepository = class {
|
|
|
25575
25621
|
SELECT 1 FROM audit_events d
|
|
25576
25622
|
WHERE d.root_session_id = audit_events.id
|
|
25577
25623
|
AND (d.content LIKE ? ESCAPE '\\'
|
|
25578
|
-
OR json_extract(d.attributes, '$.detail')
|
|
25624
|
+
OR coalesce(json_extract(d.attributes, '$.detail'),
|
|
25625
|
+
json_extract(d.attributes, '$.target')) LIKE ? ESCAPE '\\')))`
|
|
25579
25626
|
);
|
|
25580
25627
|
params.push(pattern, pattern, pattern, pattern, pattern, pattern);
|
|
25581
25628
|
}
|
|
@@ -26913,23 +26960,6 @@ var LATEST_RESOLUTION_BY_KEY_SQL = `(
|
|
|
26913
26960
|
)`;
|
|
26914
26961
|
|
|
26915
26962
|
// ../../packages/persistence/src/repositories/findings.ts
|
|
26916
|
-
var PREVIEW_INSTANCES_PER_GROUP = 200;
|
|
26917
|
-
var DEFAULT_LOCATIONS_LIMIT = 100;
|
|
26918
|
-
var LOCATION_RULE_IDS_CAP = 20;
|
|
26919
|
-
function compareLocationOrder(a, b) {
|
|
26920
|
-
return compareFindingGroupOrder(
|
|
26921
|
-
{
|
|
26922
|
-
severity: a.maxSeverity,
|
|
26923
|
-
latestDetectedAt: a.latestDetectedAt,
|
|
26924
|
-
id: ""
|
|
26925
|
-
},
|
|
26926
|
-
{
|
|
26927
|
-
severity: b.maxSeverity,
|
|
26928
|
-
latestDetectedAt: b.latestDetectedAt,
|
|
26929
|
-
id: ""
|
|
26930
|
-
}
|
|
26931
|
-
);
|
|
26932
|
-
}
|
|
26933
26963
|
var CONCAT_SEP = ",";
|
|
26934
26964
|
var TUPLE_SEP = "|";
|
|
26935
26965
|
function splitConcat(value) {
|
|
@@ -26981,13 +27011,48 @@ function decodeGroupCursor(cursor) {
|
|
|
26981
27011
|
return null;
|
|
26982
27012
|
}
|
|
26983
27013
|
function firstAfter(sorted, cursor) {
|
|
26984
|
-
const index = sorted.findIndex((
|
|
27014
|
+
const index = sorted.findIndex((t) => compareFindingGroupOrder(t, cursor) > 0);
|
|
26985
27015
|
return index === -1 ? sorted.length : index;
|
|
26986
27016
|
}
|
|
26987
27017
|
function findDeepLinked(sorted, page, id) {
|
|
26988
|
-
if (page.some((
|
|
26989
|
-
return sorted.find((
|
|
27018
|
+
if (page.some((t) => t.id === id)) return void 0;
|
|
27019
|
+
return sorted.find((t) => t.id === id);
|
|
26990
27020
|
}
|
|
27021
|
+
function encodeLocationCursor(location) {
|
|
27022
|
+
const payload = {
|
|
27023
|
+
sev: location.maxSeverity,
|
|
27024
|
+
t: location.latestDetectedAt,
|
|
27025
|
+
r: location.repo,
|
|
27026
|
+
f: location.file
|
|
27027
|
+
};
|
|
27028
|
+
return Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
27029
|
+
}
|
|
27030
|
+
function decodeLocationCursor(cursor) {
|
|
27031
|
+
const parsed2 = parseJsonObject(Buffer.from(cursor, "base64url").toString("utf8"));
|
|
27032
|
+
if (parsed2 !== void 0 && typeof parsed2.sev === "string" && typeof parsed2.t === "string" && typeof parsed2.r === "string" && typeof parsed2.f === "string") {
|
|
27033
|
+
return { maxSeverity: parsed2.sev, latestDetectedAt: parsed2.t, repo: parsed2.r, file: parsed2.f };
|
|
27034
|
+
}
|
|
27035
|
+
return null;
|
|
27036
|
+
}
|
|
27037
|
+
function firstLocationAfter(sorted, cursor) {
|
|
27038
|
+
const index = sorted.findIndex((l) => compareLocationOrder(l, cursor) > 0);
|
|
27039
|
+
return index === -1 ? sorted.length : index;
|
|
27040
|
+
}
|
|
27041
|
+
function findDeepLinkedLocation(sorted, page, id) {
|
|
27042
|
+
if (page.some((l) => l.id === id)) return void 0;
|
|
27043
|
+
return sorted.find((l) => l.id === id);
|
|
27044
|
+
}
|
|
27045
|
+
var FINDING_ROW_COLUMNS_SQL = `f.id AS id, d.rule_id AS rule_id, d.category AS category,
|
|
27046
|
+
d.severity AS severity, f.masked_match AS masked_match,
|
|
27047
|
+
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27048
|
+
e.started_at AS occurred_at,
|
|
27049
|
+
e.source_tool AS source_tool,
|
|
27050
|
+
e.repo AS repo,
|
|
27051
|
+
e.file_path AS file,
|
|
27052
|
+
e.tool_name AS tool_name,
|
|
27053
|
+
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27054
|
+
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27055
|
+
${latestResolutionStatusSql("f")} AS latest_status`;
|
|
26991
27056
|
var DAY_MS3 = 864e5;
|
|
26992
27057
|
var SqliteFindingsRepository = class {
|
|
26993
27058
|
constructor(db) {
|
|
@@ -27108,30 +27173,26 @@ var SqliteFindingsRepository = class {
|
|
|
27108
27173
|
);
|
|
27109
27174
|
}
|
|
27110
27175
|
/**
|
|
27111
|
-
*
|
|
27112
|
-
*
|
|
27113
|
-
*
|
|
27114
|
-
*
|
|
27115
|
-
*
|
|
27116
|
-
*
|
|
27117
|
-
*
|
|
27118
|
-
*
|
|
27119
|
-
*
|
|
27120
|
-
*
|
|
27121
|
-
*
|
|
27122
|
-
*
|
|
27176
|
+
* Finding TYPES for the dashboard — one row per rule, scoped to the four
|
|
27177
|
+
* capture kinds (audit_events also holds structural/reconciler/scan rows this
|
|
27178
|
+
* list must never surface), with per-filter-excluded facets, the requested
|
|
27179
|
+
* filters applied, and sorted by severity then recency. Filtering and faceting
|
|
27180
|
+
* run in JS via the shared @akasecurity/schema helpers. `totals` reflect the
|
|
27181
|
+
* full filtered set; `items` is the requested page (default 50), keyset-paged.
|
|
27182
|
+
* Under a `status` filter, `totals.findings` counts only findings whose
|
|
27183
|
+
* derived status was requested.
|
|
27184
|
+
*
|
|
27185
|
+
* ONE read, which materializes no findings: a single aggregate per rule_id,
|
|
27186
|
+
* folding EVERY finding into the numbers a type row and the filters need
|
|
27187
|
+
* (count, severity, category, providers, actions, statuses, latest, search
|
|
27188
|
+
* text). The findings OF a type come from listFindingInstances scoped to
|
|
27189
|
+
* `subtype`, so neither list bounds the other and no per-type cap exists.
|
|
27123
27190
|
*
|
|
27124
|
-
* Two reads, neither of which materializes a row per finding:
|
|
27125
|
-
* 1. one aggregate row per rule_id, folding EVERY instance into the numbers
|
|
27126
|
-
* the group and the filters need (count, providers, actions, statuses,
|
|
27127
|
-
* latest, search text);
|
|
27128
|
-
* 2. each group's newest PREVIEW_INSTANCES_PER_GROUP instances, which
|
|
27129
|
-
* populate `instances` for the table's expanded rows.
|
|
27130
27191
|
* The aggregates carry raw DB values and are translated by the same
|
|
27131
|
-
* @akasecurity/schema mappers
|
|
27132
|
-
* rule is ever restated in SQL.
|
|
27192
|
+
* @akasecurity/schema mappers every other path uses, so no enum mapping or
|
|
27193
|
+
* status rule is ever restated in SQL.
|
|
27133
27194
|
*/
|
|
27134
|
-
|
|
27195
|
+
listFindingTypes(query) {
|
|
27135
27196
|
const sessionPredicate = query.sessionId ? ` AND e.root_session_id = :sessionId` : "";
|
|
27136
27197
|
const fromMs = query.from === void 0 ? void 0 : isoToEpochMillis(query.from);
|
|
27137
27198
|
const fromPredicate = fromMs === void 0 ? "" : ` AND e.started_at >= :fromMs`;
|
|
@@ -27144,12 +27205,7 @@ var SqliteFindingsRepository = class {
|
|
|
27144
27205
|
predicate,
|
|
27145
27206
|
params: sessionParams
|
|
27146
27207
|
});
|
|
27147
|
-
const
|
|
27148
|
-
sessionId: query.sessionId,
|
|
27149
|
-
from: query.from
|
|
27150
|
-
});
|
|
27151
|
-
const groupable = rows.map(toFlatFindingRow);
|
|
27152
|
-
const allGroups = buildFindingGroups(groupable, { aggregates });
|
|
27208
|
+
const allTypes = buildFindingTypes(aggregates);
|
|
27153
27209
|
const filterOpts = {
|
|
27154
27210
|
severity: query.severity,
|
|
27155
27211
|
providers: query.provider,
|
|
@@ -27158,30 +27214,25 @@ var SqliteFindingsRepository = class {
|
|
|
27158
27214
|
subtype: query.subtype,
|
|
27159
27215
|
q: query.q
|
|
27160
27216
|
};
|
|
27161
|
-
const facets = computeFindingFacets(
|
|
27162
|
-
const sorted =
|
|
27217
|
+
const facets = computeFindingFacets(allTypes, filterOpts);
|
|
27218
|
+
const sorted = sortFindingTypes(applyFindingFilters(allTypes, filterOpts));
|
|
27163
27219
|
const statusFilter = query.status ?? [];
|
|
27164
27220
|
const totals = {
|
|
27165
|
-
findings: sorted.reduce((acc,
|
|
27166
|
-
if (statusFilter.length === 0) return acc +
|
|
27167
|
-
const agg = aggregates.get(
|
|
27168
|
-
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ??
|
|
27221
|
+
findings: sorted.reduce((acc, t) => {
|
|
27222
|
+
if (statusFilter.length === 0) return acc + t.instanceCount;
|
|
27223
|
+
const agg = aggregates.get(t.id);
|
|
27224
|
+
return acc + (agg ? countInstancesByStatus(agg.statusInputs, statusFilter) ?? t.instanceCount : t.instanceCount);
|
|
27169
27225
|
}, 0),
|
|
27170
|
-
|
|
27226
|
+
types: sorted.length
|
|
27171
27227
|
};
|
|
27172
|
-
const limit = query.limit ??
|
|
27228
|
+
const limit = query.limit ?? DEFAULT_FINDING_TYPES_LIMIT;
|
|
27173
27229
|
const cursor = query.cursor === void 0 ? null : decodeGroupCursor(query.cursor);
|
|
27174
27230
|
const start = cursor === null ? 0 : firstAfter(sorted, cursor);
|
|
27175
27231
|
const page = sorted.slice(start, start + limit);
|
|
27176
27232
|
const lastOnPage = page.at(-1);
|
|
27177
27233
|
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeGroupCursor(lastOnPage) : null;
|
|
27178
27234
|
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinked(sorted, page, query.includeId);
|
|
27179
|
-
const
|
|
27180
|
-
const narrow = (g) => statusSet ? {
|
|
27181
|
-
...g,
|
|
27182
|
-
instances: g.instances.filter((i) => i.status !== void 0 && statusSet.has(i.status))
|
|
27183
|
-
} : g;
|
|
27184
|
-
const items = [...page, ...deepLinked ? [deepLinked] : []].map(narrow);
|
|
27235
|
+
const items = [...page, ...deepLinked ? [deepLinked] : []];
|
|
27185
27236
|
return Promise.resolve({
|
|
27186
27237
|
totals,
|
|
27187
27238
|
facets,
|
|
@@ -27192,7 +27243,7 @@ var SqliteFindingsRepository = class {
|
|
|
27192
27243
|
}
|
|
27193
27244
|
/**
|
|
27194
27245
|
* One row per rule_id, folding EVERY instance of the group into the values
|
|
27195
|
-
*
|
|
27246
|
+
* buildFindingTypes cannot recover from an aggregate. Bounded by the number of
|
|
27196
27247
|
* distinct rule_ids (the installed packs' rules), not by the store's size.
|
|
27197
27248
|
*
|
|
27198
27249
|
* A single scan, folded in two levels: the inner SELECT groups by
|
|
@@ -27286,13 +27337,25 @@ var SqliteFindingsRepository = class {
|
|
|
27286
27337
|
});
|
|
27287
27338
|
}
|
|
27288
27339
|
/**
|
|
27289
|
-
* The same findings folded by
|
|
27340
|
+
* The same findings folded by WHERE they live — one row per (repo, file) pair.
|
|
27290
27341
|
*
|
|
27291
27342
|
* The grouping keys come from the capturing event's attributes, which is what
|
|
27292
|
-
* the local store relates a finding to
|
|
27293
|
-
*
|
|
27294
|
-
* empty-string bucket, which
|
|
27295
|
-
*
|
|
27343
|
+
* the local store relates a finding to; there is no finding↔asset row to group
|
|
27344
|
+
* by instead. A repo or file the event did not record folds into the
|
|
27345
|
+
* empty-string bucket, which is a real location like any other: it is listed,
|
|
27346
|
+
* it is selectable, and its `?loc=` token is as good as any other row's.
|
|
27347
|
+
*
|
|
27348
|
+
* ONE flat list rather than repos nesting files. A rollup can only be paged by
|
|
27349
|
+
* repo, which leaves the file list inside it unbounded — the shape the by-type
|
|
27350
|
+
* list was rebuilt to remove — and two-level pagination inside an
|
|
27351
|
+
* expand/collapse table is what pushed that view to master/detail in the first
|
|
27352
|
+
* place.
|
|
27353
|
+
*
|
|
27354
|
+
* Every filter narrows the FINDINGS and the locations fall out of what
|
|
27355
|
+
* survives, so each row's `instanceCount` is exactly what listFindingInstances
|
|
27356
|
+
* reports for the same filters scoped to that pair. The view depends on it:
|
|
27357
|
+
* one toolbar sits over both panels precisely because a location owns none of
|
|
27358
|
+
* its fields.
|
|
27296
27359
|
*/
|
|
27297
27360
|
listFindingLocations(query) {
|
|
27298
27361
|
const opts = {
|
|
@@ -27304,13 +27367,16 @@ var SqliteFindingsRepository = class {
|
|
|
27304
27367
|
tools: query.tool,
|
|
27305
27368
|
q: query.q
|
|
27306
27369
|
};
|
|
27307
|
-
const limit = query.limit ??
|
|
27370
|
+
const limit = query.limit ?? DEFAULT_FINDING_LOCATIONS_LIMIT;
|
|
27371
|
+
const cursor = query.cursor === void 0 ? null : decodeLocationCursor(query.cursor);
|
|
27308
27372
|
const byRepo = /* @__PURE__ */ new Map();
|
|
27373
|
+
const accumulator = createInstanceFacetAccumulator(opts);
|
|
27309
27374
|
let total = 0;
|
|
27310
27375
|
for (const row of this.scanFindingRows({
|
|
27311
27376
|
sessionId: query.sessionId,
|
|
27312
27377
|
from: query.from
|
|
27313
27378
|
})) {
|
|
27379
|
+
accumulator.add(row);
|
|
27314
27380
|
if (!matchesInstanceFilters(row, opts)) continue;
|
|
27315
27381
|
total += 1;
|
|
27316
27382
|
let files = byRepo.get(row.repo);
|
|
@@ -27325,103 +27391,35 @@ var SqliteFindingsRepository = class {
|
|
|
27325
27391
|
}
|
|
27326
27392
|
addToLocation(acc, row);
|
|
27327
27393
|
}
|
|
27328
|
-
|
|
27329
|
-
const
|
|
27330
|
-
|
|
27331
|
-
|
|
27332
|
-
|
|
27333
|
-
|
|
27334
|
-
|
|
27335
|
-
|
|
27336
|
-
|
|
27337
|
-
|
|
27338
|
-
|
|
27339
|
-
|
|
27340
|
-
|
|
27341
|
-
|
|
27342
|
-
|
|
27343
|
-
|
|
27344
|
-
|
|
27345
|
-
|
|
27346
|
-
|
|
27347
|
-
|
|
27348
|
-
|
|
27349
|
-
|
|
27350
|
-
);
|
|
27351
|
-
const statuses = fileRows.map((f) => f.status);
|
|
27352
|
-
const folded = foldGroupStatus(statuses);
|
|
27353
|
-
return {
|
|
27354
|
-
repo,
|
|
27355
|
-
instanceCount: rollup.instanceCount,
|
|
27356
|
-
maxSeverity: rollup.maxSeverity,
|
|
27357
|
-
latestDetectedAt: rollup.latestDetectedAt,
|
|
27358
|
-
...folded === void 0 ? {} : { status: folded },
|
|
27359
|
-
files: fileRows
|
|
27360
|
-
};
|
|
27361
|
-
});
|
|
27362
|
-
repos.sort(compareLocationOrder);
|
|
27394
|
+
const sorted = [];
|
|
27395
|
+
for (const [repo, files] of byRepo) {
|
|
27396
|
+
for (const [file2, acc] of files) {
|
|
27397
|
+
const status = foldGroupStatus(acc.statuses);
|
|
27398
|
+
sorted.push({
|
|
27399
|
+
id: encodeLocationId(repo, file2),
|
|
27400
|
+
repo,
|
|
27401
|
+
file: file2,
|
|
27402
|
+
instanceCount: acc.instanceCount,
|
|
27403
|
+
maxSeverity: acc.maxSeverity,
|
|
27404
|
+
latestDetectedAt: acc.latestDetectedAt,
|
|
27405
|
+
...status === void 0 ? {} : { status },
|
|
27406
|
+
ruleIds: [...acc.ruleIds]
|
|
27407
|
+
});
|
|
27408
|
+
}
|
|
27409
|
+
}
|
|
27410
|
+
sorted.sort(compareLocationOrder);
|
|
27411
|
+
const start = cursor === null ? 0 : firstLocationAfter(sorted, cursor);
|
|
27412
|
+
const page = sorted.slice(start, start + limit);
|
|
27413
|
+
const lastOnPage = page.at(-1);
|
|
27414
|
+
const nextCursor = start + limit < sorted.length && lastOnPage ? encodeLocationCursor(lastOnPage) : null;
|
|
27415
|
+
const deepLinked = query.includeId === void 0 || query.includeId === "" ? void 0 : findDeepLinkedLocation(sorted, page, query.includeId);
|
|
27363
27416
|
return Promise.resolve({
|
|
27364
|
-
totals: { findings: total,
|
|
27365
|
-
|
|
27366
|
-
|
|
27417
|
+
totals: { findings: total, locations: sorted.length },
|
|
27418
|
+
facets: accumulator.facets(),
|
|
27419
|
+
items: [...page, ...deepLinked ? [deepLinked] : []],
|
|
27420
|
+
nextCursor
|
|
27367
27421
|
});
|
|
27368
27422
|
}
|
|
27369
|
-
/**
|
|
27370
|
-
* Each group's newest instances, for the table's expanded rows.
|
|
27371
|
-
*
|
|
27372
|
-
* ONE index-ordered scan with early termination, and the shape is the point.
|
|
27373
|
-
* The natural spelling — `ROW_NUMBER() OVER (PARTITION BY rule_id ORDER BY
|
|
27374
|
-
* started_at DESC)` then `WHERE rn <= cap` — sorts EVERY finding in scope
|
|
27375
|
-
* through a temp B-tree to keep a bounded preview of each group, and then
|
|
27376
|
-
* sorts the survivors again for the page order. Both sorts grow with the
|
|
27377
|
-
* store while the answer does not.
|
|
27378
|
-
*
|
|
27379
|
-
* Instead the scan walks `audit_events` newest-first off `idx_audit_started_at`
|
|
27380
|
-
* (or the session or window index the scope names — see `findingScanSql`),
|
|
27381
|
-
* which is already the order the page wants, and keeps rows per rule until
|
|
27382
|
-
* each rule has as many as it can show. The aggregate the caller already holds
|
|
27383
|
-
* says how many that is: `min(instanceCount, PREVIEW_INSTANCES_PER_GROUP)`
|
|
27384
|
-
* per rule, summed, is the number of rows this scan has to find, and it stops
|
|
27385
|
-
* on the last one. That sum is bounded by `rules * PREVIEW_INSTANCES_PER_GROUP`
|
|
27386
|
-
* (8,000 at this repo's 40-rule bench corpus), not by a fixed row count — a
|
|
27387
|
-
* store with many firing rules widens it. The bound that DOES hold
|
|
27388
|
-
* unconditionally is the sorted form's floor: this scan visits at most as
|
|
27389
|
-
* many rows as `ROW_NUMBER() OVER (PARTITION BY rule_id …)` would have
|
|
27390
|
-
* sorted, and stops the moment every rule has its cap, where the sorted form
|
|
27391
|
-
* sorts the whole scope regardless. The true worst case — the rarest rule's
|
|
27392
|
-
* wanted instances sitting at the tail of the scope — is one pass over
|
|
27393
|
-
* everything in scope with a block sort of the id tie-break only, never a
|
|
27394
|
-
* sort of the scope, which is still that floor.
|
|
27395
|
-
*
|
|
27396
|
-
* A row whose rule the aggregate did not see is skipped: the two statements
|
|
27397
|
-
* run without a shared snapshot, so a capture landing between them can add a
|
|
27398
|
-
* rule here that has no counts there, and the counts are what the group is
|
|
27399
|
-
* built from.
|
|
27400
|
-
*/
|
|
27401
|
-
previewRows(aggregates, scope) {
|
|
27402
|
-
const wanted = /* @__PURE__ */ new Map();
|
|
27403
|
-
let remaining = 0;
|
|
27404
|
-
for (const [ruleId, agg] of aggregates) {
|
|
27405
|
-
const n = Math.min(agg.instanceCount, PREVIEW_INSTANCES_PER_GROUP);
|
|
27406
|
-
wanted.set(ruleId, n);
|
|
27407
|
-
remaining += n;
|
|
27408
|
-
}
|
|
27409
|
-
const rows = [];
|
|
27410
|
-
if (remaining === 0) return rows;
|
|
27411
|
-
const { sql, params } = this.findingScanSql(scope);
|
|
27412
|
-
const taken = /* @__PURE__ */ new Map();
|
|
27413
|
-
for (const r of iterateRows(this.db.prepare(sql), params)) {
|
|
27414
|
-
const want = wanted.get(r.rule_id);
|
|
27415
|
-
if (want === void 0) continue;
|
|
27416
|
-
const have = taken.get(r.rule_id) ?? 0;
|
|
27417
|
-
if (have >= want) continue;
|
|
27418
|
-
taken.set(r.rule_id, have + 1);
|
|
27419
|
-
rows.push(r);
|
|
27420
|
-
remaining -= 1;
|
|
27421
|
-
if (remaining === 0) break;
|
|
27422
|
-
}
|
|
27423
|
-
return rows;
|
|
27424
|
-
}
|
|
27425
27423
|
/**
|
|
27426
27424
|
* Every finding in scope as a FlatFindingRow, newest first, streamed.
|
|
27427
27425
|
*
|
|
@@ -27448,6 +27446,33 @@ var SqliteFindingsRepository = class {
|
|
|
27448
27446
|
yield toFlatFindingRow(r);
|
|
27449
27447
|
}
|
|
27450
27448
|
}
|
|
27449
|
+
/**
|
|
27450
|
+
* One finding by its own id, or null when no such row exists.
|
|
27451
|
+
*
|
|
27452
|
+
* A primary-key seek on `inspection_findings`, so its cost does not grow with
|
|
27453
|
+
* the store — and, unlike anything derived from a list page, it resolves a
|
|
27454
|
+
* finding of ANY age. That is what the Findings page's one-shot `?finding=`
|
|
27455
|
+
* deep link needs: the id it carries may name a finding thousands of rows
|
|
27456
|
+
* older than anything a first page holds.
|
|
27457
|
+
*
|
|
27458
|
+
* Deliberately UNFILTERED — no capture-kind, session or time predicate. It
|
|
27459
|
+
* RESOLVES an id; whether that row would survive the list's current filters is
|
|
27460
|
+
* a different question, and hiding the target because a filter excludes it is
|
|
27461
|
+
* worse than showing it.
|
|
27462
|
+
*
|
|
27463
|
+
* `groupId` on the result IS the rule id, so this one read answers both "which
|
|
27464
|
+
* type should the list select?" and "what does the drawer show?".
|
|
27465
|
+
*/
|
|
27466
|
+
findingInstance(id) {
|
|
27467
|
+
const row = this.db.prepare(
|
|
27468
|
+
`SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27469
|
+
FROM inspection_findings f
|
|
27470
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
27471
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
27472
|
+
WHERE f.id = ?`
|
|
27473
|
+
).get(id);
|
|
27474
|
+
return Promise.resolve(row === void 0 ? null : toInstanceDetail(toFlatFindingRow(row)));
|
|
27475
|
+
}
|
|
27451
27476
|
/**
|
|
27452
27477
|
* The one statement both instance-level scans run: every finding in scope,
|
|
27453
27478
|
* joined to its event and definition, newest first.
|
|
@@ -27481,17 +27506,7 @@ var SqliteFindingsRepository = class {
|
|
|
27481
27506
|
conditions.push("e.started_at >= ?");
|
|
27482
27507
|
params.push(isoToEpochMillis(scope.from));
|
|
27483
27508
|
}
|
|
27484
|
-
const sql = `SELECT
|
|
27485
|
-
d.severity AS severity, f.masked_match AS masked_match,
|
|
27486
|
-
f.action_taken AS action_taken, f.confidence AS confidence,
|
|
27487
|
-
e.started_at AS occurred_at,
|
|
27488
|
-
e.source_tool AS source_tool,
|
|
27489
|
-
e.repo AS repo,
|
|
27490
|
-
e.file_path AS file,
|
|
27491
|
-
e.tool_name AS tool_name,
|
|
27492
|
-
f.audit_event_id AS event_id, e.root_session_id AS session_id,
|
|
27493
|
-
e.event_type AS kind, f.finding_key AS finding_key,
|
|
27494
|
-
${latestResolutionStatusSql("f")} AS latest_status
|
|
27509
|
+
const sql = `SELECT ${FINDING_ROW_COLUMNS_SQL}
|
|
27495
27510
|
FROM audit_events e
|
|
27496
27511
|
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
27497
27512
|
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -27505,6 +27520,26 @@ var SqliteFindingsRepository = class {
|
|
|
27505
27520
|
group_concat(DISTINCT 'via ' || e.tool_name) AS tool_names` : `, NULL AS repos, NULL AS files, NULL AS tool_names`;
|
|
27506
27521
|
const rows = this.db.prepare(
|
|
27507
27522
|
`SELECT rule_id,
|
|
27523
|
+
-- BARE columns beside max(latest_at), which is deliberate and
|
|
27524
|
+
-- is SQLite's documented behaviour: with a single min()/max()
|
|
27525
|
+
-- in an aggregate query, every bare column takes its value from
|
|
27526
|
+
-- the row that produced the extremum. So these are the severity
|
|
27527
|
+
-- and category of the definition whose finding is NEWEST, which
|
|
27528
|
+
-- is what the row-based build they replaced read off its first
|
|
27529
|
+
-- (newest-first) row.
|
|
27530
|
+
--
|
|
27531
|
+
-- min() is WRONG here and was the defect: inspection_definitions
|
|
27532
|
+
-- holds one row per rule VERSION (see its writer \u2014 a version bump
|
|
27533
|
+
-- mints a new row), so a rule whose severity moved between
|
|
27534
|
+
-- versions has several, and min() picks the ALPHABETICALLY
|
|
27535
|
+
-- smallest \u2014 'low' over 'medium', but 'critical' over 'high'.
|
|
27536
|
+
-- That is arbitrary in direction, and it feeds the badge, the
|
|
27537
|
+
-- filter, the facet counts and the primary sort key.
|
|
27538
|
+
--
|
|
27539
|
+
-- Adding a second min()/max() aggregate here would make these
|
|
27540
|
+
-- bare columns ambiguous again; keep max(latest_at) the only one.
|
|
27541
|
+
severity,
|
|
27542
|
+
category,
|
|
27508
27543
|
sum(tuple_count) AS instance_count,
|
|
27509
27544
|
max(latest_at) AS latest_at,
|
|
27510
27545
|
group_concat(source_tools) AS source_tools,
|
|
@@ -27515,6 +27550,14 @@ var SqliteFindingsRepository = class {
|
|
|
27515
27550
|
group_concat(tool_names) AS tool_names
|
|
27516
27551
|
FROM (
|
|
27517
27552
|
SELECT d.rule_id AS rule_id,
|
|
27553
|
+
-- Severity and category are columns of the DEFINITION, and
|
|
27554
|
+
-- a rule can have SEVERAL definitions (one per version), so
|
|
27555
|
+
-- these are grouped on below and resolved to the newest
|
|
27556
|
+
-- firing version by the outer query's bare-column select.
|
|
27557
|
+
-- They ride the aggregate because the type build has no rows
|
|
27558
|
+
-- to read them off \u2014 see buildFindingTypes.
|
|
27559
|
+
d.severity AS severity,
|
|
27560
|
+
d.category AS category,
|
|
27518
27561
|
e.event_type || '${TUPLE_SEP}' ||
|
|
27519
27562
|
(CASE WHEN f.finding_key IS NULL THEN '' ELSE 'k' END) || '${TUPLE_SEP}' ||
|
|
27520
27563
|
coalesce(latest.status, '') AS status_tuple,
|
|
@@ -27529,7 +27572,7 @@ var SqliteFindingsRepository = class {
|
|
|
27529
27572
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
27530
27573
|
ON latest.finding_key = f.finding_key
|
|
27531
27574
|
${scope.predicate}
|
|
27532
|
-
GROUP BY d.rule_id, status_tuple
|
|
27575
|
+
GROUP BY d.rule_id, d.severity, d.category, status_tuple
|
|
27533
27576
|
)
|
|
27534
27577
|
GROUP BY rule_id`
|
|
27535
27578
|
).all(scope.params);
|
|
@@ -27538,6 +27581,8 @@ var SqliteFindingsRepository = class {
|
|
|
27538
27581
|
r.rule_id,
|
|
27539
27582
|
{
|
|
27540
27583
|
instanceCount: r.instance_count,
|
|
27584
|
+
severity: r.severity,
|
|
27585
|
+
category: r.category,
|
|
27541
27586
|
sourceTools: splitConcat(r.source_tools),
|
|
27542
27587
|
actionsTaken: splitConcat(r.actions_taken),
|
|
27543
27588
|
statusInputs: splitConcat(r.status_inputs).map((tuple2) => {
|
|
@@ -27554,7 +27599,7 @@ var SqliteFindingsRepository = class {
|
|
|
27554
27599
|
latestDetectedAt: epochMillisToIso(r.latest_at),
|
|
27555
27600
|
// Free text only — joined and substring-matched, so group_concat's
|
|
27556
27601
|
// commas need no unpicking (a repo/path containing one still matches).
|
|
27557
|
-
// Left undefined (not '') when unfetched, so
|
|
27602
|
+
// Left undefined (not '') when unfetched, so buildFindingTypes can
|
|
27558
27603
|
// tell "no q this request" from "a group with no repo/file at all"
|
|
27559
27604
|
// and skip priming a haystack nothing will read.
|
|
27560
27605
|
...withSearchText ? {
|
|
@@ -27706,6 +27751,12 @@ var SqliteHistorySyncRepository = class {
|
|
|
27706
27751
|
this.markOwedStmt = db.prepare(
|
|
27707
27752
|
`UPDATE audit_events SET outbox_owed = 1 WHERE id = :id AND synced_at IS NULL`
|
|
27708
27753
|
);
|
|
27754
|
+
this.markCaptureBacklogOwedStmt = db.prepare(
|
|
27755
|
+
`UPDATE audit_events SET outbox_owed = 1
|
|
27756
|
+
WHERE synced_at IS NULL
|
|
27757
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27758
|
+
AND started_at < :before`
|
|
27759
|
+
);
|
|
27709
27760
|
this.stampStmt = db.prepare(
|
|
27710
27761
|
`UPDATE audit_events SET synced_at = :at, sync_claimed_at = NULL WHERE id = :id`
|
|
27711
27762
|
);
|
|
@@ -27754,7 +27805,9 @@ var SqliteHistorySyncRepository = class {
|
|
|
27754
27805
|
);
|
|
27755
27806
|
this.disownCapturesStmt = db.prepare(
|
|
27756
27807
|
`UPDATE audit_events SET outbox_owed = NULL
|
|
27757
|
-
WHERE outbox_owed IS NOT NULL
|
|
27808
|
+
WHERE outbox_owed IS NOT NULL
|
|
27809
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})
|
|
27810
|
+
AND started_at < :attachedAt`
|
|
27758
27811
|
);
|
|
27759
27812
|
this.rearmStmt = db.prepare(
|
|
27760
27813
|
`UPDATE audit_events SET synced_at = NULL
|
|
@@ -27830,6 +27883,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27830
27883
|
freezeBoundaryStmt;
|
|
27831
27884
|
captureRowsStmt;
|
|
27832
27885
|
markOwedStmt;
|
|
27886
|
+
markCaptureBacklogOwedStmt;
|
|
27833
27887
|
captureSkipCountStmt;
|
|
27834
27888
|
disownCapturesStmt;
|
|
27835
27889
|
partitionStmt;
|
|
@@ -27893,6 +27947,23 @@ var SqliteHistorySyncRepository = class {
|
|
|
27893
27947
|
markCaptureOwed(id) {
|
|
27894
27948
|
this.markOwedStmt.run({ id });
|
|
27895
27949
|
}
|
|
27950
|
+
/**
|
|
27951
|
+
* Mark every capture already on disk as owed, as of `before`.
|
|
27952
|
+
*
|
|
27953
|
+
* The consent-time backfill, called once from `aka attach` when a human
|
|
27954
|
+
* grants existing-history consent — never from an ongoing drain pass, and
|
|
27955
|
+
* never inferred from a boundary that could later move. `before` is the
|
|
27956
|
+
* caller's own "now" at the moment consent was granted, so what this marks
|
|
27957
|
+
* is exactly the backlog the consent prompt already counted, not whatever a
|
|
27958
|
+
* later re-attach or key rotation might widen it to.
|
|
27959
|
+
*
|
|
27960
|
+
* Returns how many rows matched, for the caller to log or test against. Not a
|
|
27961
|
+
* count of NEWLY marked rows — a row still unsynced from an earlier call
|
|
27962
|
+
* matches again and is counted again, the same as `UPDATE`'s own `changes`.
|
|
27963
|
+
*/
|
|
27964
|
+
markCaptureBacklogOwed(before) {
|
|
27965
|
+
return Number(this.markCaptureBacklogOwedStmt.run({ before }).changes);
|
|
27966
|
+
}
|
|
27896
27967
|
/** Record delivery. Called only AFTER the far side has accepted the rows. */
|
|
27897
27968
|
markSynced(ids, atMs) {
|
|
27898
27969
|
this.stampAll(ids, atMs);
|
|
@@ -28009,15 +28080,42 @@ var SqliteHistorySyncRepository = class {
|
|
|
28009
28080
|
*
|
|
28010
28081
|
* Delivery is a fact about ONE recipient: rows sent to the deployment a
|
|
28011
28082
|
* machine has just left are undelivered as far as the new one is concerned.
|
|
28012
|
-
* All
|
|
28013
|
-
* attributed to the wrong deployment,
|
|
28083
|
+
* All four in one transaction, so a crash between them cannot leave stamps
|
|
28084
|
+
* attributed to the wrong deployment, a boundary that belongs to another, or
|
|
28085
|
+
* a disown with no re-mark to follow it.
|
|
28014
28086
|
*
|
|
28015
28087
|
* The boundary is written HERE and only here, which is what freezes it: a
|
|
28016
28088
|
* re-attach to the SAME deployment (a key rotation) leaves the fingerprint
|
|
28017
28089
|
* unchanged, so this never runs and the backlog does not widen back over rows
|
|
28018
28090
|
* the live path has since delivered.
|
|
28091
|
+
*
|
|
28092
|
+
* `backfillCapturesBefore` is the caller's OWN "now" at the instant a human
|
|
28093
|
+
* granted existing-history consent for the deployment this call is arming —
|
|
28094
|
+
* a DIFFERENT instant from `backlogBefore`: the re-mark boundary is the GRANT
|
|
28095
|
+
* instant, `backlogBefore` is the ATTACH instant, and the two can be far
|
|
28096
|
+
* apart. Passed only when that grant is valid, since this method has no way
|
|
28097
|
+
* to check consent itself and must not mark a row owed for a machine that
|
|
28098
|
+
* never agreed to it. Applied AFTER the disown above, in the SAME
|
|
28099
|
+
* transaction: what the disown clears is every marker below `backlogBefore`,
|
|
28100
|
+
* which includes this deployment's OWN pre-attach rows — `aka attach` calls
|
|
28101
|
+
* `seedCaptureBacklogOwed` at the attach instant, so every row it marks sits
|
|
28102
|
+
* on the cleared side of that bound — and the re-mark in the same
|
|
28103
|
+
* transaction is what puts those rows back. A crash between the two cannot
|
|
28104
|
+
* strand the ledger disowned with nothing re-marked — the transaction either
|
|
28105
|
+
* lands whole or not at all, and a fingerprint mismatch that has not yet
|
|
28106
|
+
* committed re-enters this method on the very next pass. Omit it (the
|
|
28107
|
+
* structural-only tests do) to exercise the disown in isolation.
|
|
28108
|
+
*
|
|
28109
|
+
* The disown is bounded by `backlogBefore`, which is what keeps it from
|
|
28110
|
+
* touching a marker the NEW deployment's OWN live path has already set: B's
|
|
28111
|
+
* live path can mark a capture owed from the moment `aka attach` writes the
|
|
28112
|
+
* descriptor, before the drain's first pass ever reaches this method, and
|
|
28113
|
+
* such a row sits at or after the bound rather than below it. What keeps the
|
|
28114
|
+
* disown from eating THIS SAME CALL's own re-mark is the order, not the
|
|
28115
|
+
* bound — disown runs first, re-mark second, both inside the one
|
|
28116
|
+
* transaction above.
|
|
28019
28117
|
*/
|
|
28020
|
-
rearmFor(fingerprint, backlogBefore) {
|
|
28118
|
+
rearmFor(fingerprint, backlogBefore, backfillCapturesBefore) {
|
|
28021
28119
|
this.ensureRowStmt.run();
|
|
28022
28120
|
withTransaction(
|
|
28023
28121
|
this.db,
|
|
@@ -28025,7 +28123,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
28025
28123
|
const previous = getRow(this.fingerprintStmt)?.fingerprint;
|
|
28026
28124
|
this.rearmStmt.run();
|
|
28027
28125
|
if (previous !== null && previous !== void 0 && previous !== fingerprint) {
|
|
28028
|
-
this.disownCapturesStmt.run();
|
|
28126
|
+
this.disownCapturesStmt.run({ attachedAt: backlogBefore });
|
|
28127
|
+
}
|
|
28128
|
+
if (backfillCapturesBefore !== void 0) {
|
|
28129
|
+
this.markCaptureBacklogOwedStmt.run({ before: backfillCapturesBefore });
|
|
28029
28130
|
}
|
|
28030
28131
|
this.setFingerprintStmt.run({ fingerprint, backlogBefore });
|
|
28031
28132
|
},
|
|
@@ -28305,7 +28406,8 @@ function managedSettingsPaths(platform2 = process.platform) {
|
|
|
28305
28406
|
}
|
|
28306
28407
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
28307
28408
|
}
|
|
28308
|
-
|
|
28409
|
+
var testOnlyManagedPaths = null;
|
|
28410
|
+
function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPaths()) {
|
|
28309
28411
|
for (const path of paths) {
|
|
28310
28412
|
let text;
|
|
28311
28413
|
try {
|
|
@@ -30785,7 +30887,7 @@ function toUtcDateString(ms) {
|
|
|
30785
30887
|
return new Date(ms).toISOString().slice(0, 10);
|
|
30786
30888
|
}
|
|
30787
30889
|
function isTimeseriesSeverity(s) {
|
|
30788
|
-
return s === "critical" || s === "high" || s === "medium";
|
|
30890
|
+
return s === "critical" || s === "high" || s === "medium" || s === "low";
|
|
30789
30891
|
}
|
|
30790
30892
|
var SqliteSecurityRepository = class {
|
|
30791
30893
|
constructor(db, now = () => Date.now()) {
|
|
@@ -30914,12 +31016,16 @@ var SqliteSecurityRepository = class {
|
|
|
30914
31016
|
const now = this.now();
|
|
30915
31017
|
const windowStart = startOfUtcDay2(now) - (lenDays - 1) * DAY_MS4;
|
|
30916
31018
|
const rows = this.findingsInRange(windowStart, now);
|
|
30917
|
-
const points = Array.from(
|
|
30918
|
-
|
|
30919
|
-
|
|
30920
|
-
|
|
30921
|
-
|
|
30922
|
-
|
|
31019
|
+
const points = Array.from(
|
|
31020
|
+
{ length: numBuckets },
|
|
31021
|
+
(_, i) => ({
|
|
31022
|
+
timestamp: toUtcDateString(windowStart + i * bucketMs),
|
|
31023
|
+
critical: 0,
|
|
31024
|
+
high: 0,
|
|
31025
|
+
medium: 0,
|
|
31026
|
+
low: 0
|
|
31027
|
+
})
|
|
31028
|
+
);
|
|
30923
31029
|
for (const r of rows) {
|
|
30924
31030
|
const idx = Math.floor((r.occurredAt - windowStart) / bucketMs);
|
|
30925
31031
|
const bucket = points[idx];
|
|
@@ -31137,6 +31243,7 @@ var SqliteSecurityRepository = class {
|
|
|
31137
31243
|
`SELECT f.finding_key AS finding_key,
|
|
31138
31244
|
d.rule_id AS rule_id,
|
|
31139
31245
|
d.severity AS severity,
|
|
31246
|
+
e.repo AS repo,
|
|
31140
31247
|
e.file_path AS path,
|
|
31141
31248
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
31142
31249
|
latest.resolved_at AS latest_resolved_at
|
|
@@ -31156,6 +31263,7 @@ var SqliteSecurityRepository = class {
|
|
|
31156
31263
|
const items = rows.map((r) => ({
|
|
31157
31264
|
findingKey: r.finding_key,
|
|
31158
31265
|
ruleId: r.rule_id,
|
|
31266
|
+
repo: r.repo ?? "",
|
|
31159
31267
|
severity: r.severity,
|
|
31160
31268
|
path: r.path ?? "",
|
|
31161
31269
|
resolvedAt: new Date(r.latest_resolved_at).toISOString(),
|
|
@@ -31165,13 +31273,66 @@ var SqliteSecurityRepository = class {
|
|
|
31165
31273
|
}));
|
|
31166
31274
|
return Promise.resolve({ items });
|
|
31167
31275
|
}
|
|
31276
|
+
/**
|
|
31277
|
+
* Per-rule tallies of the findings that are still OPEN, whole-store.
|
|
31278
|
+
*
|
|
31279
|
+
* Scoped by status rather than by time, because the card this feeds is a to-do
|
|
31280
|
+
* list: a secret committed three weeks ago and never rotated is still the most
|
|
31281
|
+
* important thing to fix, and any window hides it. It carried a "newest N
|
|
31282
|
+
* findings" cap and then a range; the first meant a different span on every
|
|
31283
|
+
* machine, and the second reported "no recommendations" over live exposure.
|
|
31284
|
+
*
|
|
31285
|
+
* `open` mirrors `deriveFindingStatus` — at-rest, minus resolved and dismissed —
|
|
31286
|
+
* so a row's count is exactly what `?status=open&type=<rule>` returns. Note that
|
|
31287
|
+
* is NOT `severitySummary`'s `openAtRest`, which keeps dismissed findings (a
|
|
31288
|
+
* dismissal is a judgement, not a remediation) and drops untracked legacy rows.
|
|
31289
|
+
* The two answer different questions and only this one has to match a link.
|
|
31290
|
+
*
|
|
31291
|
+
* Aggregated in SQL: the result is O(distinct rule × category × severity), so a
|
|
31292
|
+
* whole-store scope costs a grouped scan rather than a row per finding.
|
|
31293
|
+
*/
|
|
31294
|
+
recommendationInputs() {
|
|
31295
|
+
const rows = allRows(
|
|
31296
|
+
this.db.prepare(
|
|
31297
|
+
`SELECT d.rule_id AS rule_id,
|
|
31298
|
+
d.category AS category,
|
|
31299
|
+
d.severity AS severity,
|
|
31300
|
+
COUNT(*) AS count
|
|
31301
|
+
FROM inspection_findings f
|
|
31302
|
+
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31303
|
+
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
31304
|
+
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
31305
|
+
ON latest.finding_key = f.finding_key
|
|
31306
|
+
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
31307
|
+
AND e.event_type = 'code_change'
|
|
31308
|
+
AND (
|
|
31309
|
+
f.finding_key IS NULL
|
|
31310
|
+
OR latest.status IS NULL
|
|
31311
|
+
OR latest.status NOT IN ('resolved', 'dismissed')
|
|
31312
|
+
)
|
|
31313
|
+
GROUP BY d.rule_id, d.category, d.severity`
|
|
31314
|
+
)
|
|
31315
|
+
);
|
|
31316
|
+
return Promise.resolve(
|
|
31317
|
+
rows.map((r) => ({
|
|
31318
|
+
ruleId: r.rule_id,
|
|
31319
|
+
category: r.category,
|
|
31320
|
+
severity: r.severity,
|
|
31321
|
+
count: r.count
|
|
31322
|
+
}))
|
|
31323
|
+
);
|
|
31324
|
+
}
|
|
31168
31325
|
// Findings whose parent event occurred in [fromMs, toMs), with the parent's
|
|
31169
31326
|
// epoch-millis timestamp. started_at is an INTEGER column, so the bounds stay
|
|
31170
31327
|
// numeric and the JS aggregations bucket/split on ms directly.
|
|
31171
31328
|
findingsInRange(fromMs, toMs) {
|
|
31172
31329
|
const rows = allRows(
|
|
31173
31330
|
this.db.prepare(
|
|
31174
|
-
`
|
|
31331
|
+
// `rule_id`/`category` cost nothing extra: inspection_definitions is already
|
|
31332
|
+
// joined for `severity`, so they are two more columns off a row this read
|
|
31333
|
+
// already fetches. They feed the recommended-actions rollup.
|
|
31334
|
+
`SELECT e.started_at AS occurred_at, d.severity AS severity, f.action_taken AS action_taken,
|
|
31335
|
+
d.rule_id AS rule_id, d.category AS category
|
|
31175
31336
|
FROM inspection_findings f
|
|
31176
31337
|
JOIN audit_events e ON e.id = f.audit_event_id
|
|
31177
31338
|
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
@@ -31184,7 +31345,9 @@ var SqliteSecurityRepository = class {
|
|
|
31184
31345
|
return rows.map((r) => ({
|
|
31185
31346
|
occurredAt: r.occurred_at,
|
|
31186
31347
|
severity: r.severity,
|
|
31187
|
-
actionTaken: r.action_taken
|
|
31348
|
+
actionTaken: r.action_taken,
|
|
31349
|
+
ruleId: r.rule_id,
|
|
31350
|
+
category: r.category
|
|
31188
31351
|
}));
|
|
31189
31352
|
}
|
|
31190
31353
|
};
|
|
@@ -32354,6 +32517,43 @@ function openLocalDatabase(dir) {
|
|
|
32354
32517
|
};
|
|
32355
32518
|
}
|
|
32356
32519
|
|
|
32520
|
+
// ../../packages/persistence/src/egress-wire.ts
|
|
32521
|
+
import { createHash as createHash3 } from "crypto";
|
|
32522
|
+
function hashProjectKey(projectKey) {
|
|
32523
|
+
return createHash3("sha256").update(projectKey, "utf8").digest("hex");
|
|
32524
|
+
}
|
|
32525
|
+
function toIngestHit(hit) {
|
|
32526
|
+
return {
|
|
32527
|
+
host: hit.host,
|
|
32528
|
+
kind: hit.kind,
|
|
32529
|
+
name: hit.name,
|
|
32530
|
+
category: hit.category,
|
|
32531
|
+
trust: hit.trust,
|
|
32532
|
+
network: hit.network,
|
|
32533
|
+
method: hit.method,
|
|
32534
|
+
transport: hit.transport,
|
|
32535
|
+
url: hit.url,
|
|
32536
|
+
template: hit.template,
|
|
32537
|
+
dataClass: hit.dataClass,
|
|
32538
|
+
site: {
|
|
32539
|
+
file: hit.site.file,
|
|
32540
|
+
line: hit.site.line,
|
|
32541
|
+
dynamic: hit.site.dynamic,
|
|
32542
|
+
vendored: hit.site.vendored
|
|
32543
|
+
}
|
|
32544
|
+
};
|
|
32545
|
+
}
|
|
32546
|
+
function toEgressIngestRequest(input2) {
|
|
32547
|
+
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
32548
|
+
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
32549
|
+
return {
|
|
32550
|
+
projectKey: hashProjectKey(input2.projectKey),
|
|
32551
|
+
project: input2.project,
|
|
32552
|
+
reconcile,
|
|
32553
|
+
hits: hits.map(toIngestHit)
|
|
32554
|
+
};
|
|
32555
|
+
}
|
|
32556
|
+
|
|
32357
32557
|
// ../../packages/persistence/src/exception-policy.ts
|
|
32358
32558
|
var UserGrantPolicyProvider = class {
|
|
32359
32559
|
#exceptions;
|
|
@@ -32375,7 +32575,7 @@ var UserGrantPolicyProvider = class {
|
|
|
32375
32575
|
};
|
|
32376
32576
|
|
|
32377
32577
|
// ../../packages/persistence/src/finding-key.ts
|
|
32378
|
-
import { createHash as
|
|
32578
|
+
import { createHash as createHash4 } from "crypto";
|
|
32379
32579
|
|
|
32380
32580
|
// ../../packages/persistence/src/fingerprint.ts
|
|
32381
32581
|
import { createHmac, randomBytes } from "crypto";
|
|
@@ -32500,14 +32700,18 @@ function fingerprintValue(key, raw) {
|
|
|
32500
32700
|
return createHmac("sha256", key.material).update(raw, "utf8").digest("hex");
|
|
32501
32701
|
}
|
|
32502
32702
|
|
|
32503
|
-
// ../../packages/persistence/src/history-
|
|
32703
|
+
// ../../packages/persistence/src/history-backfill.ts
|
|
32504
32704
|
import { existsSync as existsSync4 } from "fs";
|
|
32505
32705
|
import { join as join9 } from "path";
|
|
32706
|
+
|
|
32707
|
+
// ../../packages/persistence/src/history-preview.ts
|
|
32708
|
+
import { existsSync as existsSync5 } from "fs";
|
|
32709
|
+
import { join as join10 } from "path";
|
|
32506
32710
|
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
32507
32711
|
|
|
32508
32712
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
32509
|
-
import { existsSync as
|
|
32510
|
-
import { dirname as dirname3, join as
|
|
32713
|
+
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
32714
|
+
import { dirname as dirname3, join as join11, resolve } from "path";
|
|
32511
32715
|
|
|
32512
32716
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
32513
32717
|
import {
|
|
@@ -32621,7 +32825,7 @@ function formatPointer(category, keyVersion, pointerId, tag) {
|
|
|
32621
32825
|
import { execFileSync } from "child_process";
|
|
32622
32826
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
32623
32827
|
import { chmodSync as chmodSync3, readFileSync as readFileSync7, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
32624
|
-
import { join as
|
|
32828
|
+
import { join as join12 } from "path";
|
|
32625
32829
|
var VAULT_OCCUPANT_REASON = {
|
|
32626
32830
|
symlink: "the path is a symlink; remove it so a keyring can be created",
|
|
32627
32831
|
gone: "the path was occupied but holds no keyring (removed while it was being created)",
|
|
@@ -32720,7 +32924,7 @@ function claimRotationLock(lock, owner) {
|
|
|
32720
32924
|
throw asError(err);
|
|
32721
32925
|
}
|
|
32722
32926
|
try {
|
|
32723
|
-
writeFileSync3(
|
|
32927
|
+
writeFileSync3(join12(lock, LOCK_OWNER_FILE), `${owner}
|
|
32724
32928
|
`, { mode: DATA_FILE_MODE });
|
|
32725
32929
|
return true;
|
|
32726
32930
|
} catch (err) {
|
|
@@ -32729,7 +32933,7 @@ function claimRotationLock(lock, owner) {
|
|
|
32729
32933
|
}
|
|
32730
32934
|
}
|
|
32731
32935
|
function acquireRotationLock(keysDir2) {
|
|
32732
|
-
const lock =
|
|
32936
|
+
const lock = join12(keysDir2, `${VAULT_KEY_FILENAME}.lock`);
|
|
32733
32937
|
const owner = randomBytes2(16).toString("hex");
|
|
32734
32938
|
if (claimRotationLock(lock, owner)) return { lock, owner };
|
|
32735
32939
|
let held;
|
|
@@ -32756,7 +32960,7 @@ function acquireRotationLock(keysDir2) {
|
|
|
32756
32960
|
}
|
|
32757
32961
|
function releaseRotationLock(lease) {
|
|
32758
32962
|
try {
|
|
32759
|
-
if (readFileSync7(
|
|
32963
|
+
if (readFileSync7(join12(lease.lock, LOCK_OWNER_FILE), "utf8").trim() !== lease.owner) return;
|
|
32760
32964
|
} catch {
|
|
32761
32965
|
return;
|
|
32762
32966
|
}
|
|
@@ -32777,7 +32981,7 @@ var FileKeyProvider = class {
|
|
|
32777
32981
|
this.#keysDir = keysDir2;
|
|
32778
32982
|
}
|
|
32779
32983
|
get filePath() {
|
|
32780
|
-
return
|
|
32984
|
+
return join12(this.#keysDir, VAULT_KEY_FILENAME);
|
|
32781
32985
|
}
|
|
32782
32986
|
loadOrCreate() {
|
|
32783
32987
|
return asAsync(() => {
|
|
@@ -33442,13 +33646,13 @@ var SecretVault = class {
|
|
|
33442
33646
|
};
|
|
33443
33647
|
|
|
33444
33648
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
33445
|
-
import { existsSync as
|
|
33446
|
-
import { join as
|
|
33649
|
+
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
33650
|
+
import { join as join13 } from "path";
|
|
33447
33651
|
var MARKER = "warn-era-capped";
|
|
33448
33652
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
33449
33653
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
33450
|
-
const marker =
|
|
33451
|
-
if (
|
|
33654
|
+
const marker = join13(dataDir2, MARKER);
|
|
33655
|
+
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
33452
33656
|
const capped = db.policies.capCategoryActions();
|
|
33453
33657
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
33454
33658
|
`, { mode: DATA_FILE_MODE });
|
|
@@ -33517,8 +33721,8 @@ function providerFromModelId(modelId) {
|
|
|
33517
33721
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
33518
33722
|
try {
|
|
33519
33723
|
ensureLayoutDirSync(base);
|
|
33520
|
-
const settingsFile =
|
|
33521
|
-
if (
|
|
33724
|
+
const settingsFile = join14(settingsDir(base), "settings.json");
|
|
33725
|
+
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
33522
33726
|
} catch {
|
|
33523
33727
|
}
|
|
33524
33728
|
migrateLegacyLayout(base);
|
|
@@ -33543,7 +33747,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
33543
33747
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
33544
33748
|
import { readdirSync as readdirSync2, readFileSync as readFileSync9, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
33545
33749
|
import { homedir as homedir2 } from "os";
|
|
33546
|
-
import { basename as basename3, join as
|
|
33750
|
+
import { basename as basename3, join as join16 } from "path";
|
|
33547
33751
|
|
|
33548
33752
|
// ../../packages/detections/src/egress/registry.ts
|
|
33549
33753
|
var EXTRACTOR_VERSION = "1";
|
|
@@ -36587,8 +36791,8 @@ function scanText(text, ruleVersions) {
|
|
|
36587
36791
|
}
|
|
36588
36792
|
|
|
36589
36793
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
36590
|
-
import { existsSync as
|
|
36591
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
36794
|
+
import { existsSync as existsSync9, readFileSync as readFileSync8, statSync as statSync6 } from "fs";
|
|
36795
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join15, sep as sep2 } from "path";
|
|
36592
36796
|
function resolveRepoIdentity(cwd) {
|
|
36593
36797
|
try {
|
|
36594
36798
|
const root = findGitRoot(cwd);
|
|
@@ -36621,32 +36825,32 @@ function resolveRepoNwo(cwd) {
|
|
|
36621
36825
|
function findGitRoot(start) {
|
|
36622
36826
|
let dir = start;
|
|
36623
36827
|
for (; ; ) {
|
|
36624
|
-
if (
|
|
36828
|
+
if (existsSync9(join15(dir, ".git"))) return dir;
|
|
36625
36829
|
const parent = dirname4(dir);
|
|
36626
36830
|
if (parent === dir) return void 0;
|
|
36627
36831
|
dir = parent;
|
|
36628
36832
|
}
|
|
36629
36833
|
}
|
|
36630
36834
|
function resolveGitContext(root) {
|
|
36631
|
-
const dotGit =
|
|
36835
|
+
const dotGit = join15(root, ".git");
|
|
36632
36836
|
try {
|
|
36633
36837
|
if (statSync6(dotGit).isDirectory()) {
|
|
36634
|
-
return { configPath:
|
|
36838
|
+
return { configPath: join15(dotGit, "config"), headRoot: root };
|
|
36635
36839
|
}
|
|
36636
36840
|
} catch {
|
|
36637
36841
|
return void 0;
|
|
36638
36842
|
}
|
|
36639
36843
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
36640
36844
|
if (!target) return void 0;
|
|
36641
|
-
const gitdir = isAbsolute(target) ? target :
|
|
36642
|
-
if (
|
|
36643
|
-
return { configPath:
|
|
36845
|
+
const gitdir = isAbsolute(target) ? target : join15(root, target);
|
|
36846
|
+
if (existsSync9(join15(gitdir, "config"))) {
|
|
36847
|
+
return { configPath: join15(gitdir, "config"), headRoot: root };
|
|
36644
36848
|
}
|
|
36645
|
-
const commonRaw = safeRead(
|
|
36849
|
+
const commonRaw = safeRead(join15(gitdir, "commondir"))?.trim();
|
|
36646
36850
|
if (!commonRaw) return void 0;
|
|
36647
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
36851
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join15(gitdir, commonRaw);
|
|
36648
36852
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
36649
|
-
return { configPath:
|
|
36853
|
+
return { configPath: join15(commonGitDir, "config"), headRoot };
|
|
36650
36854
|
}
|
|
36651
36855
|
function safeRead(path) {
|
|
36652
36856
|
try {
|
|
@@ -36701,17 +36905,52 @@ function nwoFromUrl(url2) {
|
|
|
36701
36905
|
}
|
|
36702
36906
|
|
|
36703
36907
|
// ../../packages/plugin-sdk/src/events.ts
|
|
36704
|
-
import { createHash as
|
|
36908
|
+
import { createHash as createHash5, randomUUID as randomUUID13 } from "crypto";
|
|
36705
36909
|
|
|
36706
36910
|
// ../../packages/plugin-sdk/src/isolated-scan.ts
|
|
36707
|
-
import { existsSync as
|
|
36911
|
+
import { existsSync as existsSync10 } from "fs";
|
|
36708
36912
|
import { fileURLToPath } from "url";
|
|
36709
36913
|
import { Worker } from "worker_threads";
|
|
36710
36914
|
|
|
36915
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
36916
|
+
import { readFileSync as readFileSync11 } from "fs";
|
|
36917
|
+
import { join as join18 } from "path";
|
|
36918
|
+
|
|
36919
|
+
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
36920
|
+
import {
|
|
36921
|
+
closeSync as closeSync2,
|
|
36922
|
+
fstatSync,
|
|
36923
|
+
mkdirSync as mkdirSync2,
|
|
36924
|
+
openSync as openSync2,
|
|
36925
|
+
readFileSync as readFileSync10,
|
|
36926
|
+
readSync,
|
|
36927
|
+
writeFileSync as writeFileSync5
|
|
36928
|
+
} from "fs";
|
|
36929
|
+
import { join as join17 } from "path";
|
|
36930
|
+
var TAIL_BYTES = 256 * 1024;
|
|
36931
|
+
|
|
36932
|
+
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
36933
|
+
var HOST_FEATURE = {
|
|
36934
|
+
ModelSwitch: "model-switch",
|
|
36935
|
+
VaultPointerDisplay: "vault-pointer-display"
|
|
36936
|
+
};
|
|
36937
|
+
var HOST_FLOORS = {
|
|
36938
|
+
[HOST_FEATURE.ModelSwitch]: {
|
|
36939
|
+
label: "model-switch protection",
|
|
36940
|
+
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
36941
|
+
since: "2.1.251"
|
|
36942
|
+
},
|
|
36943
|
+
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
36944
|
+
label: "vault pointer display",
|
|
36945
|
+
hookEvents: ["MessageDisplay"],
|
|
36946
|
+
since: "2.1.152"
|
|
36947
|
+
}
|
|
36948
|
+
};
|
|
36949
|
+
|
|
36711
36950
|
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
36712
36951
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
36713
|
-
import { readFileSync as
|
|
36714
|
-
import { join as
|
|
36952
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
36953
|
+
import { join as join19 } from "path";
|
|
36715
36954
|
|
|
36716
36955
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
36717
36956
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
@@ -36742,22 +36981,9 @@ function resolveInventoryContext(input2) {
|
|
|
36742
36981
|
return ctx;
|
|
36743
36982
|
}
|
|
36744
36983
|
|
|
36745
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
36746
|
-
import {
|
|
36747
|
-
closeSync as closeSync2,
|
|
36748
|
-
fstatSync,
|
|
36749
|
-
mkdirSync as mkdirSync2,
|
|
36750
|
-
openSync as openSync2,
|
|
36751
|
-
readFileSync as readFileSync11,
|
|
36752
|
-
readSync,
|
|
36753
|
-
writeFileSync as writeFileSync5
|
|
36754
|
-
} from "fs";
|
|
36755
|
-
import { join as join17 } from "path";
|
|
36756
|
-
var TAIL_BYTES = 256 * 1024;
|
|
36757
|
-
|
|
36758
36984
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
36759
|
-
import { mkdirSync as mkdirSync3, readFileSync as
|
|
36760
|
-
import { join as
|
|
36985
|
+
import { mkdirSync as mkdirSync3, readFileSync as readFileSync13, writeFileSync as writeFileSync6 } from "fs";
|
|
36986
|
+
import { join as join20 } from "path";
|
|
36761
36987
|
|
|
36762
36988
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
36763
36989
|
import { readdirSync as readdirSync3, realpathSync as realpathSync3 } from "fs";
|
|
@@ -36799,8 +37025,8 @@ function createPolicyResolver(bundle) {
|
|
|
36799
37025
|
}
|
|
36800
37026
|
|
|
36801
37027
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
36802
|
-
import { existsSync as
|
|
36803
|
-
import { basename as basename5, join as
|
|
37028
|
+
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
37029
|
+
import { basename as basename5, join as join21 } from "path";
|
|
36804
37030
|
|
|
36805
37031
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
36806
37032
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -36836,7 +37062,7 @@ var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
|
36836
37062
|
|
|
36837
37063
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
36838
37064
|
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
36839
|
-
import { join as
|
|
37065
|
+
import { join as join22 } from "path";
|
|
36840
37066
|
|
|
36841
37067
|
// ../../packages/plugin-sdk/src/tokenize.ts
|
|
36842
37068
|
function redactedPlaceholder(category) {
|
|
@@ -37151,43 +37377,6 @@ var UNOPENABLE_VAULT = {
|
|
|
37151
37377
|
resolvePointerIdentity: () => Promise.resolve(null)
|
|
37152
37378
|
};
|
|
37153
37379
|
|
|
37154
|
-
// ../../packages/plugin-runtime/src/attached/egress-wire.ts
|
|
37155
|
-
import { createHash as createHash5 } from "crypto";
|
|
37156
|
-
function hashProjectKey(projectKey) {
|
|
37157
|
-
return createHash5("sha256").update(projectKey, "utf8").digest("hex");
|
|
37158
|
-
}
|
|
37159
|
-
function toIngestHit(hit) {
|
|
37160
|
-
return {
|
|
37161
|
-
host: hit.host,
|
|
37162
|
-
kind: hit.kind,
|
|
37163
|
-
name: hit.name,
|
|
37164
|
-
category: hit.category,
|
|
37165
|
-
trust: hit.trust,
|
|
37166
|
-
network: hit.network,
|
|
37167
|
-
method: hit.method,
|
|
37168
|
-
transport: hit.transport,
|
|
37169
|
-
url: hit.url,
|
|
37170
|
-
template: hit.template,
|
|
37171
|
-
dataClass: hit.dataClass,
|
|
37172
|
-
site: {
|
|
37173
|
-
file: hit.site.file,
|
|
37174
|
-
line: hit.site.line,
|
|
37175
|
-
dynamic: hit.site.dynamic,
|
|
37176
|
-
vendored: hit.site.vendored
|
|
37177
|
-
}
|
|
37178
|
-
};
|
|
37179
|
-
}
|
|
37180
|
-
function toEgressIngestRequest(input2) {
|
|
37181
|
-
const { hits, droppedFiles } = capHits(input2.hits, input2.reconcile.mode);
|
|
37182
|
-
const reconcile = withoutDroppedFiles(input2.reconcile, droppedFiles);
|
|
37183
|
-
return {
|
|
37184
|
-
projectKey: hashProjectKey(input2.projectKey),
|
|
37185
|
-
project: input2.project,
|
|
37186
|
-
reconcile,
|
|
37187
|
-
hits: hits.map(toIngestHit)
|
|
37188
|
-
};
|
|
37189
|
-
}
|
|
37190
|
-
|
|
37191
37380
|
// ../../packages/remote/src/http.ts
|
|
37192
37381
|
import { request as httpRequest } from "http";
|
|
37193
37382
|
import { request as httpsRequest } from "https";
|
|
@@ -37467,6 +37656,7 @@ function createRemoteClient(options) {
|
|
|
37467
37656
|
url: url2(ROUTES.shares),
|
|
37468
37657
|
body: JSON.stringify(validated.data)
|
|
37469
37658
|
});
|
|
37659
|
+
if (response.status === 404) throw new RemoteRouteAbsent(ROUTES.shares);
|
|
37470
37660
|
okBody(response);
|
|
37471
37661
|
},
|
|
37472
37662
|
async pollCommand() {
|
|
@@ -37489,19 +37679,51 @@ function createRemoteClient(options) {
|
|
|
37489
37679
|
};
|
|
37490
37680
|
}
|
|
37491
37681
|
|
|
37492
|
-
// ../../packages/
|
|
37682
|
+
// ../../packages/remote/src/failure-kind.ts
|
|
37493
37683
|
function statusOf(err) {
|
|
37494
37684
|
if (typeof err !== "object" || err === null || !("status" in err)) return null;
|
|
37495
37685
|
const { status } = err;
|
|
37496
37686
|
if (typeof status !== "number" || !Number.isInteger(status)) return null;
|
|
37497
37687
|
return status >= 100 && status <= 599 ? status : null;
|
|
37498
37688
|
}
|
|
37499
|
-
function
|
|
37500
|
-
|
|
37689
|
+
function nameOf(err) {
|
|
37690
|
+
if (typeof err !== "object" || err === null || !("name" in err)) return null;
|
|
37691
|
+
return typeof err.name === "string" ? err.name : null;
|
|
37692
|
+
}
|
|
37693
|
+
function classifyRemoteFailure(err) {
|
|
37694
|
+
switch (nameOf(err)) {
|
|
37695
|
+
case "RemoteRouteAbsent":
|
|
37696
|
+
return "route-absent";
|
|
37697
|
+
case "RemoteRequestInvalid":
|
|
37698
|
+
return "invalid-request";
|
|
37699
|
+
case "RemoteResponseInvalid":
|
|
37700
|
+
return "rejected";
|
|
37701
|
+
default:
|
|
37702
|
+
break;
|
|
37703
|
+
}
|
|
37704
|
+
const status = statusOf(err);
|
|
37705
|
+
if (status === null) return "unreachable";
|
|
37706
|
+
switch (status) {
|
|
37501
37707
|
case 401:
|
|
37502
37708
|
return "unauthorized";
|
|
37503
37709
|
case 403:
|
|
37504
37710
|
return "forbidden";
|
|
37711
|
+
case 429:
|
|
37712
|
+
return "unreachable";
|
|
37713
|
+
case 404:
|
|
37714
|
+
return "unreachable";
|
|
37715
|
+
default:
|
|
37716
|
+
return status >= 400 && status <= 499 ? "rejected" : "unreachable";
|
|
37717
|
+
}
|
|
37718
|
+
}
|
|
37719
|
+
|
|
37720
|
+
// ../../packages/plugin-runtime/src/attached/failure.ts
|
|
37721
|
+
function classifyFailure(err) {
|
|
37722
|
+
switch (classifyRemoteFailure(err)) {
|
|
37723
|
+
case "unauthorized":
|
|
37724
|
+
return "unauthorized";
|
|
37725
|
+
case "forbidden":
|
|
37726
|
+
return "forbidden";
|
|
37505
37727
|
default:
|
|
37506
37728
|
return "unreachable";
|
|
37507
37729
|
}
|
|
@@ -37523,11 +37745,11 @@ function withTimeout(promise2, ms) {
|
|
|
37523
37745
|
}
|
|
37524
37746
|
|
|
37525
37747
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
37526
|
-
import { readFileSync as
|
|
37527
|
-
import { join as
|
|
37748
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
37749
|
+
import { join as join23 } from "path";
|
|
37528
37750
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
37529
37751
|
function forwardDropsPath(dataDir2) {
|
|
37530
|
-
return
|
|
37752
|
+
return join23(dataDir2, FORWARD_DROPS_FILENAME);
|
|
37531
37753
|
}
|
|
37532
37754
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
37533
37755
|
if (count <= 0) return;
|
|
@@ -37545,7 +37767,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
37545
37767
|
}
|
|
37546
37768
|
function readForwardDrops(dataDir2) {
|
|
37547
37769
|
try {
|
|
37548
|
-
const parsed2 = JSON.parse(
|
|
37770
|
+
const parsed2 = JSON.parse(readFileSync14(forwardDropsPath(dataDir2), "utf8"));
|
|
37549
37771
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
37550
37772
|
const record2 = parsed2;
|
|
37551
37773
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -37563,9 +37785,9 @@ function readForwardDrops(dataDir2) {
|
|
|
37563
37785
|
|
|
37564
37786
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
37565
37787
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
37566
|
-
import { readFileSync as
|
|
37788
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
37567
37789
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
37568
|
-
import { join as
|
|
37790
|
+
import { join as join24 } from "path";
|
|
37569
37791
|
function isInvalidRequest(err) {
|
|
37570
37792
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
37571
37793
|
}
|
|
@@ -37603,7 +37825,7 @@ function parseBreakerState(raw, nowMs) {
|
|
|
37603
37825
|
}
|
|
37604
37826
|
function createForwardPolicy(deps) {
|
|
37605
37827
|
const now = deps.now ?? (() => Date.now());
|
|
37606
|
-
const file2 =
|
|
37828
|
+
const file2 = join24(deps.dir, STATE_FILENAME);
|
|
37607
37829
|
let state = null;
|
|
37608
37830
|
let loading = null;
|
|
37609
37831
|
async function readState() {
|
|
@@ -38325,8 +38547,8 @@ function toolAuditEvent(input2) {
|
|
|
38325
38547
|
}
|
|
38326
38548
|
|
|
38327
38549
|
// ../../packages/plugin-runtime/src/attached/history-state.ts
|
|
38328
|
-
import { readFileSync as
|
|
38329
|
-
import { join as
|
|
38550
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
38551
|
+
import { join as join25 } from "path";
|
|
38330
38552
|
|
|
38331
38553
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
38332
38554
|
import { createHash as createHash6 } from "crypto";
|
|
@@ -38343,14 +38565,14 @@ import { fileURLToPath as fileURLToPath2 } from "url";
|
|
|
38343
38565
|
var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
38344
38566
|
|
|
38345
38567
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
38346
|
-
import { readFileSync as
|
|
38568
|
+
import { readFileSync as readFileSync17 } from "fs";
|
|
38347
38569
|
var manifestBuildCache = /* @__PURE__ */ new Map();
|
|
38348
38570
|
function readManifestBuild(manifestUrl, packageName) {
|
|
38349
38571
|
const key = manifestUrl.href;
|
|
38350
38572
|
if (!manifestBuildCache.has(key)) {
|
|
38351
38573
|
let build;
|
|
38352
38574
|
try {
|
|
38353
|
-
const manifest = JSON.parse(
|
|
38575
|
+
const manifest = JSON.parse(readFileSync17(manifestUrl, "utf8"));
|
|
38354
38576
|
build = typeof manifest.version === "string" && manifest.version.length > 0 ? { package: packageName, version: manifest.version } : void 0;
|
|
38355
38577
|
} catch {
|
|
38356
38578
|
build = void 0;
|
|
@@ -38377,7 +38599,7 @@ function createPluginBlock(build, policyStore) {
|
|
|
38377
38599
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
38378
38600
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
38379
38601
|
import { readFile as readFile2, rm, writeFile as writeFile2 } from "fs/promises";
|
|
38380
|
-
import { join as
|
|
38602
|
+
import { join as join26 } from "path";
|
|
38381
38603
|
|
|
38382
38604
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
38383
38605
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -38401,7 +38623,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
38401
38623
|
|
|
38402
38624
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
38403
38625
|
function createPolicyStore(dir = dataDir()) {
|
|
38404
|
-
const file2 =
|
|
38626
|
+
const file2 = join26(dir, "policy-cache.json");
|
|
38405
38627
|
async function read() {
|
|
38406
38628
|
try {
|
|
38407
38629
|
const raw = await readFile2(file2, "utf8");
|
|
@@ -38632,11 +38854,11 @@ function readStorePosture(dbPath2) {
|
|
|
38632
38854
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
38633
38855
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
38634
38856
|
import { readFile as readFile3, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
38635
|
-
import { join as
|
|
38857
|
+
import { join as join27 } from "path";
|
|
38636
38858
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
38637
38859
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
38638
|
-
const file2 =
|
|
38639
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
38860
|
+
const file2 = join27(dir, "posture-state.json");
|
|
38861
|
+
const legacyFile = legacyDir === void 0 ? null : join27(legacyDir, "posture-state.json");
|
|
38640
38862
|
async function persist(state) {
|
|
38641
38863
|
await ensureDataDir(dir);
|
|
38642
38864
|
const tmp = `${file2}.${randomUUID17()}.tmp`;
|
|
@@ -38704,8 +38926,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
38704
38926
|
}
|
|
38705
38927
|
|
|
38706
38928
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
38707
|
-
import { readFileSync as
|
|
38708
|
-
import { join as
|
|
38929
|
+
import { readFileSync as readFileSync18 } from "fs";
|
|
38930
|
+
import { join as join28 } from "path";
|
|
38709
38931
|
|
|
38710
38932
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
38711
38933
|
var REFUSAL_LINES = {
|
|
@@ -39186,21 +39408,21 @@ function pluginBuild() {
|
|
|
39186
39408
|
import {
|
|
39187
39409
|
lstatSync as lstatSync4,
|
|
39188
39410
|
readdirSync as readdirSync6,
|
|
39189
|
-
readFileSync as
|
|
39411
|
+
readFileSync as readFileSync20,
|
|
39190
39412
|
realpathSync as realpathSync4,
|
|
39191
39413
|
renameSync as renameSync5,
|
|
39192
39414
|
rmSync as rmSync7,
|
|
39193
39415
|
statSync as statSync10,
|
|
39194
39416
|
writeFileSync as writeFileSync8
|
|
39195
39417
|
} from "fs";
|
|
39196
|
-
import { basename as basename6, dirname as dirname6, isAbsolute as isAbsolute2, join as
|
|
39418
|
+
import { basename as basename6, dirname as dirname6, isAbsolute as isAbsolute2, join as join30, relative, resolve as resolve2 } from "path";
|
|
39197
39419
|
|
|
39198
39420
|
// src/history/transcripts.ts
|
|
39199
|
-
import { readdirSync as readdirSync5, readFileSync as
|
|
39421
|
+
import { readdirSync as readdirSync5, readFileSync as readFileSync19 } from "fs";
|
|
39200
39422
|
import { homedir as homedir3 } from "os";
|
|
39201
|
-
import { join as
|
|
39423
|
+
import { join as join29 } from "path";
|
|
39202
39424
|
function transcriptsDir(home) {
|
|
39203
|
-
return
|
|
39425
|
+
return join29(home ?? homedir3(), ".claude", "projects");
|
|
39204
39426
|
}
|
|
39205
39427
|
function isRecord(value) {
|
|
39206
39428
|
return typeof value === "object" && value !== null;
|
|
@@ -39433,13 +39655,13 @@ import {
|
|
|
39433
39655
|
fstatSync as fstatSync2,
|
|
39434
39656
|
mkdirSync as mkdirSync5,
|
|
39435
39657
|
openSync as openSync3,
|
|
39436
|
-
readFileSync as
|
|
39658
|
+
readFileSync as readFileSync21,
|
|
39437
39659
|
readSync as readSync2,
|
|
39438
39660
|
writeFileSync as writeFileSync9
|
|
39439
39661
|
} from "fs";
|
|
39440
|
-
import { join as
|
|
39662
|
+
import { join as join31 } from "path";
|
|
39441
39663
|
function offsetsDir(dataDir2) {
|
|
39442
|
-
return
|
|
39664
|
+
return join31(dataDir2, "usage-offsets");
|
|
39443
39665
|
}
|
|
39444
39666
|
var SAFE_SESSION_ID = /^[A-Za-z0-9._-]+$/;
|
|
39445
39667
|
function safeSessionId(sessionId) {
|
|
@@ -39449,11 +39671,11 @@ function safeSessionId(sessionId) {
|
|
|
39449
39671
|
return createHash7("sha256").update(sessionId).digest("hex");
|
|
39450
39672
|
}
|
|
39451
39673
|
function offsetPath(dataDir2, sessionId) {
|
|
39452
|
-
return
|
|
39674
|
+
return join31(offsetsDir(dataDir2), safeSessionId(sessionId));
|
|
39453
39675
|
}
|
|
39454
39676
|
function readOffset(dataDir2, sessionId) {
|
|
39455
39677
|
try {
|
|
39456
|
-
const raw =
|
|
39678
|
+
const raw = readFileSync21(offsetPath(dataDir2, sessionId), "utf8");
|
|
39457
39679
|
const parsed2 = JSON.parse(raw);
|
|
39458
39680
|
if (typeof parsed2 === "object" && parsed2 !== null) {
|
|
39459
39681
|
const rec = parsed2;
|
|
@@ -39511,7 +39733,7 @@ function readTail(transcriptPath, startOffset) {
|
|
|
39511
39733
|
}
|
|
39512
39734
|
|
|
39513
39735
|
// src/history/tail-scrub.ts
|
|
39514
|
-
import { readFileSync as
|
|
39736
|
+
import { readFileSync as readFileSync22, renameSync as renameSync6, rmSync as rmSync8, statSync as statSync11, writeFileSync as writeFileSync10 } from "fs";
|
|
39515
39737
|
var DEFAULT_MAX_SCRUB_BYTES = 32 * 1024 * 1024;
|
|
39516
39738
|
async function scrubTranscriptTail(filePath, deps) {
|
|
39517
39739
|
try {
|
|
@@ -39519,7 +39741,7 @@ async function scrubTranscriptTail(filePath, deps) {
|
|
|
39519
39741
|
if (realPath === null) return null;
|
|
39520
39742
|
const statBefore = statSync11(realPath);
|
|
39521
39743
|
if (statBefore.size > (deps.maxBytes ?? DEFAULT_MAX_SCRUB_BYTES)) return null;
|
|
39522
|
-
const content =
|
|
39744
|
+
const content = readFileSync22(realPath, "utf8");
|
|
39523
39745
|
const lines = content.split("\n");
|
|
39524
39746
|
let rewritten = 0;
|
|
39525
39747
|
for (const [i, line] of lines.entries()) {
|