@akasecurity/ai-tc-codex 0.9.16 → 0.9.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/package.json +6 -6
- package/scripts/apply-suppressions.js +739 -1263
- package/scripts/backfill.js +1040 -1291
- package/scripts/content-retention.js +781 -2074
- package/scripts/filescan.js +1266 -497
- package/scripts/firstrun.js +1277 -1701
- package/scripts/history-sync.js +777 -2107
- package/scripts/intro.js +141 -2190
- package/scripts/onboard.js +2806 -1186
- package/scripts/post-tool-use.js +1512 -1728
- package/scripts/pre-tool-use.js +1094 -1319
- package/scripts/query.js +1277 -1701
- package/scripts/reconcile.js +897 -1288
- package/scripts/remediate.js +1081 -1341
- package/scripts/scan-worker.js +147 -14
- package/scripts/session-start.js +1895 -827
- package/scripts/start-light.js +176 -1360
- package/scripts/stop.js +322 -1113
- package/scripts/sync.js +1818 -1029
- package/scripts/user-prompt-submit.js +1295 -1489
package/scripts/filescan.js
CHANGED
|
@@ -716,13 +716,13 @@ var require_ignore = __commonJS({
|
|
|
716
716
|
const rules = this._rules;
|
|
717
717
|
const { length } = rules;
|
|
718
718
|
const shortcut = this._basenameCount * 2 >= length;
|
|
719
|
-
const
|
|
719
|
+
const basename6 = shortcut ? basenameOf(path) : path;
|
|
720
720
|
for (let index = 0; index < length; index++) {
|
|
721
721
|
const rule = rules[index];
|
|
722
722
|
const { negative } = rule;
|
|
723
723
|
const skip = unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored;
|
|
724
724
|
if (!skip && rule[mode].test(
|
|
725
|
-
shortcut && rule._basenameOnly ?
|
|
725
|
+
shortcut && rule._basenameOnly ? basename6 : path
|
|
726
726
|
)) {
|
|
727
727
|
ignored = !negative;
|
|
728
728
|
unignored = negative;
|
|
@@ -874,19 +874,7 @@ var require_ignore = __commonJS({
|
|
|
874
874
|
|
|
875
875
|
// ../../packages/plugin-sdk/src/config.ts
|
|
876
876
|
import { existsSync as existsSync8 } from "fs";
|
|
877
|
-
import { join as
|
|
878
|
-
|
|
879
|
-
// ../../packages/persistence/src/attached-derived.ts
|
|
880
|
-
import { rmSync } from "fs";
|
|
881
|
-
import { join } from "path";
|
|
882
|
-
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
883
|
-
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
884
|
-
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
885
|
-
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
886
|
-
|
|
887
|
-
// ../../packages/persistence/src/control-plane-credential.ts
|
|
888
|
-
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
889
|
-
import { join as join2 } from "path";
|
|
877
|
+
import { join as join17 } from "path";
|
|
890
878
|
|
|
891
879
|
// ../../packages/schema/src/drizzle/deferred-migrations.ts
|
|
892
880
|
var DEFERRED_MIGRATION_TAGS = [
|
|
@@ -1059,7 +1047,7 @@ var MAX_TEMPORARY_MS = 24 * HOUR_MS;
|
|
|
1059
1047
|
var ONCE_BACKSTOP_MS = 30 * MINUTE_MS;
|
|
1060
1048
|
|
|
1061
1049
|
// ../../packages/schema/src/invisible-padding.ts
|
|
1062
|
-
var INVISIBLE_PADDING = /[\u00AD\u200B\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
1050
|
+
var INVISIBLE_PADDING = /[\u00AD\u061C\u180E\u200B\u200E\u200F\u2060-\u2064\u202A-\u202E\u2066-\u2069\uFEFF\uFFF9-\uFFFB\u{E0001}\u{E0020}-\u{E007F}]/gu;
|
|
1063
1051
|
function stripInvisiblePadding(text) {
|
|
1064
1052
|
return text.replace(INVISIBLE_PADDING, "");
|
|
1065
1053
|
}
|
|
@@ -3877,9 +3865,9 @@ var asciiTabOrNewline = /[\t\n\r]/g;
|
|
|
3877
3865
|
function stripTabAndNewline(value) {
|
|
3878
3866
|
return value.replace(asciiTabOrNewline, "");
|
|
3879
3867
|
}
|
|
3880
|
-
function urlHostnameOk(url2,
|
|
3881
|
-
|
|
3882
|
-
return
|
|
3868
|
+
function urlHostnameOk(url2, hostname6) {
|
|
3869
|
+
hostname6.lastIndex = 0;
|
|
3870
|
+
return hostname6.test(url2.hostname);
|
|
3883
3871
|
}
|
|
3884
3872
|
function urlProtocolOk(url2, protocol) {
|
|
3885
3873
|
protocol.lastIndex = 0;
|
|
@@ -20799,13 +20787,16 @@ function serviceTierMultiplier(tier) {
|
|
|
20799
20787
|
if (tier === void 0) return 1;
|
|
20800
20788
|
return SERVICE_TIER_MULTIPLIERS.get(tier) ?? 1;
|
|
20801
20789
|
}
|
|
20790
|
+
function promptTokensOf(usage) {
|
|
20791
|
+
return usage.promptTokens ?? (usage.inputTokens ?? 0) + (usage.cacheReadTokens ?? 0) + (usage.cacheWrite1hTokens ?? 0) + (usage.cacheWrite5mTokens ?? 0);
|
|
20792
|
+
}
|
|
20802
20793
|
function costOf(price, usage) {
|
|
20803
20794
|
const metered = [
|
|
20804
20795
|
[usage.cacheWrite1hTokens ?? 0, price.cacheWrite1h],
|
|
20805
20796
|
[usage.cacheWrite5mTokens ?? 0, price.cacheWrite5m],
|
|
20806
20797
|
[usage.cacheReadTokens ?? 0, price.cacheRead]
|
|
20807
20798
|
];
|
|
20808
|
-
const band = price.longContext !== null && (usage
|
|
20799
|
+
const band = price.longContext !== null && promptTokensOf(usage) > price.longContext.thresholdInputTokens ? price.longContext : null;
|
|
20809
20800
|
if (band !== null && (band.input === null || band.output === null)) return null;
|
|
20810
20801
|
const inputRate = band?.input ?? price.input;
|
|
20811
20802
|
const outputRate = band?.output ?? price.output;
|
|
@@ -20878,8 +20869,8 @@ var PLATFORM_HOSTING = /* @__PURE__ */ new Map([
|
|
|
20878
20869
|
["ollama", "local"],
|
|
20879
20870
|
["local", "local"]
|
|
20880
20871
|
]);
|
|
20881
|
-
function hostingFor(
|
|
20882
|
-
return PLATFORM_HOSTING.get(
|
|
20872
|
+
function hostingFor(platform) {
|
|
20873
|
+
return PLATFORM_HOSTING.get(platform) ?? "api";
|
|
20883
20874
|
}
|
|
20884
20875
|
var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
20885
20876
|
["anthropic", "anthropic"],
|
|
@@ -20893,8 +20884,8 @@ var FIRST_PARTY = /* @__PURE__ */ new Map([
|
|
|
20893
20884
|
function firstPartyPlatformFor(vendor2) {
|
|
20894
20885
|
return FIRST_PARTY.get(vendor2) ?? null;
|
|
20895
20886
|
}
|
|
20896
|
-
function isFirstParty(vendor2,
|
|
20897
|
-
return FIRST_PARTY.get(vendor2) ===
|
|
20887
|
+
function isFirstParty(vendor2, platform) {
|
|
20888
|
+
return FIRST_PARTY.get(vendor2) === platform;
|
|
20898
20889
|
}
|
|
20899
20890
|
var PLATFORM_NAMESPACES = Object.freeze([
|
|
20900
20891
|
"anthropic",
|
|
@@ -20955,14 +20946,14 @@ var ModelVendorBuilder = class {
|
|
|
20955
20946
|
);
|
|
20956
20947
|
}
|
|
20957
20948
|
for (const ref of spec.on ?? []) {
|
|
20958
|
-
const { platform
|
|
20959
|
-
const firstParty = isFirstParty(this.vendor,
|
|
20960
|
-
const hosting = hostingFor(
|
|
20949
|
+
const { platform, price, retention, region } = normalizeRef(ref);
|
|
20950
|
+
const firstParty = isFirstParty(this.vendor, platform);
|
|
20951
|
+
const hosting = hostingFor(platform);
|
|
20961
20952
|
const isSelfHosted = hosting === "local";
|
|
20962
20953
|
platforms.set(
|
|
20963
|
-
|
|
20954
|
+
platform,
|
|
20964
20955
|
Object.freeze({
|
|
20965
|
-
platform
|
|
20956
|
+
platform,
|
|
20966
20957
|
hosting,
|
|
20967
20958
|
firstParty,
|
|
20968
20959
|
price: price ?? (isSelfHosted ? ZERO_PRICE : firstParty ? spec.price ?? null : null),
|
|
@@ -21015,35 +21006,35 @@ var GATEWAY_VENDOR_SLASH_RE = /^[a-z0-9][\w.-]*\//iu;
|
|
|
21015
21006
|
var BEDROCK_VERSION_RE = /-v\d+:\d+$/u;
|
|
21016
21007
|
var BEDROCK_REVISION_RE = /:\d+$/u;
|
|
21017
21008
|
var VERTEX_VERSION_RE = /@[\w-]+$/u;
|
|
21018
|
-
var DATED_SUFFIX_RE =
|
|
21009
|
+
var DATED_SUFFIX_RE = /-(?:\d{8}|\d{4}-\d{2}-\d{2})$/u;
|
|
21019
21010
|
function stripPlatformDecorations(model) {
|
|
21020
21011
|
let id = model.trim();
|
|
21021
|
-
let
|
|
21012
|
+
let platform = null;
|
|
21022
21013
|
if (GEO_PREFIX_RE.test(id)) {
|
|
21023
21014
|
id = id.replace(GEO_PREFIX_RE, "");
|
|
21024
|
-
|
|
21015
|
+
platform = "bedrock";
|
|
21025
21016
|
}
|
|
21026
21017
|
if (NAMESPACE_DOT_RE.test(id)) {
|
|
21027
21018
|
id = id.replace(NAMESPACE_DOT_RE, "");
|
|
21028
|
-
|
|
21019
|
+
platform ??= "bedrock";
|
|
21029
21020
|
}
|
|
21030
21021
|
if (BEDROCK_VERSION_RE.test(id)) {
|
|
21031
21022
|
id = id.replace(BEDROCK_VERSION_RE, "");
|
|
21032
|
-
|
|
21023
|
+
platform ??= "bedrock";
|
|
21033
21024
|
} else if (BEDROCK_REVISION_RE.test(id)) {
|
|
21034
21025
|
id = id.replace(BEDROCK_REVISION_RE, "");
|
|
21035
|
-
|
|
21026
|
+
platform ??= "bedrock";
|
|
21036
21027
|
}
|
|
21037
21028
|
if (VERTEX_VERSION_RE.test(id)) {
|
|
21038
21029
|
id = id.replace(VERTEX_VERSION_RE, "");
|
|
21039
|
-
|
|
21030
|
+
platform ??= "vertex";
|
|
21040
21031
|
}
|
|
21041
21032
|
if (NAMESPACE_SLASH_RE.test(id)) {
|
|
21042
21033
|
id = id.replace(NAMESPACE_SLASH_RE, "");
|
|
21043
21034
|
} else if (GATEWAY_VENDOR_SLASH_RE.test(id)) {
|
|
21044
21035
|
id = id.replace(GATEWAY_VENDOR_SLASH_RE, "");
|
|
21045
21036
|
}
|
|
21046
|
-
return { id, platform
|
|
21037
|
+
return { id, platform };
|
|
21047
21038
|
}
|
|
21048
21039
|
function buildModelIndex(entries) {
|
|
21049
21040
|
const byId = /* @__PURE__ */ new Map();
|
|
@@ -21060,19 +21051,19 @@ function resolveModel(raw, index) {
|
|
|
21060
21051
|
if (exact !== void 0) {
|
|
21061
21052
|
return { entry: exact, canonicalId: raw, platform: null, raw };
|
|
21062
21053
|
}
|
|
21063
|
-
const { id, platform
|
|
21054
|
+
const { id, platform } = stripPlatformDecorations(raw);
|
|
21064
21055
|
const stripped = index.byId.get(id);
|
|
21065
21056
|
if (stripped !== void 0) {
|
|
21066
|
-
return { entry: stripped, canonicalId: id, platform
|
|
21057
|
+
return { entry: stripped, canonicalId: id, platform, raw };
|
|
21067
21058
|
}
|
|
21068
21059
|
if (DATED_SUFFIX_RE.test(id)) {
|
|
21069
21060
|
const undated = id.replace(DATED_SUFFIX_RE, "");
|
|
21070
21061
|
const byDate = index.byId.get(undated);
|
|
21071
21062
|
if (byDate !== void 0) {
|
|
21072
|
-
return { entry: byDate, canonicalId: undated, platform
|
|
21063
|
+
return { entry: byDate, canonicalId: undated, platform, raw };
|
|
21073
21064
|
}
|
|
21074
21065
|
}
|
|
21075
|
-
return { entry: null, canonicalId: raw, platform
|
|
21066
|
+
return { entry: null, canonicalId: raw, platform, raw };
|
|
21076
21067
|
}
|
|
21077
21068
|
|
|
21078
21069
|
// ../../packages/schema/src/model/catalog.ts
|
|
@@ -21165,7 +21156,7 @@ anthropic.model("claude-haiku-4-5", {
|
|
|
21165
21156
|
name: "Claude Haiku 4.5",
|
|
21166
21157
|
ctx: 2e5,
|
|
21167
21158
|
maxOut: 64e3,
|
|
21168
|
-
// Reviewed: fast/cheap tier,
|
|
21159
|
+
// Reviewed: fast/cheap general-purpose tier, not a reasoning or code model.
|
|
21169
21160
|
capability: null,
|
|
21170
21161
|
price: anthropicPrice(1, 5, 0.1),
|
|
21171
21162
|
// The vendor documents `claude-haiku-4-5-20251001` as the versioned id and
|
|
@@ -21296,6 +21287,11 @@ openai.model("gpt-4o", {
|
|
|
21296
21287
|
price: tokenPrice(2.5, 10, { cacheRead: 1.25 }),
|
|
21297
21288
|
on: [...OPENAI_RESELLERS]
|
|
21298
21289
|
});
|
|
21290
|
+
openai.model("gpt-4o-2024-05-13", {
|
|
21291
|
+
name: "GPT-4o (2024-05-13)",
|
|
21292
|
+
price: tokenPrice(5, 15),
|
|
21293
|
+
on: [...OPENAI_RESELLERS]
|
|
21294
|
+
});
|
|
21299
21295
|
openai.model("gpt-4o-mini", {
|
|
21300
21296
|
name: "GPT-4o mini",
|
|
21301
21297
|
price: tokenPrice(0.15, 0.6, { cacheRead: 0.075 }),
|
|
@@ -21315,6 +21311,24 @@ openai.model("o3", {
|
|
|
21315
21311
|
price: tokenPrice(2, 8, { cacheRead: 0.5 }),
|
|
21316
21312
|
on: [...OPENAI_RESELLERS]
|
|
21317
21313
|
});
|
|
21314
|
+
openai.model("text-embedding-3-small", {
|
|
21315
|
+
name: "text-embedding-3-small",
|
|
21316
|
+
capability: "embedding",
|
|
21317
|
+
price: tokenPrice(0.02, 0),
|
|
21318
|
+
on: [...OPENAI_RESELLERS]
|
|
21319
|
+
});
|
|
21320
|
+
openai.model("text-embedding-3-large", {
|
|
21321
|
+
name: "text-embedding-3-large",
|
|
21322
|
+
capability: "embedding",
|
|
21323
|
+
price: tokenPrice(0.13, 0),
|
|
21324
|
+
on: [...OPENAI_RESELLERS]
|
|
21325
|
+
});
|
|
21326
|
+
openai.model("text-embedding-ada-002", {
|
|
21327
|
+
name: "text-embedding-ada-002",
|
|
21328
|
+
capability: "embedding",
|
|
21329
|
+
price: tokenPrice(0.1, 0),
|
|
21330
|
+
on: [...OPENAI_RESELLERS]
|
|
21331
|
+
});
|
|
21318
21332
|
openai.model("gpt-oss-120b", {
|
|
21319
21333
|
name: "GPT-OSS 120B",
|
|
21320
21334
|
openWeights: true,
|
|
@@ -21601,10 +21615,21 @@ var MODEL_ENTRIES = Object.freeze([
|
|
|
21601
21615
|
...alibaba.models(),
|
|
21602
21616
|
...amazon.models()
|
|
21603
21617
|
]);
|
|
21618
|
+
var LONG_CONTEXT_THRESHOLDS = Object.freeze(
|
|
21619
|
+
[
|
|
21620
|
+
...new Set(
|
|
21621
|
+
MODEL_ENTRIES.flatMap(
|
|
21622
|
+
(entry) => [...entry.platforms.values()].flatMap(
|
|
21623
|
+
(offering) => offering.price?.longContext ? [offering.price.longContext.thresholdInputTokens] : []
|
|
21624
|
+
)
|
|
21625
|
+
)
|
|
21626
|
+
)
|
|
21627
|
+
].sort((a, b) => a - b)
|
|
21628
|
+
);
|
|
21604
21629
|
var MODEL_INDEX = buildModelIndex(MODEL_ENTRIES);
|
|
21605
21630
|
|
|
21606
21631
|
// ../../packages/schema/src/model/governance.ts
|
|
21607
|
-
var ModelCapability = external_exports.enum(["reasoning", "code"]);
|
|
21632
|
+
var ModelCapability = external_exports.enum(["reasoning", "code", "embedding"]);
|
|
21608
21633
|
var DataRetention = external_exports.enum([
|
|
21609
21634
|
"zero_retention",
|
|
21610
21635
|
"no_storage",
|
|
@@ -21700,16 +21725,16 @@ function platformForProvider(provider) {
|
|
|
21700
21725
|
return PROVIDER_PLATFORM.get(provider.trim().toLowerCase()) ?? null;
|
|
21701
21726
|
}
|
|
21702
21727
|
function isLocalProvider(provider) {
|
|
21703
|
-
const
|
|
21704
|
-
return
|
|
21728
|
+
const platform = platformForProvider(provider);
|
|
21729
|
+
return platform !== null && hostingFor(platform) === "local";
|
|
21705
21730
|
}
|
|
21706
21731
|
function priceFor(provider, model) {
|
|
21707
21732
|
if (isLocalProvider(provider)) return ZERO_PRICE;
|
|
21708
21733
|
const resolved = resolveModel(model, MODEL_INDEX);
|
|
21709
21734
|
if (resolved.entry === null) return null;
|
|
21710
|
-
const
|
|
21711
|
-
if (
|
|
21712
|
-
return resolved.entry.platforms.get(
|
|
21735
|
+
const platform = resolved.platform ?? platformForProvider(provider);
|
|
21736
|
+
if (platform === null) return null;
|
|
21737
|
+
return resolved.entry.platforms.get(platform)?.price ?? null;
|
|
21713
21738
|
}
|
|
21714
21739
|
var defaultCostModel = {
|
|
21715
21740
|
normalizeModelId(provider, model) {
|
|
@@ -21735,7 +21760,7 @@ var COMPACT = new Intl.NumberFormat("en-US", {
|
|
|
21735
21760
|
|
|
21736
21761
|
// ../../packages/schema/src/token/token-report.ts
|
|
21737
21762
|
var num = (value) => value ?? 0;
|
|
21738
|
-
function costUsageOf(a) {
|
|
21763
|
+
function costUsageOf(a, promptTokens) {
|
|
21739
21764
|
const usage = {
|
|
21740
21765
|
inputTokens: num(a.input_tokens),
|
|
21741
21766
|
outputTokens: num(a.output_tokens),
|
|
@@ -21745,11 +21770,12 @@ function costUsageOf(a) {
|
|
|
21745
21770
|
webSearchRequests: num(a.web_search_requests)
|
|
21746
21771
|
};
|
|
21747
21772
|
if (a.service_tier !== void 0) usage.serviceTier = a.service_tier;
|
|
21773
|
+
if (promptTokens !== void 0) usage.promptTokens = promptTokens;
|
|
21748
21774
|
return usage;
|
|
21749
21775
|
}
|
|
21750
21776
|
function buildTokenReports(leaves, costModel) {
|
|
21751
21777
|
const bySession = /* @__PURE__ */ new Map();
|
|
21752
|
-
for (const { sessionId, attributes } of leaves) {
|
|
21778
|
+
for (const { sessionId, attributes, promptTokens } of leaves) {
|
|
21753
21779
|
const provider = attributes.provider ?? "unknown";
|
|
21754
21780
|
const model = attributes.model ?? "unknown";
|
|
21755
21781
|
const key = `${provider} ${model}`;
|
|
@@ -21768,7 +21794,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21768
21794
|
cacheCreation: 0,
|
|
21769
21795
|
cacheRead: 0,
|
|
21770
21796
|
costUsd: 0,
|
|
21771
|
-
priced: false
|
|
21797
|
+
priced: false,
|
|
21798
|
+
partial: false
|
|
21772
21799
|
};
|
|
21773
21800
|
rollups.set(key, acc);
|
|
21774
21801
|
}
|
|
@@ -21776,8 +21803,14 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21776
21803
|
acc.output += num(attributes.output_tokens);
|
|
21777
21804
|
acc.cacheCreation += num(attributes.cache_creation_input_tokens);
|
|
21778
21805
|
acc.cacheRead += num(attributes.cache_read_input_tokens);
|
|
21779
|
-
const leafCost = costModel.costFor({
|
|
21780
|
-
|
|
21806
|
+
const leafCost = costModel.costFor({
|
|
21807
|
+
provider,
|
|
21808
|
+
model,
|
|
21809
|
+
usage: costUsageOf(attributes, promptTokens)
|
|
21810
|
+
});
|
|
21811
|
+
if (leafCost === null) {
|
|
21812
|
+
acc.partial = true;
|
|
21813
|
+
} else {
|
|
21781
21814
|
acc.costUsd += leafCost;
|
|
21782
21815
|
acc.priced = true;
|
|
21783
21816
|
}
|
|
@@ -21793,9 +21826,8 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21793
21826
|
const rollupTotal = acc.input + acc.output + acc.cacheCreation + acc.cacheRead;
|
|
21794
21827
|
totalTokens += rollupTotal;
|
|
21795
21828
|
const estimatedCostUsd = acc.priced ? acc.costUsd : null;
|
|
21796
|
-
if (
|
|
21797
|
-
|
|
21798
|
-
} else {
|
|
21829
|
+
if (acc.partial) anyUnpriced = true;
|
|
21830
|
+
if (estimatedCostUsd !== null) {
|
|
21799
21831
|
anyPriced = true;
|
|
21800
21832
|
costUsd += estimatedCostUsd;
|
|
21801
21833
|
}
|
|
@@ -21818,7 +21850,7 @@ function buildTokenReports(leaves, costModel) {
|
|
|
21818
21850
|
totalTokens,
|
|
21819
21851
|
// Σ of the PRICED rollups; null when none had a known price.
|
|
21820
21852
|
estimatedCostUsd: anyPriced ? costUsd : null,
|
|
21821
|
-
// Any
|
|
21853
|
+
// Any call priced to null means the total understates real spend.
|
|
21822
21854
|
costIsPartial: anyUnpriced
|
|
21823
21855
|
});
|
|
21824
21856
|
}
|
|
@@ -22520,6 +22552,11 @@ var CaptureAttributes = external_exports.object({
|
|
|
22520
22552
|
// here too. The full statement is on EventMetadata.redactDegradedTo; it is
|
|
22521
22553
|
// repeated rather than referenced because a store reader opens this file.
|
|
22522
22554
|
redact_degraded_to: ActionTaken.optional(),
|
|
22555
|
+
// Why a capture has no content and no findings: its field was refused
|
|
22556
|
+
// because its bounded scan did not finish (see EventMetadata.scanIncomplete,
|
|
22557
|
+
// whose value this is). Absent on every capture that was scanned, so a
|
|
22558
|
+
// reader can tell a refused row from an empty clean one.
|
|
22559
|
+
scan_incomplete: external_exports.enum(["timeout", "unavailable"]).optional(),
|
|
22523
22560
|
// The scope key this capture was stamped with: the canonical repository
|
|
22524
22561
|
// (`host/owner/repo`) of the path the capture names (a relative path is read
|
|
22525
22562
|
// against its working directory), else of its own working directory, or a
|
|
@@ -22697,8 +22734,9 @@ var SessionTokenReport = external_exports.object({
|
|
|
22697
22734
|
totalTokens: external_exports.number().int().nonnegative(),
|
|
22698
22735
|
// Σ of the PRICED rollups only; null when no rollup had a known price.
|
|
22699
22736
|
estimatedCostUsd: external_exports.number().nullable(),
|
|
22700
|
-
// True whenever any
|
|
22701
|
-
//
|
|
22737
|
+
// True whenever any call priced to null (an unknown provider/model, or a call
|
|
22738
|
+
// over a long-context threshold whose rate is unpublished), so the total
|
|
22739
|
+
// understates real spend — the UI renders `≥ $X` instead of a falsely
|
|
22702
22740
|
// precise figure rather than silently dropping the unpriced calls.
|
|
22703
22741
|
costIsPartial: external_exports.boolean()
|
|
22704
22742
|
});
|
|
@@ -23575,7 +23613,15 @@ var StorePostureSnapshot = external_exports.object({
|
|
|
23575
23613
|
policyCounts: StorePosturePolicyCounts,
|
|
23576
23614
|
// OPTIONAL, not nullable: a reporter that predates this member keeps
|
|
23577
23615
|
// getting its 200 without a payload change.
|
|
23578
|
-
plugin: StorePosturePlugin.optional()
|
|
23616
|
+
plugin: StorePosturePlugin.optional(),
|
|
23617
|
+
// OPTIONAL, and sent only by a scoped attachment, always as `scoped`. A
|
|
23618
|
+
// machine attachment omits it, so its body is byte for byte the one it
|
|
23619
|
+
// sent before this member existed. Absent therefore means machine-wide OR
|
|
23620
|
+
// a reporter older than this member, never "scoped". Both values parse, so
|
|
23621
|
+
// a sender that one day spells `machine` breaks no receiver; any other
|
|
23622
|
+
// value fails the whole snapshot, which is why the reporter sends a
|
|
23623
|
+
// constant and never the raw mode.
|
|
23624
|
+
attachmentMode: AttachmentMode.optional()
|
|
23579
23625
|
}).meta({ id: "StorePostureSnapshot" });
|
|
23580
23626
|
var CAPTURE_VERSION_PREFIX = "capture/";
|
|
23581
23627
|
var RecordAuditEventRequest = AuditEventInput.extend({
|
|
@@ -23852,7 +23898,19 @@ var EventMetadata = external_exports.object({
|
|
|
23852
23898
|
// Both are pinned as behaviour in @akasecurity/plugin-sdk's runtime suite.
|
|
23853
23899
|
// Closing either means moving the reason onto the finding row, which
|
|
23854
23900
|
// already carries its own action.
|
|
23855
|
-
redactDegradedTo: ActionTaken.optional()
|
|
23901
|
+
redactDegradedTo: ActionTaken.optional(),
|
|
23902
|
+
// Set when this capture's field was REFUSED rather than scanned: a hook
|
|
23903
|
+
// bounds the scan of a large field (see `LargeInputScanOptions` in
|
|
23904
|
+
// @akasecurity/plugin-sdk), and a scan that did not finish blocks the
|
|
23905
|
+
// field instead of letting it through unscanned.
|
|
23906
|
+
//
|
|
23907
|
+
// - 'timeout': the bounded scan ran out of time.
|
|
23908
|
+
// - 'unavailable': no worker could run it.
|
|
23909
|
+
//
|
|
23910
|
+
// A refused row stores '' as its content and has no findings, which is
|
|
23911
|
+
// exactly what a clean, empty capture looks like — this marker is the only
|
|
23912
|
+
// thing that tells the two apart. Absent on every capture that was scanned.
|
|
23913
|
+
scanIncomplete: external_exports.enum(["timeout", "unavailable"]).optional()
|
|
23856
23914
|
}).meta({ id: "EventMetadata" });
|
|
23857
23915
|
var Event = external_exports.object({
|
|
23858
23916
|
id: external_exports.guid(),
|
|
@@ -24022,7 +24080,7 @@ var Rule = external_exports.strictObject({
|
|
|
24022
24080
|
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
24023
24081
|
requiresNearby: RequiresNearby.optional(),
|
|
24024
24082
|
examples: external_exports.array(external_exports.string()).optional(),
|
|
24025
|
-
// Whether the matched text is itself sensitive
|
|
24083
|
+
// Whether the matched text is itself sensitive (see RuleEvidence).
|
|
24026
24084
|
evidence: RuleEvidence.optional()
|
|
24027
24085
|
}).meta({ id: "Rule" });
|
|
24028
24086
|
var Author = external_exports.object({
|
|
@@ -24114,7 +24172,13 @@ var DetectionRule = external_exports.object({
|
|
|
24114
24172
|
// Representative matching strings the rule author shipped with the rule. The
|
|
24115
24173
|
// cheapest honest answer to "show me what this rule catches" — every bundled
|
|
24116
24174
|
// rule has them, and they are already in the stored snapshot.
|
|
24117
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
24175
|
+
examples: external_exports.array(external_exports.string()).optional(),
|
|
24176
|
+
// The rule's DECLARED evidence, as stored. Absent defers to the engine's
|
|
24177
|
+
// classification (ruleEvidence in @akasecurity/detections): a bundled
|
|
24178
|
+
// code-flaw rule reads as 'code' and anything else as 'value', and a rule
|
|
24179
|
+
// in a value category (secret/pii/financial/phi) is always 'value',
|
|
24180
|
+
// whatever it declares.
|
|
24181
|
+
evidence: RuleEvidence.optional()
|
|
24118
24182
|
}).meta({ id: "DetectionRule" });
|
|
24119
24183
|
var DetectionUpdate = external_exports.object({
|
|
24120
24184
|
available: external_exports.boolean(),
|
|
@@ -24182,8 +24246,10 @@ var ImportDetectionRequest = external_exports.object({
|
|
|
24182
24246
|
}).meta({ id: "ImportDetectionRequest" });
|
|
24183
24247
|
|
|
24184
24248
|
// ../../packages/schema/src/zod/detection-build.ts
|
|
24185
|
-
function optional2(key,
|
|
24186
|
-
if (raw === void 0
|
|
24249
|
+
function optional2(key, raw, parse4) {
|
|
24250
|
+
if (raw === void 0) return {};
|
|
24251
|
+
const parsed2 = parse4(raw);
|
|
24252
|
+
if (!parsed2.success || parsed2.data === void 0) return {};
|
|
24187
24253
|
return { [key]: parsed2.data };
|
|
24188
24254
|
}
|
|
24189
24255
|
function isStringArray(value) {
|
|
@@ -24218,10 +24284,12 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24218
24284
|
category: r.category,
|
|
24219
24285
|
severity: r.severity,
|
|
24220
24286
|
matcher: parsed2.data,
|
|
24221
|
-
//
|
|
24222
|
-
//
|
|
24223
|
-
//
|
|
24224
|
-
//
|
|
24287
|
+
// `appliesTo`, `postValidators` and `requiresNearby` are the rest of what
|
|
24288
|
+
// decides whether this rule fires. Carried so a consumer re-running the
|
|
24289
|
+
// rule (a preview, a tester) evaluates what the engine evaluates rather
|
|
24290
|
+
// than a matcher stripped of its guards — half the bundled catalog
|
|
24291
|
+
// carries at least one of these. `examples` and `evidence` describe the
|
|
24292
|
+
// rule and never gate a match.
|
|
24225
24293
|
//
|
|
24226
24294
|
// Enrichment is deliberately per-field and best-effort, NOT a whole-rule
|
|
24227
24295
|
// `Rule.safeParse`. Two reasons: `Rule` is a strict object pinned to
|
|
@@ -24231,18 +24299,19 @@ function rowToDetectionDetail(row, findingsLast30d, update) {
|
|
|
24231
24299
|
// test should stay exactly what it was, namely a renderable matcher. A
|
|
24232
24300
|
// field that fails validation is omitted, which reads as "not set" and is
|
|
24233
24301
|
// the same thing the consumer saw before this change.
|
|
24234
|
-
...optional2("appliesTo",
|
|
24302
|
+
...optional2("appliesTo", r.appliesTo, (v) => AppliesTo.safeParse(v)),
|
|
24235
24303
|
...optional2(
|
|
24236
24304
|
"postValidators",
|
|
24237
|
-
|
|
24238
|
-
|
|
24305
|
+
r.postValidators,
|
|
24306
|
+
(v) => PostValidatorRef.array().safeParse(v)
|
|
24239
24307
|
),
|
|
24240
|
-
...optional2("requiresNearby",
|
|
24308
|
+
...optional2("requiresNearby", r.requiresNearby, (v) => RequiresNearby.safeParse(v)),
|
|
24241
24309
|
...optional2(
|
|
24242
24310
|
"examples",
|
|
24243
|
-
|
|
24244
|
-
|
|
24245
|
-
)
|
|
24311
|
+
r.examples,
|
|
24312
|
+
(v) => isStringArray(v) ? { success: true, data: v } : { success: false }
|
|
24313
|
+
),
|
|
24314
|
+
...optional2("evidence", r.evidence, (v) => RuleEvidence.safeParse(v))
|
|
24246
24315
|
}
|
|
24247
24316
|
];
|
|
24248
24317
|
});
|
|
@@ -24935,11 +25004,14 @@ var PolicyBundle = external_exports.object({
|
|
|
24935
25004
|
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
24936
25005
|
// Model ids (the raw `model` string a harness reports, e.g.
|
|
24937
25006
|
// `claude-opus-4-1`) the tenant has PROHIBITED. The plugin refuses to switch
|
|
24938
|
-
// a session onto one (PreModelSwitch)
|
|
24939
|
-
//
|
|
24940
|
-
//
|
|
24941
|
-
//
|
|
24942
|
-
//
|
|
25007
|
+
// a session onto one (PreModelSwitch), refuses a turn that would run on one
|
|
25008
|
+
// (UserPromptSubmit) and refuses a subagent spawn onto one (PreToolUse),
|
|
25009
|
+
// wherever the organization governs the event: everywhere on a
|
|
25010
|
+
// machine-wide attachment, and only in enrolled repositories on a scoped
|
|
25011
|
+
// one (the plugin runtime's `governanceApplies`).
|
|
25012
|
+
// Optional so an older backend — and an older on-disk cache — still
|
|
25013
|
+
// parses; consumers read `?? []`, which is the unenforced behaviour that
|
|
25014
|
+
// predates this field and the safe direction to default.
|
|
24943
25015
|
//
|
|
24944
25016
|
// Ids, not display names: the governance decision is keyed on the exact
|
|
24945
25017
|
// string the harness reports (`model_status_override.versionId` in the
|
|
@@ -25398,6 +25470,8 @@ var AttachmentScopeEntry = external_exports.object({
|
|
|
25398
25470
|
});
|
|
25399
25471
|
var AttachmentScope = external_exports.object({
|
|
25400
25472
|
endpoint: external_exports.string().min(1),
|
|
25473
|
+
tenantName: PluginWhoami.shape.tenantName.optional(),
|
|
25474
|
+
userEmail: PluginWhoami.shape.userEmail.optional(),
|
|
25401
25475
|
entries: external_exports.array(AttachmentScopeEntry)
|
|
25402
25476
|
});
|
|
25403
25477
|
var AttachmentScopeEnvelope = AttachmentScope.extend({ entries: external_exports.array(external_exports.unknown()) });
|
|
@@ -25410,7 +25484,13 @@ function parseAttachmentScope(raw) {
|
|
|
25410
25484
|
const entry = AttachmentScopeEntry.safeParse(candidate);
|
|
25411
25485
|
if (entry.success) entries.push(entry.data);
|
|
25412
25486
|
}
|
|
25413
|
-
|
|
25487
|
+
const { endpoint, tenantName, userEmail } = envelope.data;
|
|
25488
|
+
return {
|
|
25489
|
+
endpoint,
|
|
25490
|
+
...tenantName === void 0 ? {} : { tenantName },
|
|
25491
|
+
...userEmail === void 0 ? {} : { userEmail },
|
|
25492
|
+
entries
|
|
25493
|
+
};
|
|
25414
25494
|
} catch {
|
|
25415
25495
|
return void 0;
|
|
25416
25496
|
}
|
|
@@ -25647,6 +25727,7 @@ function toCaptureAttributes(event) {
|
|
|
25647
25727
|
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
25648
25728
|
...metadata?.inspectionMs !== void 0 ? { inspection_ms: metadata.inspectionMs } : {},
|
|
25649
25729
|
...metadata?.redactDegradedTo !== void 0 ? { redact_degraded_to: metadata.redactDegradedTo } : {},
|
|
25730
|
+
...metadata?.scanIncomplete !== void 0 ? { scan_incomplete: metadata.scanIncomplete } : {},
|
|
25650
25731
|
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
25651
25732
|
// has ever populated either), but every legacy metadata key still rides
|
|
25652
25733
|
// the bag rather than being silently dropped — CaptureAttributes'
|
|
@@ -25775,6 +25856,27 @@ var ManagedSettings = external_exports.object({
|
|
|
25775
25856
|
};
|
|
25776
25857
|
}).meta({ id: "ManagedSettings" });
|
|
25777
25858
|
|
|
25859
|
+
// ../../packages/schema/src/zod/mod-policy-snapshot.ts
|
|
25860
|
+
var MOD_POLICY_SNAPSHOT_VERSION = 1;
|
|
25861
|
+
var MOD_POLICY_SNAPSHOT_MAX_BYTES = 4 * 1024 * 1024;
|
|
25862
|
+
var ModPolicySnapshot = external_exports.object({
|
|
25863
|
+
version: external_exports.literal(MOD_POLICY_SNAPSHOT_VERSION),
|
|
25864
|
+
generatedAt: external_exports.iso.datetime(),
|
|
25865
|
+
// The complete effective ruleset, as the hook's runtime scans with it: the
|
|
25866
|
+
// user's enabled installed packs (user-modified and custom packs included).
|
|
25867
|
+
// Absent means the store holds no authoritative snapshot, and the reader
|
|
25868
|
+
// scans with the packs it ships — the hook's own fallback.
|
|
25869
|
+
rules: external_exports.array(Rule).optional(),
|
|
25870
|
+
// Rule-targeted actions (first enabled policy per rule wins).
|
|
25871
|
+
ruleActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25872
|
+
// The resolved action per detection category.
|
|
25873
|
+
categoryActions: external_exports.record(external_exports.string(), ActionTaken),
|
|
25874
|
+
// Rules with an active exception grant. Honouring a grant means matching a
|
|
25875
|
+
// keyed fingerprint of the value and consuming a use, which only the hook can
|
|
25876
|
+
// do, so the mod leaves a finding of one of these rules for the hook to decide.
|
|
25877
|
+
exceptionRuleIds: external_exports.array(external_exports.string())
|
|
25878
|
+
}).meta({ id: "ModPolicySnapshot" });
|
|
25879
|
+
|
|
25778
25880
|
// ../../packages/schema/src/zod/project-files.ts
|
|
25779
25881
|
var ProjectFileInput = external_exports.object({
|
|
25780
25882
|
path: external_exports.string().min(1),
|
|
@@ -26095,7 +26197,16 @@ var AttachInput = external_exports.object({
|
|
|
26095
26197
|
// 200 matches the tenantName bound beside it in control-plane.ts; nothing
|
|
26096
26198
|
// renders a longer one usefully.
|
|
26097
26199
|
label: printable(200).optional(),
|
|
26098
|
-
accessKey: external_exports.string()
|
|
26200
|
+
accessKey: external_exports.string(),
|
|
26201
|
+
// How much of this machine the attachment is for: everything, or only the
|
|
26202
|
+
// repositories its user enrolls. Optional, so an input without it still
|
|
26203
|
+
// parses; what an absent mode means is for whatever reads it to decide, not
|
|
26204
|
+
// this shape. This member validates the VALUE rather than leaving that to the
|
|
26205
|
+
// call site, a deliberate exception to this module's shape-only rule: a shape
|
|
26206
|
+
// rejection names the field, so a value that is not a mode is refused as a bad
|
|
26207
|
+
// `mode` rather than stripped or passed on. The dashboard's attach action reads
|
|
26208
|
+
// it as the mode to attach in.
|
|
26209
|
+
mode: AttachmentMode.optional()
|
|
26099
26210
|
});
|
|
26100
26211
|
|
|
26101
26212
|
// ../../packages/schema/src/zod/triage.ts
|
|
@@ -26381,6 +26492,18 @@ function fromCaptureStatusAttributes(bag) {
|
|
|
26381
26492
|
return parsedStatus.success ? parsedStatus.data : null;
|
|
26382
26493
|
}
|
|
26383
26494
|
|
|
26495
|
+
// ../../packages/persistence/src/attached-derived.ts
|
|
26496
|
+
import { rmSync } from "fs";
|
|
26497
|
+
import { join } from "path";
|
|
26498
|
+
var POLICY_CACHE_FILENAME = "policy-cache.json";
|
|
26499
|
+
var ATTACHED_FORWARD_STATE_FILENAME = "attached-state.json";
|
|
26500
|
+
var ATTACHED_FORWARD_DROPS_FILENAME = "attached-forward-drops.json";
|
|
26501
|
+
var ATTACHED_POSTURE_REPORT_FILENAME = "attached-posture-report.json";
|
|
26502
|
+
|
|
26503
|
+
// ../../packages/persistence/src/control-plane-credential.ts
|
|
26504
|
+
import { chmodSync as chmodSync2, lstatSync as lstatSync2, readFileSync, rmSync as rmSync3, statSync } from "fs";
|
|
26505
|
+
import { join as join2 } from "path";
|
|
26506
|
+
|
|
26384
26507
|
// ../../packages/persistence/src/paths.ts
|
|
26385
26508
|
import {
|
|
26386
26509
|
chmodSync,
|
|
@@ -26527,6 +26650,14 @@ function repairOrRefuseMode(file2) {
|
|
|
26527
26650
|
}
|
|
26528
26651
|
return "ok";
|
|
26529
26652
|
}
|
|
26653
|
+
function asReadableCredential(value) {
|
|
26654
|
+
const result = AttachedCredentialAny.safeParse(value);
|
|
26655
|
+
if (!result.success) return null;
|
|
26656
|
+
if (attachmentModeOf(result.data) === "machine" && typeof value === "object" && value !== null && Object.hasOwn(value, "mode")) {
|
|
26657
|
+
return null;
|
|
26658
|
+
}
|
|
26659
|
+
return result.data;
|
|
26660
|
+
}
|
|
26530
26661
|
function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
26531
26662
|
const file2 = controlPlaneCredentialPath(settingsDir2);
|
|
26532
26663
|
let raw;
|
|
@@ -26545,20 +26676,20 @@ function readControlPlaneCredentialFile(settingsDir2, connection) {
|
|
|
26545
26676
|
} catch {
|
|
26546
26677
|
return { usable: false, reason: "malformed" };
|
|
26547
26678
|
}
|
|
26548
|
-
const
|
|
26549
|
-
if (
|
|
26550
|
-
if (!isSafeEndpoint(
|
|
26679
|
+
const credential = asReadableCredential(parsed2);
|
|
26680
|
+
if (credential === null) return { usable: false, reason: "malformed" };
|
|
26681
|
+
if (!isSafeEndpoint(credential.endpoint)) {
|
|
26551
26682
|
return { usable: false, reason: "unsafe-endpoint" };
|
|
26552
26683
|
}
|
|
26553
|
-
if (connection !== void 0 && connection.endpoint !==
|
|
26684
|
+
if (connection !== void 0 && connection.endpoint !== credential.endpoint) {
|
|
26554
26685
|
return {
|
|
26555
26686
|
usable: false,
|
|
26556
26687
|
reason: "endpoint-mismatch",
|
|
26557
|
-
credentialEndpoint:
|
|
26688
|
+
credentialEndpoint: credential.endpoint,
|
|
26558
26689
|
settingsEndpoint: connection.endpoint
|
|
26559
26690
|
};
|
|
26560
26691
|
}
|
|
26561
|
-
return { usable: true, credential
|
|
26692
|
+
return { usable: true, credential };
|
|
26562
26693
|
}
|
|
26563
26694
|
function readControlPlaneCredential(settingsDir2, connection) {
|
|
26564
26695
|
const read = readControlPlaneCredentialFile(settingsDir2, connection);
|
|
@@ -26567,7 +26698,7 @@ function readControlPlaneCredential(settingsDir2, connection) {
|
|
|
26567
26698
|
|
|
26568
26699
|
// ../../packages/persistence/src/database.ts
|
|
26569
26700
|
import { randomUUID as randomUUID11 } from "crypto";
|
|
26570
|
-
import { dirname as dirname2, join as
|
|
26701
|
+
import { dirname as dirname2, join as join8, sep } from "path";
|
|
26571
26702
|
import { DatabaseSync } from "node:sqlite";
|
|
26572
26703
|
|
|
26573
26704
|
// ../../packages/persistence/src/ids.ts
|
|
@@ -26621,6 +26752,7 @@ function uuidFromDigest(digest) {
|
|
|
26621
26752
|
function captureWireId(sessionId, contentHash, filePath = null) {
|
|
26622
26753
|
return uuidFromDigest(captureId(sessionId, contentHash, filePath));
|
|
26623
26754
|
}
|
|
26755
|
+
var DOT = ".".charCodeAt(0);
|
|
26624
26756
|
|
|
26625
26757
|
// ../../packages/persistence/src/internal/snapshot.ts
|
|
26626
26758
|
import { randomUUID } from "crypto";
|
|
@@ -26948,6 +27080,25 @@ function scopeKeysParam(scopeKeys) {
|
|
|
26948
27080
|
var ROOT_SCOPE_KEY = `(SELECT session_root.scope_key
|
|
26949
27081
|
FROM audit_events AS session_root
|
|
26950
27082
|
WHERE session_root.id = COALESCE(audit_events.root_session_id, audit_events.id))`;
|
|
27083
|
+
var COUNTED_IN_SCOPE = `
|
|
27084
|
+
AND ${inScope("scope_key")}
|
|
27085
|
+
AND (event_type IN (${CAPTURE_TYPE_LIST}) OR ${inScope(ROOT_SCOPE_KEY)})`;
|
|
27086
|
+
var DRAIN_TOTALS = `SELECT
|
|
27087
|
+
SUM(CASE WHEN synced_at IS NULL AND started_at < :before THEN 1 ELSE 0 END) AS pending,
|
|
27088
|
+
SUM(CASE WHEN synced_at > 0 THEN 1 ELSE 0 END) AS sent,
|
|
27089
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27090
|
+
AND (sync_failure IS NULL OR sync_failure = 'payload_invalid')
|
|
27091
|
+
THEN 1 ELSE 0 END) AS skipped,
|
|
27092
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27093
|
+
AND sync_failure = 'deployment_refused' THEN 1 ELSE 0 END) AS refused,
|
|
27094
|
+
SUM(CASE WHEN synced_at = ${String(SKIPPED)}
|
|
27095
|
+
AND sync_failure = 'detached_undelivered' THEN 1 ELSE 0 END) AS detached
|
|
27096
|
+
FROM audit_events
|
|
27097
|
+
WHERE event_type IN (${TYPE_LIST})`;
|
|
27098
|
+
var CAPTURE_SKIPS = `SELECT COUNT(*) AS skipped
|
|
27099
|
+
FROM audit_events
|
|
27100
|
+
WHERE synced_at = ${String(SKIPPED)}
|
|
27101
|
+
AND event_type IN (${CAPTURE_TYPE_LIST})`;
|
|
26951
27102
|
var ROW_COLUMNS = `id,
|
|
26952
27103
|
parent_id AS parentId,
|
|
26953
27104
|
root_session_id AS rootSessionId,
|
|
@@ -27023,7 +27174,7 @@ var SqliteHistorySyncRepository = class {
|
|
|
27023
27174
|
);
|
|
27024
27175
|
this.scopedCaptureRowsStmt = db.prepare(
|
|
27025
27176
|
`SELECT ${ROW_COLUMNS}
|
|
27026
|
-
FROM audit_events
|
|
27177
|
+
FROM audit_events INDEXED BY idx_audit_scope_owed
|
|
27027
27178
|
WHERE synced_at IS NULL
|
|
27028
27179
|
AND sync_claimed_at IS NULL
|
|
27029
27180
|
AND outbox_owed = 1
|
|
@@ -27076,40 +27227,28 @@ var SqliteHistorySyncRepository = class {
|
|
|
27076
27227
|
);
|
|
27077
27228
|
this.partitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27078
27229
|
FROM audit_events${COUNTED_SCOPE}`);
|
|
27230
|
+
this.scopedPartitionStmt = db.prepare(`SELECT${PARTITION_BUCKETS}
|
|
27231
|
+
FROM audit_events${COUNTED_SCOPE}${COUNTED_IN_SCOPE}`);
|
|
27079
27232
|
this.partitionByKindStmt = db.prepare(
|
|
27080
27233
|
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27081
27234
|
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}
|
|
27082
27235
|
GROUP BY event_type`
|
|
27083
27236
|
);
|
|
27084
|
-
this.
|
|
27085
|
-
`SELECT
|
|
27086
|
-
|
|
27087
|
-
|
|
27088
|
-
|
|
27089
|
-
|
|
27090
|
-
|
|
27091
|
-
|
|
27092
|
-
|
|
27093
|
-
|
|
27094
|
-
|
|
27095
|
-
|
|
27096
|
-
|
|
27097
|
-
|
|
27098
|
-
|
|
27099
|
-
// EVERY sentinel capture, whatever the reason — deliberately NOT split the
|
|
27100
|
-
// way the structural totals are. The split exists because a refusal is
|
|
27101
|
-
// terminal only against the deployment that gave it, and the structural
|
|
27102
|
-
// re-arm frees it on a change of deployment. The capture lane has no such
|
|
27103
|
-
// escape: re-arming a capture would offer one deployment's undelivered
|
|
27104
|
-
// prompts, with their text, to a deployment that never saw them, which is
|
|
27105
|
-
// exactly what disownCapturesStmt exists to prevent. So on this lane both
|
|
27106
|
-
// reasons mean the same thing — this row will not be sent — and splitting
|
|
27107
|
-
// them would put refused captures in a bucket nothing reads and nothing
|
|
27108
|
-
// frees.
|
|
27109
|
-
`SELECT COUNT(*) AS skipped
|
|
27110
|
-
FROM audit_events
|
|
27111
|
-
WHERE synced_at = ${String(SKIPPED)}
|
|
27112
|
-
AND event_type IN (${CAPTURE_TYPE_LIST})`
|
|
27237
|
+
this.scopedPartitionByKindStmt = db.prepare(
|
|
27238
|
+
`SELECT event_type AS kind,${PARTITION_BUCKETS}
|
|
27239
|
+
FROM audit_events INDEXED BY idx_audit_events_sync${COUNTED_SCOPE}${COUNTED_IN_SCOPE}
|
|
27240
|
+
GROUP BY event_type`
|
|
27241
|
+
);
|
|
27242
|
+
this.countsStmt = db.prepare(DRAIN_TOTALS);
|
|
27243
|
+
this.scopedCountsStmt = db.prepare(
|
|
27244
|
+
`${DRAIN_TOTALS}
|
|
27245
|
+
AND ${inScope("scope_key")}
|
|
27246
|
+
AND ${inScope(ROOT_SCOPE_KEY)}`
|
|
27247
|
+
);
|
|
27248
|
+
this.captureSkipCountStmt = db.prepare(CAPTURE_SKIPS);
|
|
27249
|
+
this.scopedCaptureSkipCountStmt = db.prepare(
|
|
27250
|
+
`${CAPTURE_SKIPS}
|
|
27251
|
+
AND ${inScope("scope_key")}`
|
|
27113
27252
|
);
|
|
27114
27253
|
this.fingerprintStmt = db.prepare(
|
|
27115
27254
|
`SELECT endpoint_fingerprint AS fingerprint, backlog_before AS backlogBefore
|
|
@@ -27223,6 +27362,10 @@ var SqliteHistorySyncRepository = class {
|
|
|
27223
27362
|
scopedCaptureRowsStmt;
|
|
27224
27363
|
scopedCaptureBacklogOwedStmt;
|
|
27225
27364
|
markScopeCapturesOwedStmt;
|
|
27365
|
+
scopedPartitionStmt;
|
|
27366
|
+
scopedPartitionByKindStmt;
|
|
27367
|
+
scopedCountsStmt;
|
|
27368
|
+
scopedCaptureSkipCountStmt;
|
|
27226
27369
|
/**
|
|
27227
27370
|
* The masked detections recorded against one tool call.
|
|
27228
27371
|
*
|
|
@@ -27444,7 +27587,29 @@ var SqliteHistorySyncRepository = class {
|
|
|
27444
27587
|
* in" — and a machine that has never attached has no boundary to pass, so
|
|
27445
27588
|
* requiring one would force a caller to invent one and report the whole store
|
|
27446
27589
|
* as queued.
|
|
27590
|
+
*
|
|
27591
|
+
* `scopeKeys` is a scoped attachment's filter: every bucket then counts only
|
|
27592
|
+
* the rows that pass the drain's reachability rule for that scope
|
|
27593
|
+
* (COUNTED_IN_SCOPE, which also names the one kind of row it counts that the
|
|
27594
|
+
* drain never offers), so a personal repository's rows are in none of them.
|
|
27595
|
+
* Omitted, this runs the machine statement, unchanged; an empty list counts
|
|
27596
|
+
* nothing.
|
|
27447
27597
|
*/
|
|
27598
|
+
partition(scopeKeys) {
|
|
27599
|
+
const row = getRow(
|
|
27600
|
+
scopeKeys === void 0 ? this.partitionStmt : this.scopedPartitionStmt,
|
|
27601
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27602
|
+
);
|
|
27603
|
+
return {
|
|
27604
|
+
queued: row?.queued ?? 0,
|
|
27605
|
+
inProgress: row?.inProgress ?? 0,
|
|
27606
|
+
synced: row?.synced ?? 0,
|
|
27607
|
+
failed: row?.failed ?? 0,
|
|
27608
|
+
refused: row?.refused ?? 0,
|
|
27609
|
+
detached: row?.detached ?? 0,
|
|
27610
|
+
total: row?.total ?? 0
|
|
27611
|
+
};
|
|
27612
|
+
}
|
|
27448
27613
|
/**
|
|
27449
27614
|
* The same partition, one row per kind that a lane carries.
|
|
27450
27615
|
*
|
|
@@ -27454,11 +27619,14 @@ var SqliteHistorySyncRepository = class {
|
|
|
27454
27619
|
* rendering a fixed list of kinds must therefore treat a missing one as "no
|
|
27455
27620
|
* rows", never as "zero sent"; the two look identical in a bar and mean
|
|
27456
27621
|
* different things.
|
|
27622
|
+
*
|
|
27623
|
+
* `scopeKeys` scopes it with the clause `partition` uses, so the per-kind rows
|
|
27624
|
+
* still sum to the scoped aggregate. An empty list returns no rows.
|
|
27457
27625
|
*/
|
|
27458
|
-
partitionByKind() {
|
|
27626
|
+
partitionByKind(scopeKeys) {
|
|
27459
27627
|
return allRows(
|
|
27460
|
-
this.partitionByKindStmt,
|
|
27461
|
-
{}
|
|
27628
|
+
scopeKeys === void 0 ? this.partitionByKindStmt : this.scopedPartitionByKindStmt,
|
|
27629
|
+
scopeKeys === void 0 ? {} : { scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27462
27630
|
).map((row) => ({
|
|
27463
27631
|
kind: row.kind,
|
|
27464
27632
|
queued: row.queued ?? 0,
|
|
@@ -27470,22 +27638,25 @@ var SqliteHistorySyncRepository = class {
|
|
|
27470
27638
|
total: row.total ?? 0
|
|
27471
27639
|
}));
|
|
27472
27640
|
}
|
|
27473
|
-
|
|
27474
|
-
|
|
27475
|
-
|
|
27476
|
-
|
|
27477
|
-
|
|
27478
|
-
|
|
27479
|
-
|
|
27480
|
-
|
|
27481
|
-
|
|
27482
|
-
|
|
27483
|
-
|
|
27484
|
-
|
|
27485
|
-
|
|
27486
|
-
|
|
27487
|
-
|
|
27488
|
-
|
|
27641
|
+
/**
|
|
27642
|
+
* The drain's totals. `pending` counts only what is inside the backlog; sent
|
|
27643
|
+
* and skipped are totals.
|
|
27644
|
+
*
|
|
27645
|
+
* `scopeKeys` is a scoped attachment's filter, and it scopes every figure,
|
|
27646
|
+
* `capturesSkipped` included: a structural row is counted only when its own
|
|
27647
|
+
* key and its session root's key are among them, a capture when its own key
|
|
27648
|
+
* is. So `pending` is exactly what pendingSessions and pendingRows page out
|
|
27649
|
+
* under the same keys and boundary. Omitted, this runs the machine
|
|
27650
|
+
* statements, unchanged; an empty list counts nothing.
|
|
27651
|
+
*/
|
|
27652
|
+
counts(before, scopeKeys) {
|
|
27653
|
+
const row = getRow(
|
|
27654
|
+
scopeKeys === void 0 ? this.countsStmt : this.scopedCountsStmt,
|
|
27655
|
+
scopeKeys === void 0 ? { before } : { before, scopeKeys: scopeKeysParam(scopeKeys) }
|
|
27656
|
+
);
|
|
27657
|
+
const captures = scopeKeys === void 0 ? getRow(this.captureSkipCountStmt) : getRow(this.scopedCaptureSkipCountStmt, {
|
|
27658
|
+
scopeKeys: scopeKeysParam(scopeKeys)
|
|
27659
|
+
});
|
|
27489
27660
|
return {
|
|
27490
27661
|
pending: row?.pending ?? 0,
|
|
27491
27662
|
sent: row?.sent ?? 0,
|
|
@@ -27737,6 +27908,7 @@ function applyMigrations(db, file2, options = {}) {
|
|
|
27737
27908
|
}
|
|
27738
27909
|
ensureSyncedAtColumn(db, "audit_events");
|
|
27739
27910
|
ensureScopeKeyColumn(db);
|
|
27911
|
+
ensureScopeOwedIndex(db);
|
|
27740
27912
|
ensureScanLedgerTable(db);
|
|
27741
27913
|
ensureHistorySyncTable(db);
|
|
27742
27914
|
ensureBlockedDetectionsTable(db);
|
|
@@ -28177,14 +28349,48 @@ function ensureScopeKeyColumn(db) {
|
|
|
28177
28349
|
function hasScopeKeyColumn(db) {
|
|
28178
28350
|
return columnNames(db, "audit_events", { includeGenerated: true }).includes("scope_key");
|
|
28179
28351
|
}
|
|
28352
|
+
var SCOPE_OWED_INDEX_DDL = "CREATE INDEX IF NOT EXISTS idx_audit_scope_owed ON audit_events (scope_key, event_type, started_at) WHERE outbox_owed = 1 AND synced_at IS NULL";
|
|
28353
|
+
function ensureScopeOwedIndex(db) {
|
|
28354
|
+
if (!schemaObjectExists(db, "table", "audit_events")) return;
|
|
28355
|
+
const columns = columnNames(db, "audit_events", { includeGenerated: true });
|
|
28356
|
+
const complete = ["scope_key", "outbox_owed", "synced_at"].every((c) => columns.includes(c));
|
|
28357
|
+
if (!complete) return;
|
|
28358
|
+
db.exec(SCOPE_OWED_INDEX_DDL);
|
|
28359
|
+
}
|
|
28180
28360
|
function ensureScanLedgerTable(db) {
|
|
28181
28361
|
db.exec(`CREATE TABLE IF NOT EXISTS scan_ledger (
|
|
28182
28362
|
path TEXT PRIMARY KEY,
|
|
28183
28363
|
mtime TEXT NOT NULL,
|
|
28184
28364
|
content_hash TEXT NOT NULL,
|
|
28185
28365
|
ruleset_hash TEXT NOT NULL,
|
|
28186
|
-
scanned_at INTEGER NOT NULL
|
|
28366
|
+
scanned_at INTEGER NOT NULL,
|
|
28367
|
+
scope_key TEXT,
|
|
28368
|
+
scope_root TEXT
|
|
28187
28369
|
)`);
|
|
28370
|
+
ensureScanLedgerScopeKeyColumn(db);
|
|
28371
|
+
ensureScanLedgerScopeRootColumn(db);
|
|
28372
|
+
}
|
|
28373
|
+
var SCAN_LEDGER_SCOPE_KEY_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_key TEXT";
|
|
28374
|
+
var SCAN_LEDGER_SCOPE_ROOT_DDL = "ALTER TABLE scan_ledger ADD COLUMN scope_root TEXT";
|
|
28375
|
+
function ensureScanLedgerScopeKeyColumn(db) {
|
|
28376
|
+
ensureScanLedgerColumn(db, "scope_key", SCAN_LEDGER_SCOPE_KEY_DDL);
|
|
28377
|
+
}
|
|
28378
|
+
function ensureScanLedgerScopeRootColumn(db) {
|
|
28379
|
+
ensureScanLedgerColumn(db, "scope_root", SCAN_LEDGER_SCOPE_ROOT_DDL);
|
|
28380
|
+
}
|
|
28381
|
+
function ensureScanLedgerColumn(db, column, ddl) {
|
|
28382
|
+
if (!schemaObjectExists(db, "table", "scan_ledger")) return;
|
|
28383
|
+
if (hasScanLedgerColumn(db, column)) return;
|
|
28384
|
+
withTransaction(
|
|
28385
|
+
db,
|
|
28386
|
+
() => {
|
|
28387
|
+
if (!hasScanLedgerColumn(db, column)) db.exec(ddl);
|
|
28388
|
+
},
|
|
28389
|
+
"IMMEDIATE"
|
|
28390
|
+
);
|
|
28391
|
+
}
|
|
28392
|
+
function hasScanLedgerColumn(db, column) {
|
|
28393
|
+
return columnNames(db, "scan_ledger").includes(column);
|
|
28188
28394
|
}
|
|
28189
28395
|
function ensureHistorySyncTable(db) {
|
|
28190
28396
|
db.exec(`CREATE TABLE IF NOT EXISTS history_sync (
|
|
@@ -28235,6 +28441,106 @@ function ensureRuleProbeCacheTable(db) {
|
|
|
28235
28441
|
)`);
|
|
28236
28442
|
}
|
|
28237
28443
|
|
|
28444
|
+
// ../../packages/persistence/src/mod-policy-snapshot.ts
|
|
28445
|
+
import { createHash as createHash2 } from "crypto";
|
|
28446
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
28447
|
+
import { join as join4 } from "path";
|
|
28448
|
+
var MOD_POLICY_SNAPSHOT_FILENAME = "mod-policy.json";
|
|
28449
|
+
function modPolicySnapshotPath(dataDir2) {
|
|
28450
|
+
return join4(dataDir2, MOD_POLICY_SNAPSHOT_FILENAME);
|
|
28451
|
+
}
|
|
28452
|
+
function buildModPolicySnapshot(input2, generatedAt = /* @__PURE__ */ new Date()) {
|
|
28453
|
+
const byRule = /* @__PURE__ */ new Map();
|
|
28454
|
+
const byCategory = /* @__PURE__ */ new Map();
|
|
28455
|
+
for (const policy of input2.policies) {
|
|
28456
|
+
if (!policy.enabled) continue;
|
|
28457
|
+
if ("ruleId" in policy.target) {
|
|
28458
|
+
if (!byRule.has(policy.target.ruleId)) byRule.set(policy.target.ruleId, policy.action);
|
|
28459
|
+
} else if (!byCategory.has(policy.target.category)) {
|
|
28460
|
+
byCategory.set(policy.target.category, policy.action);
|
|
28461
|
+
}
|
|
28462
|
+
}
|
|
28463
|
+
const categoryActions = {};
|
|
28464
|
+
for (const category of DetectionCategory.options) {
|
|
28465
|
+
categoryActions[category] = byCategory.get(category) ?? DEFAULT_ACTIONS[category];
|
|
28466
|
+
}
|
|
28467
|
+
return {
|
|
28468
|
+
version: MOD_POLICY_SNAPSHOT_VERSION,
|
|
28469
|
+
generatedAt: generatedAt.toISOString(),
|
|
28470
|
+
// `examples` is documentation the mod never reads, and a custom pack's are
|
|
28471
|
+
// whatever its author pasted in, so they stay behind.
|
|
28472
|
+
...input2.rules !== void 0 ? { rules: input2.rules.map(withoutExamples) } : {},
|
|
28473
|
+
ruleActions: Object.fromEntries(byRule),
|
|
28474
|
+
categoryActions,
|
|
28475
|
+
exceptionRuleIds: [...new Set(input2.exceptionRuleIds)].sort()
|
|
28476
|
+
};
|
|
28477
|
+
}
|
|
28478
|
+
function assignedRuleActionPolicies(installed) {
|
|
28479
|
+
const out = [];
|
|
28480
|
+
for (const [ruleId, action] of installed.ruleActions) {
|
|
28481
|
+
if (installed.assignedRules.has(ruleId))
|
|
28482
|
+
out.push({ target: { ruleId }, action, enabled: true });
|
|
28483
|
+
}
|
|
28484
|
+
return out;
|
|
28485
|
+
}
|
|
28486
|
+
function withoutExamples(rule) {
|
|
28487
|
+
const copy = { ...rule };
|
|
28488
|
+
delete copy.examples;
|
|
28489
|
+
return copy;
|
|
28490
|
+
}
|
|
28491
|
+
function sameContent(a, b) {
|
|
28492
|
+
return JSON.stringify({ ...a, generatedAt: "" }) === JSON.stringify({ ...b, generatedAt: "" });
|
|
28493
|
+
}
|
|
28494
|
+
function readModPolicySnapshot(dataDir2) {
|
|
28495
|
+
try {
|
|
28496
|
+
const text = readFileSync2(modPolicySnapshotPath(dataDir2), "utf8");
|
|
28497
|
+
if (text.length > MOD_POLICY_SNAPSHOT_MAX_BYTES) return null;
|
|
28498
|
+
const parsed2 = ModPolicySnapshot.safeParse(JSON.parse(text));
|
|
28499
|
+
return parsed2.success ? parsed2.data : null;
|
|
28500
|
+
} catch {
|
|
28501
|
+
return null;
|
|
28502
|
+
}
|
|
28503
|
+
}
|
|
28504
|
+
function writeModPolicySnapshot(dataDir2, snapshot) {
|
|
28505
|
+
const text = JSON.stringify(snapshot);
|
|
28506
|
+
if (Buffer.byteLength(text) > MOD_POLICY_SNAPSHOT_MAX_BYTES) return false;
|
|
28507
|
+
const existing = readModPolicySnapshot(dataDir2);
|
|
28508
|
+
if (existing !== null && sameContent(existing, snapshot)) return false;
|
|
28509
|
+
ensureDataDirSync(dataDir2);
|
|
28510
|
+
writeOwnerOnlyFileSync(modPolicySnapshotPath(dataDir2), text);
|
|
28511
|
+
return true;
|
|
28512
|
+
}
|
|
28513
|
+
function regexProbeKey(matcher) {
|
|
28514
|
+
return createHash2("sha256").update(`${matcher.pattern} ${matcher.flags}`).digest("hex");
|
|
28515
|
+
}
|
|
28516
|
+
function vetRulesForMod(rules, sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
28517
|
+
const bundled = new Set(sources.bundledRegexMatchers().map(regexProbeKey));
|
|
28518
|
+
return rules.filter((rule) => {
|
|
28519
|
+
if (rule.matcher.type !== "regex") return true;
|
|
28520
|
+
const key = regexProbeKey(rule.matcher);
|
|
28521
|
+
const verdict = sources.probeVerdict(key);
|
|
28522
|
+
if (verdict === "quarantined") return false;
|
|
28523
|
+
return verdict === "safe" || bundled.has(key) || previouslyVetted.has(key);
|
|
28524
|
+
});
|
|
28525
|
+
}
|
|
28526
|
+
function modPolicyInputFromStore(sources, previouslyVetted = /* @__PURE__ */ new Set()) {
|
|
28527
|
+
const policies = sources.readPolicies();
|
|
28528
|
+
const snapshot = sources.installedRuleset();
|
|
28529
|
+
const usable = snapshot.installedPacks > 0 && (snapshot.enabledPacks === 0 || snapshot.invalidRules === 0 && snapshot.rules.length > 0);
|
|
28530
|
+
const empty = snapshot.installedPacks > 0 && snapshot.enabledPacks === 0;
|
|
28531
|
+
return {
|
|
28532
|
+
...usable ? { rules: empty ? [] : vetRulesForMod(snapshot.rules, sources, previouslyVetted) } : {},
|
|
28533
|
+
policies: [...policies, ...usable && !empty ? assignedRuleActionPolicies(snapshot) : []],
|
|
28534
|
+
exceptionRuleIds: sources.activeExceptionRuleIds()
|
|
28535
|
+
};
|
|
28536
|
+
}
|
|
28537
|
+
function refreshModPolicySnapshot(dataDir2, sources) {
|
|
28538
|
+
try {
|
|
28539
|
+
writeModPolicySnapshot(dataDir2, buildModPolicySnapshot(modPolicyInputFromStore(sources)));
|
|
28540
|
+
} catch {
|
|
28541
|
+
}
|
|
28542
|
+
}
|
|
28543
|
+
|
|
28238
28544
|
// ../../packages/persistence/src/internal/json.ts
|
|
28239
28545
|
function safeJson(s, fallback) {
|
|
28240
28546
|
if (s == null) return fallback;
|
|
@@ -28409,6 +28715,11 @@ var TIMELINE_COLUMNS = `
|
|
|
28409
28715
|
json_extract(attributes, '$.targetId') AS target_id,
|
|
28410
28716
|
json_extract(attributes, '$.internal') AS internal,
|
|
28411
28717
|
json_extract(attributes, '$.flagged') AS flagged`;
|
|
28718
|
+
var CALL_PROMPT_TOKENS = `(coalesce(input_tokens, 0) + coalesce(cache_read_input_tokens, 0)
|
|
28719
|
+
+ coalesce(ephemeral_1h_input_tokens, 0) + coalesce(ephemeral_5m_input_tokens, 0))`;
|
|
28720
|
+
var CALL_BAND = LONG_CONTEXT_THRESHOLDS.length === 0 ? "0" : LONG_CONTEXT_THRESHOLDS.map((t) => `(${CALL_PROMPT_TOKENS} > ${String(Math.trunc(t))})`).join(
|
|
28721
|
+
" + "
|
|
28722
|
+
);
|
|
28412
28723
|
var LLM_USAGE_SELECT = `
|
|
28413
28724
|
SELECT root_session_id AS sessionId,
|
|
28414
28725
|
provider,
|
|
@@ -28420,9 +28731,10 @@ var LLM_USAGE_SELECT = `
|
|
|
28420
28731
|
coalesce(sum(cache_read_input_tokens), 0) AS cacheReadTokens,
|
|
28421
28732
|
coalesce(sum(ephemeral_1h_input_tokens), 0) AS ephemeral1hTokens,
|
|
28422
28733
|
coalesce(sum(ephemeral_5m_input_tokens), 0) AS ephemeral5mTokens,
|
|
28423
|
-
coalesce(sum(web_search_requests), 0) AS webSearchRequests
|
|
28734
|
+
coalesce(sum(web_search_requests), 0) AS webSearchRequests,
|
|
28735
|
+
coalesce(max(${CALL_PROMPT_TOKENS}), 0) AS promptTokens`;
|
|
28424
28736
|
var LLM_USAGE_SCOPE = `event_type = 'llm_call' AND attributes IS NOT NULL AND root_session_id IS NOT NULL`;
|
|
28425
|
-
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier`;
|
|
28737
|
+
var LLM_USAGE_GROUP = `GROUP BY root_session_id, provider, model, service_tier, ${CALL_BAND}`;
|
|
28426
28738
|
function usageLeaves(rows) {
|
|
28427
28739
|
return rows.map((row) => {
|
|
28428
28740
|
const attributes = {
|
|
@@ -28437,7 +28749,7 @@ function usageLeaves(rows) {
|
|
|
28437
28749
|
if (row.provider !== null) attributes.provider = row.provider;
|
|
28438
28750
|
if (row.model !== null) attributes.model = row.model;
|
|
28439
28751
|
if (row.serviceTier !== null) attributes.service_tier = row.serviceTier;
|
|
28440
|
-
return { sessionId: row.sessionId, attributes };
|
|
28752
|
+
return { sessionId: row.sessionId, attributes, promptTokens: row.promptTokens };
|
|
28441
28753
|
});
|
|
28442
28754
|
}
|
|
28443
28755
|
var SESSION_ROOT = `event_type = 'session'`;
|
|
@@ -29771,9 +30083,10 @@ var ACTIVE_REVEAL_GRANT_PREDICATE = `capability = 'reveal_to_model'
|
|
|
29771
30083
|
AND conditions IS NULL
|
|
29772
30084
|
AND ${ACTIVE_PREDICATE}`;
|
|
29773
30085
|
var SqliteExceptionsRepository = class {
|
|
29774
|
-
constructor(db, now = () => Date.now()) {
|
|
30086
|
+
constructor(db, now = () => Date.now(), onChange = () => void 0) {
|
|
29775
30087
|
this.db = db;
|
|
29776
30088
|
this.now = now;
|
|
30089
|
+
this.onChange = onChange;
|
|
29777
30090
|
this.consumeStmt = db.prepare(
|
|
29778
30091
|
`UPDATE exceptions
|
|
29779
30092
|
SET use_count = use_count + 1, last_used_at = :now, updated_at = :now
|
|
@@ -29792,6 +30105,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29792
30105
|
}
|
|
29793
30106
|
db;
|
|
29794
30107
|
now;
|
|
30108
|
+
onChange;
|
|
29795
30109
|
consumeStmt;
|
|
29796
30110
|
insertBlockedStmt;
|
|
29797
30111
|
sweepBlockedStmt;
|
|
@@ -29807,7 +30121,9 @@ var SqliteExceptionsRepository = class {
|
|
|
29807
30121
|
*/
|
|
29808
30122
|
create(input2) {
|
|
29809
30123
|
try {
|
|
29810
|
-
|
|
30124
|
+
const created = this.createSync(input2);
|
|
30125
|
+
this.onChange();
|
|
30126
|
+
return Promise.resolve(created);
|
|
29811
30127
|
} catch (err) {
|
|
29812
30128
|
return Promise.reject(err instanceof Error ? err : new Error(String(err)));
|
|
29813
30129
|
}
|
|
@@ -29938,6 +30254,7 @@ var SqliteExceptionsRepository = class {
|
|
|
29938
30254
|
SET revoked_at = :now, revoked_by = :revokedBy, revoke_reason = :reason, updated_at = :now
|
|
29939
30255
|
WHERE id = :id AND revoked_at IS NULL`
|
|
29940
30256
|
).run({ id, revokedBy, reason: reason ?? null, now });
|
|
30257
|
+
if (Number(result.changes) === 1) this.onChange();
|
|
29941
30258
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29942
30259
|
}
|
|
29943
30260
|
/**
|
|
@@ -29950,6 +30267,15 @@ var SqliteExceptionsRepository = class {
|
|
|
29950
30267
|
const result = this.consumeStmt.run({ id, now });
|
|
29951
30268
|
return Promise.resolve(Number(result.changes) === 1);
|
|
29952
30269
|
}
|
|
30270
|
+
/** The rule ids with at least one active grant, under any key version. */
|
|
30271
|
+
activeRuleIds(now = this.now()) {
|
|
30272
|
+
return allRows(
|
|
30273
|
+
this.db.prepare(
|
|
30274
|
+
`SELECT DISTINCT rule_id AS ruleId FROM exceptions WHERE ${ACTIVE_PREDICATE}`
|
|
30275
|
+
),
|
|
30276
|
+
{ now }
|
|
30277
|
+
).map((row) => row.ruleId);
|
|
30278
|
+
}
|
|
29953
30279
|
/**
|
|
29954
30280
|
* The evaluation subset of every active grant under one fingerprint key
|
|
29955
30281
|
* version — what rides the policy bundle to the hook. Grants written under
|
|
@@ -31073,28 +31399,28 @@ var SqliteInspectionFindingsRepository = class {
|
|
|
31073
31399
|
};
|
|
31074
31400
|
|
|
31075
31401
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
31076
|
-
import { createHash as
|
|
31402
|
+
import { createHash as createHash3, randomUUID as randomUUID4 } from "crypto";
|
|
31077
31403
|
|
|
31078
31404
|
// ../../packages/persistence/src/policy-floor.ts
|
|
31079
|
-
import { readFileSync as
|
|
31080
|
-
import { join as
|
|
31405
|
+
import { readFileSync as readFileSync6 } from "fs";
|
|
31406
|
+
import { join as join7 } from "path";
|
|
31081
31407
|
|
|
31082
31408
|
// ../../packages/persistence/src/local-layout.ts
|
|
31083
31409
|
import { renameSync as renameSync3 } from "fs";
|
|
31084
31410
|
import { mkdir } from "fs/promises";
|
|
31085
31411
|
import { homedir } from "os";
|
|
31086
|
-
import { join as
|
|
31412
|
+
import { join as join5 } from "path";
|
|
31087
31413
|
function defaultDataDir() {
|
|
31088
|
-
return
|
|
31414
|
+
return join5(homedir(), ".aka");
|
|
31089
31415
|
}
|
|
31090
31416
|
function settingsDir(base = defaultDataDir()) {
|
|
31091
|
-
return
|
|
31417
|
+
return join5(base, "settings");
|
|
31092
31418
|
}
|
|
31093
31419
|
function dataDir(base = defaultDataDir()) {
|
|
31094
|
-
return
|
|
31420
|
+
return join5(base, "data");
|
|
31095
31421
|
}
|
|
31096
31422
|
function dbPath(base = defaultDataDir()) {
|
|
31097
|
-
return
|
|
31423
|
+
return join5(dataDir(base), "aka.db");
|
|
31098
31424
|
}
|
|
31099
31425
|
async function ensureDataDir(dir = defaultDataDir()) {
|
|
31100
31426
|
await mkdir(dir, { recursive: true, mode: DATA_DIR_MODE });
|
|
@@ -31111,8 +31437,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31111
31437
|
for (const { name, dest } of moves) {
|
|
31112
31438
|
try {
|
|
31113
31439
|
ensureDataDirSync(dest);
|
|
31114
|
-
const moved =
|
|
31115
|
-
renameSync3(
|
|
31440
|
+
const moved = join5(dest, name);
|
|
31441
|
+
renameSync3(join5(base, name), moved);
|
|
31116
31442
|
tightenFile(moved);
|
|
31117
31443
|
} catch {
|
|
31118
31444
|
}
|
|
@@ -31120,8 +31446,8 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
31120
31446
|
}
|
|
31121
31447
|
|
|
31122
31448
|
// ../../packages/persistence/src/settings.ts
|
|
31123
|
-
import { readFileSync as
|
|
31124
|
-
import { join as
|
|
31449
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
31450
|
+
import { join as join6 } from "path";
|
|
31125
31451
|
|
|
31126
31452
|
// ../../packages/persistence/src/file-lock.ts
|
|
31127
31453
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -31129,7 +31455,7 @@ import {
|
|
|
31129
31455
|
closeSync,
|
|
31130
31456
|
existsSync as existsSync2,
|
|
31131
31457
|
openSync,
|
|
31132
|
-
readFileSync as
|
|
31458
|
+
readFileSync as readFileSync3,
|
|
31133
31459
|
rmSync as rmSync5,
|
|
31134
31460
|
statSync as statSync3,
|
|
31135
31461
|
writeFileSync as writeFileSync2
|
|
@@ -31138,16 +31464,16 @@ import { hostname as hostname3 } from "os";
|
|
|
31138
31464
|
var PARK = new Int32Array(new SharedArrayBuffer(4));
|
|
31139
31465
|
|
|
31140
31466
|
// ../../packages/persistence/src/managed-settings.ts
|
|
31141
|
-
import { readFileSync as
|
|
31467
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
31142
31468
|
import { posix, win32 } from "path";
|
|
31143
|
-
function managedSettingsPaths(
|
|
31144
|
-
if (
|
|
31469
|
+
function managedSettingsPaths(platform = process.platform) {
|
|
31470
|
+
if (platform === "darwin") {
|
|
31145
31471
|
return [
|
|
31146
31472
|
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
31147
31473
|
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
31148
31474
|
];
|
|
31149
31475
|
}
|
|
31150
|
-
if (
|
|
31476
|
+
if (platform === "win32") {
|
|
31151
31477
|
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
31152
31478
|
}
|
|
31153
31479
|
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
@@ -31157,7 +31483,7 @@ function readManagedSettings(paths = testOnlyManagedPaths ?? managedSettingsPath
|
|
|
31157
31483
|
for (const path of paths) {
|
|
31158
31484
|
let text;
|
|
31159
31485
|
try {
|
|
31160
|
-
text =
|
|
31486
|
+
text = readFileSync4(path, "utf8");
|
|
31161
31487
|
} catch {
|
|
31162
31488
|
continue;
|
|
31163
31489
|
}
|
|
@@ -31211,7 +31537,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
31211
31537
|
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
31212
31538
|
}
|
|
31213
31539
|
function readUserSettings(base) {
|
|
31214
|
-
const record2 = readJson(
|
|
31540
|
+
const record2 = readJson(join6(settingsDir(base), SETTINGS_FILENAME));
|
|
31215
31541
|
if (!record2) return defaultWorkspaceSettings();
|
|
31216
31542
|
try {
|
|
31217
31543
|
return WorkspaceSettings.parse(record2);
|
|
@@ -31222,7 +31548,7 @@ function readUserSettings(base) {
|
|
|
31222
31548
|
function readJson(file2) {
|
|
31223
31549
|
let text;
|
|
31224
31550
|
try {
|
|
31225
|
-
text =
|
|
31551
|
+
text = readFileSync5(file2, "utf8");
|
|
31226
31552
|
} catch {
|
|
31227
31553
|
return null;
|
|
31228
31554
|
}
|
|
@@ -31262,7 +31588,7 @@ var PolicyFloorError = class extends Error {
|
|
|
31262
31588
|
};
|
|
31263
31589
|
function readCachedPolicyBundle(base = defaultDataDir()) {
|
|
31264
31590
|
try {
|
|
31265
|
-
const raw =
|
|
31591
|
+
const raw = readFileSync6(join7(dataDir(base), POLICY_CACHE_FILENAME), "utf8");
|
|
31266
31592
|
const parsed2 = JSON.parse(raw);
|
|
31267
31593
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
31268
31594
|
return PolicyBundle.parse(parsed2.bundle);
|
|
@@ -31386,7 +31712,7 @@ function inventorySignature(packs2) {
|
|
|
31386
31712
|
return packs2.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
31387
31713
|
}
|
|
31388
31714
|
function hashRules(rulesJson) {
|
|
31389
|
-
return
|
|
31715
|
+
return createHash3("sha256").update(rulesJson).digest("hex");
|
|
31390
31716
|
}
|
|
31391
31717
|
function parseVersion(v) {
|
|
31392
31718
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -31428,9 +31754,10 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31428
31754
|
* from `openLocalDatabase`, which is the single construction site that owns a
|
|
31429
31755
|
* real `~/.aka`.
|
|
31430
31756
|
*/
|
|
31431
|
-
constructor(db, baseDir) {
|
|
31757
|
+
constructor(db, baseDir, onChange = () => void 0) {
|
|
31432
31758
|
this.db = db;
|
|
31433
31759
|
this.baseDir = baseDir;
|
|
31760
|
+
this.onChange = onChange;
|
|
31434
31761
|
this.insertMissingStmt = db.prepare(
|
|
31435
31762
|
`INSERT INTO installed_packs (id, namespace, pack_id, version, name, rules_json, enabled, policy_id, created_at, updated_at)
|
|
31436
31763
|
VALUES (:id, :namespace, :packId, :version, :name, :rulesJson, 1, :policyId, :now, :now)
|
|
@@ -31459,6 +31786,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31459
31786
|
}
|
|
31460
31787
|
db;
|
|
31461
31788
|
baseDir;
|
|
31789
|
+
onChange;
|
|
31462
31790
|
insertMissingStmt;
|
|
31463
31791
|
upsertAvailableStmt;
|
|
31464
31792
|
signatureStmt;
|
|
@@ -31531,6 +31859,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31531
31859
|
},
|
|
31532
31860
|
"IMMEDIATE"
|
|
31533
31861
|
);
|
|
31862
|
+
this.onChange();
|
|
31534
31863
|
} catch {
|
|
31535
31864
|
}
|
|
31536
31865
|
}
|
|
@@ -31605,6 +31934,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31605
31934
|
},
|
|
31606
31935
|
"IMMEDIATE"
|
|
31607
31936
|
);
|
|
31937
|
+
if (changed) this.onChange();
|
|
31608
31938
|
return changed;
|
|
31609
31939
|
}
|
|
31610
31940
|
/**
|
|
@@ -31846,6 +32176,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31846
32176
|
`UPDATE installed_packs SET policy_id = :policyId, updated_at = :now
|
|
31847
32177
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31848
32178
|
).run({ policyId, now: Date.now(), namespace, packId });
|
|
32179
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31849
32180
|
return Number(res.changes) > 0;
|
|
31850
32181
|
}
|
|
31851
32182
|
/**
|
|
@@ -31870,6 +32201,7 @@ var SqliteInstalledPacksRepository = class {
|
|
|
31870
32201
|
`UPDATE installed_packs SET enabled = :enabled, updated_at = :now
|
|
31871
32202
|
WHERE namespace = :namespace AND pack_id = :packId`
|
|
31872
32203
|
).run({ enabled: boolToInt(enabled), now: Date.now(), namespace, packId });
|
|
32204
|
+
if (Number(res.changes) > 0) this.onChange();
|
|
31873
32205
|
return Number(res.changes) > 0;
|
|
31874
32206
|
}
|
|
31875
32207
|
// Fingerprint of the recorded available mirror — compared against the
|
|
@@ -32767,13 +33099,19 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
32767
33099
|
import { randomUUID as randomUUID6 } from "crypto";
|
|
32768
33100
|
var SEED_BATCH_WINDOW_MS = 6e4;
|
|
32769
33101
|
var SqlitePoliciesRepository = class {
|
|
32770
|
-
constructor(db) {
|
|
33102
|
+
constructor(db, onChange = () => void 0) {
|
|
32771
33103
|
this.db = db;
|
|
33104
|
+
this.onChange = onChange;
|
|
32772
33105
|
}
|
|
32773
33106
|
db;
|
|
33107
|
+
onChange;
|
|
32774
33108
|
readPolicies() {
|
|
33109
|
+
return Promise.resolve(this.listPolicies());
|
|
33110
|
+
}
|
|
33111
|
+
/** The synchronous read behind {@link readPolicies}. */
|
|
33112
|
+
listPolicies() {
|
|
32775
33113
|
const rows = allRows(this.db.prepare("SELECT * FROM policies"));
|
|
32776
|
-
|
|
33114
|
+
return mapRowsTolerant(rows, (row) => {
|
|
32777
33115
|
const target = JSON.parse(row.target);
|
|
32778
33116
|
const customKeywords = row.custom_keywords ? JSON.parse(row.custom_keywords) : void 0;
|
|
32779
33117
|
return Policy.parse({
|
|
@@ -32785,7 +33123,6 @@ var SqlitePoliciesRepository = class {
|
|
|
32785
33123
|
customKeywords
|
|
32786
33124
|
});
|
|
32787
33125
|
});
|
|
32788
|
-
return Promise.resolve(policies);
|
|
32789
33126
|
}
|
|
32790
33127
|
// Seed one policy per bundled category at Monitor so the detection-type config
|
|
32791
33128
|
// exists from first run. An unassigned pack's rules follow these rows, so
|
|
@@ -32796,7 +33133,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32796
33133
|
const count = countScalar(this.db, "SELECT count(*) AS n FROM policies");
|
|
32797
33134
|
if (count > 0) {
|
|
32798
33135
|
this.markEarlierChoices();
|
|
32799
|
-
this.monitorUntouchedSeeds();
|
|
33136
|
+
if (this.monitorUntouchedSeeds()) this.onChange();
|
|
32800
33137
|
return;
|
|
32801
33138
|
}
|
|
32802
33139
|
const stmt = this.db.prepare(
|
|
@@ -32813,6 +33150,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32813
33150
|
});
|
|
32814
33151
|
}
|
|
32815
33152
|
});
|
|
33153
|
+
this.onChange();
|
|
32816
33154
|
}
|
|
32817
33155
|
// Before this build, upsertCategoryAction INSERTed a new row with updated_at
|
|
32818
33156
|
// equal to created_at, so a choice made for a category that had no row yet
|
|
@@ -32878,7 +33216,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32878
33216
|
).filter(
|
|
32879
33217
|
(row) => DEFAULT_ACTIONS[row.category] === row.action
|
|
32880
33218
|
);
|
|
32881
|
-
if (untouched.length === 0) return;
|
|
33219
|
+
if (untouched.length === 0) return false;
|
|
32882
33220
|
const stmt = this.db.prepare(
|
|
32883
33221
|
`UPDATE policies SET action = 'log'
|
|
32884
33222
|
WHERE scope = 'global' AND json_extract(target, '$.category') = :category
|
|
@@ -32889,6 +33227,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32889
33227
|
stmt.run({ category: row.category, seeded: row.action });
|
|
32890
33228
|
}
|
|
32891
33229
|
});
|
|
33230
|
+
return true;
|
|
32892
33231
|
}
|
|
32893
33232
|
// Insert-or-update the single global per-category policy row, keyed on the
|
|
32894
33233
|
// existing uq_policies_scope_target unique index (scope, target). `action`
|
|
@@ -32905,6 +33244,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32905
33244
|
ON CONFLICT(scope, target) DO UPDATE SET action = excluded.action, enabled = 1,
|
|
32906
33245
|
updated_at = MAX(excluded.updated_at, policies.created_at + 1)`
|
|
32907
33246
|
).run({ id: randomUUID6(), target: JSON.stringify({ category }), action, now });
|
|
33247
|
+
this.onChange();
|
|
32908
33248
|
}
|
|
32909
33249
|
// Caps every global per-category policy currently set to block/redact down
|
|
32910
33250
|
// to warn (see warn-era-cap.ts). Rule-targeted policies are untouched.
|
|
@@ -32915,6 +33255,7 @@ var SqlitePoliciesRepository = class {
|
|
|
32915
33255
|
WHERE scope='global' AND action IN ('block','redact')
|
|
32916
33256
|
AND json_extract(target,'$.category') IS NOT NULL`
|
|
32917
33257
|
).run({ now: Date.now() });
|
|
33258
|
+
if (Number(info.changes) > 0) this.onChange();
|
|
32918
33259
|
return Number(info.changes);
|
|
32919
33260
|
}
|
|
32920
33261
|
// Whether the category's row was ever written after it was created — by the
|
|
@@ -33234,31 +33575,45 @@ var SqliteScanLedgerRepository = class {
|
|
|
33234
33575
|
constructor(db) {
|
|
33235
33576
|
this.db = db;
|
|
33236
33577
|
this.upsertStmt = db.prepare(
|
|
33237
|
-
`INSERT INTO scan_ledger
|
|
33238
|
-
|
|
33578
|
+
`INSERT INTO scan_ledger
|
|
33579
|
+
(path, mtime, content_hash, ruleset_hash, scope_key, scope_root, scanned_at)
|
|
33580
|
+
VALUES (:path, :mtime, :contentHash, :rulesetHash, :scopeKey, :scopeRoot, :scannedAt)
|
|
33239
33581
|
ON CONFLICT (path) DO UPDATE SET
|
|
33240
33582
|
mtime = excluded.mtime,
|
|
33241
33583
|
content_hash = excluded.content_hash,
|
|
33242
33584
|
ruleset_hash = excluded.ruleset_hash,
|
|
33585
|
+
scope_key = excluded.scope_key,
|
|
33586
|
+
scope_root = excluded.scope_root,
|
|
33243
33587
|
scanned_at = excluded.scanned_at`
|
|
33244
33588
|
);
|
|
33245
33589
|
this.readStmt = db.prepare(
|
|
33246
|
-
`SELECT path, mtime, content_hash AS contentHash
|
|
33590
|
+
`SELECT path, mtime, content_hash AS contentHash, scope_key AS scopeKey,
|
|
33591
|
+
scope_root AS scopeRoot
|
|
33247
33592
|
FROM scan_ledger WHERE ruleset_hash = :rulesetHash`
|
|
33248
33593
|
);
|
|
33249
33594
|
this.pathsStmt = db.prepare(`SELECT path FROM scan_ledger`);
|
|
33595
|
+
this.pathKeysStmt = db.prepare(`SELECT path, scope_key AS scopeKey FROM scan_ledger`);
|
|
33250
33596
|
}
|
|
33251
33597
|
db;
|
|
33252
33598
|
upsertStmt;
|
|
33253
33599
|
readStmt;
|
|
33254
33600
|
pathsStmt;
|
|
33601
|
+
pathKeysStmt;
|
|
33255
33602
|
// Previously scanned files under THIS ruleset, keyed by path. Rows from an
|
|
33256
33603
|
// older ruleset are simply absent, which reads as "never scanned".
|
|
33257
33604
|
entriesForRuleset(rulesetHash) {
|
|
33258
|
-
const rows = allRows(this.readStmt, {
|
|
33259
|
-
|
|
33260
|
-
|
|
33261
|
-
|
|
33605
|
+
const rows = allRows(this.readStmt, { rulesetHash });
|
|
33606
|
+
return new Map(
|
|
33607
|
+
rows.map((r) => [
|
|
33608
|
+
r.path,
|
|
33609
|
+
{
|
|
33610
|
+
mtime: r.mtime,
|
|
33611
|
+
contentHash: r.contentHash,
|
|
33612
|
+
...r.scopeKey !== null ? { scopeKey: r.scopeKey } : {},
|
|
33613
|
+
...r.scopeRoot !== null ? { scopeRoot: r.scopeRoot } : {}
|
|
33614
|
+
}
|
|
33615
|
+
])
|
|
33616
|
+
);
|
|
33262
33617
|
}
|
|
33263
33618
|
// Every ledgered path, whatever ruleset it was scanned under — the set a
|
|
33264
33619
|
// deletion sweep checks against disk. A file deleted before a ruleset change
|
|
@@ -33267,6 +33622,14 @@ var SqliteScanLedgerRepository = class {
|
|
|
33267
33622
|
allPaths() {
|
|
33268
33623
|
return allRows(this.pathsStmt).map((r) => r.path);
|
|
33269
33624
|
}
|
|
33625
|
+
// Every ledgered path with the repository it was in when it was last read,
|
|
33626
|
+
// whatever ruleset it was scanned under: what a deletion sweep needs to say
|
|
33627
|
+
// which repository a vanished file belonged to. `undefined` for a row with no
|
|
33628
|
+
// key, which is every row written before the column existed.
|
|
33629
|
+
pathKeys() {
|
|
33630
|
+
const rows = allRows(this.pathKeysStmt);
|
|
33631
|
+
return new Map(rows.map((r) => [r.path, r.scopeKey ?? void 0]));
|
|
33632
|
+
}
|
|
33270
33633
|
upsertEntries(entries) {
|
|
33271
33634
|
if (entries.length === 0) return;
|
|
33272
33635
|
const scannedAt = Date.now();
|
|
@@ -33277,6 +33640,8 @@ var SqliteScanLedgerRepository = class {
|
|
|
33277
33640
|
mtime: entry.mtime,
|
|
33278
33641
|
contentHash: entry.contentHash,
|
|
33279
33642
|
rulesetHash: entry.rulesetHash,
|
|
33643
|
+
scopeKey: entry.scopeKey ?? null,
|
|
33644
|
+
scopeRoot: entry.scopeRoot ?? null,
|
|
33280
33645
|
scannedAt
|
|
33281
33646
|
});
|
|
33282
33647
|
}
|
|
@@ -34364,6 +34729,11 @@ function withoutDroppedFiles(reconcile, droppedFiles) {
|
|
|
34364
34729
|
deletedFiles: reconcile.deletedFiles.filter((file2) => !dropped.has(file2))
|
|
34365
34730
|
};
|
|
34366
34731
|
}
|
|
34732
|
+
function withoutTrailingSlashes(path) {
|
|
34733
|
+
let end = path.length;
|
|
34734
|
+
while (end > 0 && path.charCodeAt(end - 1) === 47) end--;
|
|
34735
|
+
return path.slice(0, end);
|
|
34736
|
+
}
|
|
34367
34737
|
function toEndpointSummary(row) {
|
|
34368
34738
|
return {
|
|
34369
34739
|
id: row.id,
|
|
@@ -34651,7 +35021,7 @@ var SqliteSharesRepository = class {
|
|
|
34651
35021
|
*/
|
|
34652
35022
|
reconcileCallSites(projectKey, reconcile) {
|
|
34653
35023
|
if (reconcile.mode === "walk") {
|
|
34654
|
-
const prefix = reconcile.walkedPrefix
|
|
35024
|
+
const prefix = withoutTrailingSlashes(reconcile.walkedPrefix);
|
|
34655
35025
|
this.db.prepare(
|
|
34656
35026
|
`DELETE FROM share_call_site
|
|
34657
35027
|
WHERE project_key = :key
|
|
@@ -35219,7 +35589,7 @@ function backupLegacyStore(db, file2) {
|
|
|
35219
35589
|
discardStore(file2, backup);
|
|
35220
35590
|
return backup;
|
|
35221
35591
|
}
|
|
35222
|
-
function openAndInitialize(file2, base, skipTags) {
|
|
35592
|
+
function openAndInitialize(file2, base, skipTags, shippedRegexMatchers2) {
|
|
35223
35593
|
let db = openWithPragmas(file2);
|
|
35224
35594
|
try {
|
|
35225
35595
|
if (isForeignSqliteLineage(db)) {
|
|
@@ -35231,8 +35601,15 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35231
35601
|
}
|
|
35232
35602
|
applyMigrations(db, file2, { skipTags });
|
|
35233
35603
|
tightenPerms(file2);
|
|
35234
|
-
const
|
|
35235
|
-
const
|
|
35604
|
+
const modPolicy = {};
|
|
35605
|
+
const onPolicyStateChange = () => {
|
|
35606
|
+
if (modPolicy.current !== void 0)
|
|
35607
|
+
refreshModPolicySnapshot(dirname2(file2), modPolicy.current);
|
|
35608
|
+
};
|
|
35609
|
+
const policies = new SqlitePoliciesRepository(db, onPolicyStateChange);
|
|
35610
|
+
const installedPacks = new SqliteInstalledPacksRepository(db, base, onPolicyStateChange);
|
|
35611
|
+
const ruleProbeCache = new SqliteRuleProbeCacheRepository(db);
|
|
35612
|
+
const exceptions = new SqliteExceptionsRepository(db, void 0, onPolicyStateChange);
|
|
35236
35613
|
const repositories = {
|
|
35237
35614
|
events: new SqliteEventsRepository(db),
|
|
35238
35615
|
findings: new SqliteFindingsRepository(db),
|
|
@@ -35241,9 +35618,9 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35241
35618
|
scanLedger: new SqliteScanLedgerRepository(db),
|
|
35242
35619
|
historySync: new SqliteHistorySyncRepository(db),
|
|
35243
35620
|
secretVault: new SqliteSecretVaultRepository(db),
|
|
35244
|
-
exceptions
|
|
35621
|
+
exceptions,
|
|
35245
35622
|
resolutions: new SqliteResolutionsRepository(db),
|
|
35246
|
-
ruleProbeCache
|
|
35623
|
+
ruleProbeCache,
|
|
35247
35624
|
bodyRetention: new SqliteBodyRetentionRepository(db),
|
|
35248
35625
|
security: new SqliteSecurityRepository(db),
|
|
35249
35626
|
detections: new SqliteDetectionsRepository(db),
|
|
@@ -35261,6 +35638,13 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35261
35638
|
inspectionFindings: new SqliteInspectionFindingsRepository(db),
|
|
35262
35639
|
configInventory: new SqliteConfigInventoryRepository(db)
|
|
35263
35640
|
};
|
|
35641
|
+
modPolicy.current = {
|
|
35642
|
+
installedRuleset: () => installedPacks.installedRuleset(),
|
|
35643
|
+
readPolicies: () => policies.listPolicies(),
|
|
35644
|
+
activeExceptionRuleIds: () => exceptions.activeRuleIds(),
|
|
35645
|
+
probeVerdict: (key) => ruleProbeCache.getVerdict(key)?.verdict,
|
|
35646
|
+
bundledRegexMatchers: () => shippedRegexMatchers2
|
|
35647
|
+
};
|
|
35264
35648
|
policies.seedDefaults();
|
|
35265
35649
|
return { db, ...repositories };
|
|
35266
35650
|
} catch (err) {
|
|
@@ -35272,7 +35656,7 @@ function openAndInitialize(file2, base, skipTags) {
|
|
|
35272
35656
|
var DEFERRED_TAGS = new Set(DEFERRED_MIGRATION_TAGS);
|
|
35273
35657
|
function openLocalDatabase(dir, options = {}) {
|
|
35274
35658
|
ensureDataDirSync(dir);
|
|
35275
|
-
const file2 =
|
|
35659
|
+
const file2 = join8(dir, DB_FILENAME);
|
|
35276
35660
|
reapStalePartials(file2);
|
|
35277
35661
|
const {
|
|
35278
35662
|
db,
|
|
@@ -35308,7 +35692,8 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35308
35692
|
// `dataDir()` — so its parent is the `~/.aka` base the layout splits into
|
|
35309
35693
|
// settings/ and data/, and the pack-policy floor needs both halves.
|
|
35310
35694
|
dirname2(dir),
|
|
35311
|
-
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS
|
|
35695
|
+
options.applyDeferredMigrations === true ? void 0 : DEFERRED_TAGS,
|
|
35696
|
+
options.shippedRegexMatchers ?? []
|
|
35312
35697
|
);
|
|
35313
35698
|
function captureRowId(event) {
|
|
35314
35699
|
return captureId(
|
|
@@ -35573,7 +35958,7 @@ function openLocalDatabase(dir, options = {}) {
|
|
|
35573
35958
|
}
|
|
35574
35959
|
|
|
35575
35960
|
// ../../packages/persistence/src/egress-wire.ts
|
|
35576
|
-
import { createHash as
|
|
35961
|
+
import { createHash as createHash4 } from "crypto";
|
|
35577
35962
|
var PROJECT_KEY_DIGEST_VERSION = "v2";
|
|
35578
35963
|
var SCP_FORM = /^(?:[^@/]+@)?([^/:]+):(.+)$/;
|
|
35579
35964
|
var DOS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
@@ -35605,7 +35990,7 @@ function canonicalGitUrl(url2) {
|
|
|
35605
35990
|
}
|
|
35606
35991
|
function hashProjectKey(projectKey) {
|
|
35607
35992
|
const canonical = projectKey.startsWith("git:") ? `git:${canonicalGitUrl(projectKey.slice("git:".length))}` : projectKey;
|
|
35608
|
-
return
|
|
35993
|
+
return createHash4("sha256").update(`${PROJECT_KEY_DIGEST_VERSION}:${canonical}`, "utf8").digest("hex");
|
|
35609
35994
|
}
|
|
35610
35995
|
var SCOPE_KEY = printable(ATTACHMENT_SCOPE_IDENTITY_MAX_LENGTH);
|
|
35611
35996
|
var URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
@@ -35670,24 +36055,23 @@ function toEgressIngestRequest(input2) {
|
|
|
35670
36055
|
}
|
|
35671
36056
|
|
|
35672
36057
|
// ../../packages/persistence/src/finding-key.ts
|
|
35673
|
-
import { createHash as
|
|
36058
|
+
import { createHash as createHash5 } from "crypto";
|
|
35674
36059
|
function normalizeFilePath(filePath) {
|
|
35675
36060
|
return filePath.replaceAll("\\", "/");
|
|
35676
36061
|
}
|
|
35677
36062
|
function computeFindingKey(input2) {
|
|
35678
36063
|
const normalizedPath = normalizeFilePath(input2.filePath);
|
|
35679
|
-
return
|
|
36064
|
+
return createHash5("sha256").update(`${input2.ruleId}\0${normalizedPath}\0${input2.valueFingerprint}`).digest("hex");
|
|
35680
36065
|
}
|
|
35681
36066
|
|
|
35682
36067
|
// ../../packages/persistence/src/fingerprint.ts
|
|
35683
36068
|
import { createHmac, randomBytes } from "crypto";
|
|
35684
|
-
import { existsSync as existsSync3, readFileSync as
|
|
35685
|
-
import { join as
|
|
35686
|
-
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
36069
|
+
import { existsSync as existsSync3, readFileSync as readFileSync7 } from "fs";
|
|
36070
|
+
import { join as join9 } from "path";
|
|
35687
36071
|
var EXCEPTION_KEY_FILENAME = "exception.key";
|
|
35688
36072
|
var KEY_MATERIAL_BYTES = 32;
|
|
35689
36073
|
function keyFilePath(dataDir2) {
|
|
35690
|
-
return
|
|
36074
|
+
return join9(dataDir2, EXCEPTION_KEY_FILENAME);
|
|
35691
36075
|
}
|
|
35692
36076
|
function parseKeyFile(raw) {
|
|
35693
36077
|
const parsed2 = JSON.parse(raw);
|
|
@@ -35714,6 +36098,12 @@ var KEY_VERSION_COLUMNS = {
|
|
|
35714
36098
|
};
|
|
35715
36099
|
var SQLITE_ERROR2 = 1;
|
|
35716
36100
|
var FLOOR_BUSY_TIMEOUT_MS = 250;
|
|
36101
|
+
function openReadOnly(file2) {
|
|
36102
|
+
const host = process;
|
|
36103
|
+
const sqlite = host.getBuiltinModule?.("node:sqlite");
|
|
36104
|
+
if (sqlite === void 0) throw new Error("this Node runtime cannot load node:sqlite");
|
|
36105
|
+
return new sqlite.DatabaseSync(file2, { readOnly: true });
|
|
36106
|
+
}
|
|
35717
36107
|
var FloorUnreadableError = class extends Error {
|
|
35718
36108
|
code = "floor-unreadable";
|
|
35719
36109
|
constructor(cause) {
|
|
@@ -35725,11 +36115,11 @@ var FloorUnreadableError = class extends Error {
|
|
|
35725
36115
|
}
|
|
35726
36116
|
};
|
|
35727
36117
|
function storedKeyVersionFloor(dataDir2) {
|
|
35728
|
-
const file2 =
|
|
36118
|
+
const file2 = join9(dataDir2, DB_FILENAME);
|
|
35729
36119
|
if (!existsSync3(file2)) return 0;
|
|
35730
36120
|
let db;
|
|
35731
36121
|
try {
|
|
35732
|
-
db =
|
|
36122
|
+
db = openReadOnly(file2);
|
|
35733
36123
|
db.exec(`PRAGMA busy_timeout = ${String(FLOOR_BUSY_TIMEOUT_MS)}`);
|
|
35734
36124
|
let floor = 0;
|
|
35735
36125
|
for (const [table2, column] of Object.entries(KEY_VERSION_COLUMNS)) {
|
|
@@ -35780,7 +36170,7 @@ function occupantMessage(file2, kind) {
|
|
|
35780
36170
|
function readFingerprintKey(dataDir2) {
|
|
35781
36171
|
let raw;
|
|
35782
36172
|
try {
|
|
35783
|
-
raw =
|
|
36173
|
+
raw = readFileSync7(keyFilePath(dataDir2), "utf8");
|
|
35784
36174
|
} catch (err) {
|
|
35785
36175
|
if (err.code === "ENOENT") return null;
|
|
35786
36176
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -35806,8 +36196,8 @@ function exactFingerprintValue(key, raw) {
|
|
|
35806
36196
|
}
|
|
35807
36197
|
|
|
35808
36198
|
// ../../packages/persistence/src/forward-health.ts
|
|
35809
|
-
import { readFileSync as
|
|
35810
|
-
import { join as
|
|
36199
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
36200
|
+
import { join as join10 } from "path";
|
|
35811
36201
|
var BREAKER_COOLDOWN_MS = 3e4;
|
|
35812
36202
|
function parseForwardHealth(raw, nowMs) {
|
|
35813
36203
|
try {
|
|
@@ -35831,20 +36221,21 @@ function isForwardPaused(health, nowMs) {
|
|
|
35831
36221
|
|
|
35832
36222
|
// ../../packages/persistence/src/history-backfill.ts
|
|
35833
36223
|
import { existsSync as existsSync4 } from "fs";
|
|
35834
|
-
import { join as
|
|
36224
|
+
import { join as join11 } from "path";
|
|
35835
36225
|
|
|
35836
36226
|
// ../../packages/persistence/src/history-preview.ts
|
|
35837
36227
|
import { existsSync as existsSync5 } from "fs";
|
|
35838
|
-
import { join as
|
|
35839
|
-
import { DatabaseSync as
|
|
36228
|
+
import { join as join12 } from "path";
|
|
36229
|
+
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
35840
36230
|
|
|
35841
36231
|
// ../../packages/persistence/src/history-sync-state.ts
|
|
35842
|
-
import { readFileSync as
|
|
35843
|
-
import { join as
|
|
36232
|
+
import { readFileSync as readFileSync9 } from "fs";
|
|
36233
|
+
import { join as join13 } from "path";
|
|
36234
|
+
var COUNTS_SCOPES = new Set(AttachmentMode.options);
|
|
35844
36235
|
|
|
35845
36236
|
// ../../packages/persistence/src/store-symlinks.ts
|
|
35846
36237
|
import { existsSync as existsSync6, lstatSync as lstatSync3, readlinkSync, realpathSync, statSync as statSync4 } from "fs";
|
|
35847
|
-
import { dirname as dirname3, join as
|
|
36238
|
+
import { dirname as dirname3, join as join14, resolve } from "path";
|
|
35848
36239
|
|
|
35849
36240
|
// ../../packages/persistence/src/vault/crypto.ts
|
|
35850
36241
|
import {
|
|
@@ -35858,19 +36249,19 @@ import {
|
|
|
35858
36249
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
35859
36250
|
import { execFileSync } from "child_process";
|
|
35860
36251
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
35861
|
-
import { chmodSync as chmodSync3, readFileSync as
|
|
35862
|
-
import { join as
|
|
36252
|
+
import { chmodSync as chmodSync3, readFileSync as readFileSync10, renameSync as renameSync4, rmSync as rmSync6, statSync as statSync5, writeFileSync as writeFileSync3 } from "fs";
|
|
36253
|
+
import { join as join15 } from "path";
|
|
35863
36254
|
|
|
35864
36255
|
// ../../packages/persistence/src/vault/vault.ts
|
|
35865
36256
|
import { randomBytes as randomBytes3, randomUUID as randomUUID12 } from "crypto";
|
|
35866
36257
|
|
|
35867
36258
|
// ../../packages/persistence/src/warn-era-cap.ts
|
|
35868
36259
|
import { existsSync as existsSync7, writeFileSync as writeFileSync4 } from "fs";
|
|
35869
|
-
import { join as
|
|
36260
|
+
import { join as join16 } from "path";
|
|
35870
36261
|
var MARKER = "warn-era-capped";
|
|
35871
36262
|
function capWarnEraEnforcementOnce(db, policyMode, dataDir2) {
|
|
35872
36263
|
if (policyMode !== "warn") return { capped: 0, skipped: "not-warn" };
|
|
35873
|
-
const marker =
|
|
36264
|
+
const marker = join16(dataDir2, MARKER);
|
|
35874
36265
|
if (existsSync7(marker)) return { capped: 0, skipped: "already-run" };
|
|
35875
36266
|
const capped = db.policies.capCategoryActions();
|
|
35876
36267
|
writeFileSync4(marker, `${new Date(Date.now()).toISOString()}
|
|
@@ -35930,7 +36321,7 @@ function resolveProvider() {
|
|
|
35930
36321
|
function loadConfig(base = defaultDataDir(), resolveProviderFn = resolveProvider) {
|
|
35931
36322
|
try {
|
|
35932
36323
|
ensureLayoutDirSync(base);
|
|
35933
|
-
const settingsFile =
|
|
36324
|
+
const settingsFile = join17(settingsDir(base), "settings.json");
|
|
35934
36325
|
if (existsSync8(settingsFile)) tightenFile(settingsFile);
|
|
35935
36326
|
} catch {
|
|
35936
36327
|
}
|
|
@@ -35953,11 +36344,6 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
35953
36344
|
}
|
|
35954
36345
|
}
|
|
35955
36346
|
|
|
35956
|
-
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
35957
|
-
import { readdirSync as readdirSync2, readFileSync as readFileSync11, realpathSync as realpathSync2, statSync as statSync7 } from "fs";
|
|
35958
|
-
import { homedir as homedir2 } from "os";
|
|
35959
|
-
import { basename as basename3, join as join18 } from "path";
|
|
35960
|
-
|
|
35961
36347
|
// ../../packages/detections/src/egress/registry.ts
|
|
35962
36348
|
var EXTRACTOR_VERSION = "3";
|
|
35963
36349
|
var PROVIDER_REGISTRY = [
|
|
@@ -37062,11 +37448,11 @@ var EXACT_KIND_BY_BASENAME = {
|
|
|
37062
37448
|
"composer.json": "composer.json",
|
|
37063
37449
|
"packages.config": "packages.config"
|
|
37064
37450
|
};
|
|
37065
|
-
function manifestKindOf(
|
|
37066
|
-
if (LOCKFILE_BASENAMES.has(
|
|
37067
|
-
const exact = Object.hasOwn(EXACT_KIND_BY_BASENAME,
|
|
37451
|
+
function manifestKindOf(basename6) {
|
|
37452
|
+
if (LOCKFILE_BASENAMES.has(basename6)) return null;
|
|
37453
|
+
const exact = Object.hasOwn(EXACT_KIND_BY_BASENAME, basename6) ? EXACT_KIND_BY_BASENAME[basename6] : void 0;
|
|
37068
37454
|
if (exact !== void 0) return exact;
|
|
37069
|
-
if (
|
|
37455
|
+
if (basename6.endsWith(".csproj")) return "csproj";
|
|
37070
37456
|
return null;
|
|
37071
37457
|
}
|
|
37072
37458
|
function extractManifestSdks(text, kind) {
|
|
@@ -37694,12 +38080,12 @@ var RegexMatcher2 = class {
|
|
|
37694
38080
|
rule.matcher,
|
|
37695
38081
|
() => new RegExp(pattern, flags.includes("d") ? flags : `${flags}d`)
|
|
37696
38082
|
);
|
|
37697
|
-
const
|
|
38083
|
+
const scanText = text.length > MAX_REGEX_INPUT_LENGTH ? text.slice(0, MAX_REGEX_INPUT_LENGTH) : text;
|
|
37698
38084
|
const spans = [];
|
|
37699
38085
|
let m;
|
|
37700
|
-
const maxIterations =
|
|
38086
|
+
const maxIterations = scanText.length + 1;
|
|
37701
38087
|
let iterations = 0;
|
|
37702
|
-
while ((m = re.exec(
|
|
38088
|
+
while ((m = re.exec(scanText)) !== null) {
|
|
37703
38089
|
if (++iterations > maxIterations) break;
|
|
37704
38090
|
const group = captureGroup != null ? m[captureGroup] : m[0];
|
|
37705
38091
|
if (m[0].length === 0) re.lastIndex++;
|
|
@@ -38041,17 +38427,18 @@ function ruleEvidence(rule) {
|
|
|
38041
38427
|
|
|
38042
38428
|
// ../../packages/detections/src/mask.ts
|
|
38043
38429
|
function maskMatch(raw) {
|
|
38044
|
-
|
|
38045
|
-
|
|
38046
|
-
|
|
38047
|
-
|
|
38430
|
+
const visible = stripInvisiblePadding(raw);
|
|
38431
|
+
if (visible.length <= 5) return "***";
|
|
38432
|
+
const atIndex = visible.indexOf("@");
|
|
38433
|
+
if (atIndex > 0 && atIndex < visible.length - 1) {
|
|
38434
|
+
const domain2 = visible.slice(atIndex + 1);
|
|
38048
38435
|
if (domain2.includes(".")) {
|
|
38049
|
-
const local =
|
|
38436
|
+
const local = visible.slice(0, atIndex);
|
|
38050
38437
|
const maskedLocal = local.length <= 1 ? local : local.charAt(0) + "*".repeat(local.length - 1);
|
|
38051
38438
|
return `${maskedLocal}@${domain2}`;
|
|
38052
38439
|
}
|
|
38053
38440
|
}
|
|
38054
|
-
return `${
|
|
38441
|
+
return `${visible.charAt(0)}${"*".repeat(6)}${visible.charAt(visible.length - 1)}`;
|
|
38055
38442
|
}
|
|
38056
38443
|
|
|
38057
38444
|
// ../../packages/detections/src/pointer-shield.ts
|
|
@@ -38287,6 +38674,38 @@ function worstProbeMs(rule, now = wallClock, corroborate) {
|
|
|
38287
38674
|
}
|
|
38288
38675
|
var CPU_CORROBORATION_SHARE = 0.2;
|
|
38289
38676
|
var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
|
|
38677
|
+
function repeatTo(unit, length) {
|
|
38678
|
+
return unit.repeat(Math.ceil(length / unit.length)).slice(0, length);
|
|
38679
|
+
}
|
|
38680
|
+
function joinTo(length, open3, close, item) {
|
|
38681
|
+
const parts = [];
|
|
38682
|
+
let size = open3.length;
|
|
38683
|
+
for (let i = 0; size < length; i++) {
|
|
38684
|
+
const next = (i === 0 ? "" : ",") + item(i);
|
|
38685
|
+
parts.push(next);
|
|
38686
|
+
size += next.length;
|
|
38687
|
+
}
|
|
38688
|
+
return (open3 + parts.join("") + close).slice(0, length);
|
|
38689
|
+
}
|
|
38690
|
+
var SQL_WORDS = ["select", "insert", "update", "delete", "drop", "where"];
|
|
38691
|
+
var GROWTH_CORPORA = [
|
|
38692
|
+
{
|
|
38693
|
+
name: "one-line JSON dictionary",
|
|
38694
|
+
build: (length) => joinTo(length, "{", "}", (i) => `"id-${String(i)}":"label ${String(i)}"`)
|
|
38695
|
+
},
|
|
38696
|
+
{
|
|
38697
|
+
name: "JSON array of quoted SQL keywords",
|
|
38698
|
+
build: (length) => joinTo(length, "[", "]", (i) => `"${SQL_WORDS[i % SQL_WORDS.length] ?? ""} ${String(i)}"`)
|
|
38699
|
+
},
|
|
38700
|
+
{ name: "single-quoted keyword run ('where)", build: (length) => repeatTo("'where", length) },
|
|
38701
|
+
{ name: "double-quote run", build: (length) => repeatTo('"', length) },
|
|
38702
|
+
{ name: "space run", build: (length) => repeatTo(" ", length) },
|
|
38703
|
+
{ name: "newline run", build: (length) => repeatTo("\n", length) },
|
|
38704
|
+
...["abc-", "a.", "a ", "a=", "x", "0", "a@", "a/", "ab"].map((unit) => ({
|
|
38705
|
+
name: `unit run ${JSON.stringify(unit)}`,
|
|
38706
|
+
build: (length) => repeatTo(unit, length)
|
|
38707
|
+
}))
|
|
38708
|
+
];
|
|
38290
38709
|
function checkRuleTiming(rule, corroborate) {
|
|
38291
38710
|
const { ms, probe, corroboratedMs } = worstProbeMs(rule, wallClock, corroborate);
|
|
38292
38711
|
const work = corroboratedMs ?? 0;
|
|
@@ -38313,7 +38732,12 @@ var MIN_RAW_LEN = 4;
|
|
|
38313
38732
|
var RAW_RUN_LEN = 8;
|
|
38314
38733
|
function carriesRawRun(text, rawValues) {
|
|
38315
38734
|
let windows = null;
|
|
38316
|
-
|
|
38735
|
+
const values = /* @__PURE__ */ new Set();
|
|
38736
|
+
for (const raw of rawValues) {
|
|
38737
|
+
values.add(raw);
|
|
38738
|
+
values.add(stripInvisiblePadding(raw));
|
|
38739
|
+
}
|
|
38740
|
+
for (const raw of values) {
|
|
38317
38741
|
if (raw.length < MIN_RAW_LEN) continue;
|
|
38318
38742
|
if (raw.length < RAW_RUN_LEN) {
|
|
38319
38743
|
if (text.includes(raw)) return true;
|
|
@@ -38337,11 +38761,16 @@ function carriesRawRun(text, rawValues) {
|
|
|
38337
38761
|
return false;
|
|
38338
38762
|
}
|
|
38339
38763
|
function safeMaskedMatch(rawMatch) {
|
|
38340
|
-
const
|
|
38341
|
-
|
|
38342
|
-
|
|
38764
|
+
const visible = stripInvisiblePadding(rawMatch);
|
|
38765
|
+
const masked = maskMatch(visible);
|
|
38766
|
+
const reveals = (preview) => preview === visible || visible.length >= MIN_RAW_LEN && preview.includes(visible);
|
|
38767
|
+
if (!reveals(masked)) return masked;
|
|
38768
|
+
const atIndex = masked.indexOf("@");
|
|
38769
|
+
if (atIndex > 0 && atIndex < masked.length - 1) {
|
|
38770
|
+
const emailFallback = `*${masked.slice(atIndex)}`;
|
|
38771
|
+
if (!reveals(emailFallback)) return emailFallback;
|
|
38343
38772
|
}
|
|
38344
|
-
return
|
|
38773
|
+
return "***";
|
|
38345
38774
|
}
|
|
38346
38775
|
function assertRawFree(text, rawValues) {
|
|
38347
38776
|
if (carriesRawRun(text, rawValues)) {
|
|
@@ -38578,7 +39007,7 @@ var auth_jwt_no_verify_default = {
|
|
|
38578
39007
|
severity: "critical",
|
|
38579
39008
|
matcher: {
|
|
38580
39009
|
type: "regex",
|
|
38581
|
-
pattern: "(verify\\s*=\\s*false|verify_signature
|
|
39010
|
+
pattern: "(verify\\s*=\\s*false|verify_signature(?:(?!verify_signature).)*false|algorithms\\s*=\\s*\\[\\])",
|
|
38582
39011
|
flags: "gi"
|
|
38583
39012
|
},
|
|
38584
39013
|
requiresNearby: {
|
|
@@ -38666,7 +39095,7 @@ var cmd_inject_shell_default = {
|
|
|
38666
39095
|
severity: "critical",
|
|
38667
39096
|
matcher: {
|
|
38668
39097
|
type: "regex",
|
|
38669
|
-
pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\([^)]*shell\\s*=\\s*True",
|
|
39098
|
+
pattern: "subprocess\\.(run|Popen|call|check_output)\\s*\\((?:(?!subprocess\\.(?:run|Popen|call|check_output)\\s*\\()[^)])*shell\\s*=\\s*True",
|
|
38670
39099
|
flags: "gi"
|
|
38671
39100
|
},
|
|
38672
39101
|
requiresNearby: {
|
|
@@ -38795,7 +39224,7 @@ var deser_yaml_unsafe_default = {
|
|
|
38795
39224
|
severity: "high",
|
|
38796
39225
|
matcher: {
|
|
38797
39226
|
type: "regex",
|
|
38798
|
-
pattern: "\\byaml\\.load\\s*\\((?![^)]
|
|
39227
|
+
pattern: "\\byaml\\.load\\s*\\((?!(?:(?!yaml\\.load\\s*\\()[^)])*?(?:SafeLoader|safe_load))",
|
|
38799
39228
|
flags: "gi"
|
|
38800
39229
|
},
|
|
38801
39230
|
examples: ["data = yaml.load(user_input)", "config = yaml.load(f)"],
|
|
@@ -39012,7 +39441,7 @@ var sql_inject_concat_dot_default = {
|
|
|
39012
39441
|
severity: "high",
|
|
39013
39442
|
matcher: {
|
|
39014
39443
|
type: "regex",
|
|
39015
|
-
pattern: `["'][
|
|
39444
|
+
pattern: `["'](?=([^"'\\n]*?(?:select|insert|update|delete|drop|where)))\\1(?:(?!["'][^"'\\n]*?(?:select|insert|update|delete|drop|where))[^\\n])*?["']\\s*\\.`,
|
|
39016
39445
|
flags: "gi"
|
|
39017
39446
|
},
|
|
39018
39447
|
appliesTo: {
|
|
@@ -39030,7 +39459,7 @@ var sql_inject_concat_default = {
|
|
|
39030
39459
|
severity: "high",
|
|
39031
39460
|
matcher: {
|
|
39032
39461
|
type: "regex",
|
|
39033
|
-
pattern: `["']\\s*(?:select\\b[^\\n]*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b[^\\n]*?=)[^\\n]*?["']\\s*\\+`,
|
|
39462
|
+
pattern: `(["'])\\s*(?=(select\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?=))\\2(?:(?!\\1\\s*(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b))[^\\n])*?["']\\s*\\+`,
|
|
39034
39463
|
flags: "gi"
|
|
39035
39464
|
},
|
|
39036
39465
|
examples: ['"SELECT * FROM users WHERE id = " + userId']
|
|
@@ -39045,7 +39474,7 @@ var sql_inject_format_default = {
|
|
|
39045
39474
|
severity: "high",
|
|
39046
39475
|
matcher: {
|
|
39047
39476
|
type: "regex",
|
|
39048
|
-
pattern: "\\b(?:select\\b[^\\n]*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b|where\\b[^\\n]*?=)[^\\n]*?(?:[%][sd]|\\{[^}]+\\})",
|
|
39477
|
+
pattern: "\\b(?=(select\\b(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?\\bfrom\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))\\1(?:(?!\\b(?:select\\b|insert\\s+into\\b|update\\s+\\S+\\s+set\\b|delete\\s+from\\b|drop\\s+(?:table|database)\\b))[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})|\\b(?=(where\\b(?:(?!\\bwhere\\b)[^\\n])*?=))\\2(?:(?!\\bwhere\\b)[^\\n])*?(?:[%][sd]|\\{[^{}\\n]+\\})",
|
|
39049
39478
|
flags: "gi"
|
|
39050
39479
|
},
|
|
39051
39480
|
examples: [
|
|
@@ -39063,7 +39492,7 @@ var sql_inject_interp_default = {
|
|
|
39063
39492
|
severity: "high",
|
|
39064
39493
|
matcher: {
|
|
39065
39494
|
type: "regex",
|
|
39066
|
-
pattern: "(select|insert|update|delete|where)[^\\n]*?(#\\{|\\$[a-z_])",
|
|
39495
|
+
pattern: "(select|insert|update|delete|where)(?:(?!(?:select|insert|update|delete|where))[^\\n])*?(#\\{|\\$[a-z_])",
|
|
39067
39496
|
flags: "gi"
|
|
39068
39497
|
},
|
|
39069
39498
|
examples: [
|
|
@@ -39438,7 +39867,7 @@ var stack_trace_default = {
|
|
|
39438
39867
|
severity: "low",
|
|
39439
39868
|
matcher: {
|
|
39440
39869
|
type: "regex",
|
|
39441
|
-
pattern: "(
|
|
39870
|
+
pattern: "(?:^|(?<!\\s)\\s+)at\\s+[A-Za-z0-9._$<>]+\\.[A-Za-z0-9_$]+\\s*\\([A-Za-z0-9._\\-/:]+:\\d+:\\d+\\)",
|
|
39442
39871
|
flags: "g"
|
|
39443
39872
|
},
|
|
39444
39873
|
examples: ["at com.example.service.UserService.findUser(UserService.java:42:13)"]
|
|
@@ -40596,7 +41025,7 @@ var BUNDLED_PACKS = [
|
|
|
40596
41025
|
{
|
|
40597
41026
|
packId: "code-flaws",
|
|
40598
41027
|
name: "Code Security Flaws",
|
|
40599
|
-
version: "0.1.
|
|
41028
|
+
version: "0.1.1",
|
|
40600
41029
|
rawRules: [
|
|
40601
41030
|
sql_inject_concat_default,
|
|
40602
41031
|
sql_inject_concat_dot_default,
|
|
@@ -40646,7 +41075,7 @@ var BUNDLED_PACKS = [
|
|
|
40646
41075
|
{
|
|
40647
41076
|
packId: "core-code-context",
|
|
40648
41077
|
name: "Code Context",
|
|
40649
|
-
version: "0.2.
|
|
41078
|
+
version: "0.2.2",
|
|
40650
41079
|
rawRules: [
|
|
40651
41080
|
internal_ip_default,
|
|
40652
41081
|
localhost_ref_default,
|
|
@@ -40783,6 +41212,11 @@ function bundledDetections() {
|
|
|
40783
41212
|
}));
|
|
40784
41213
|
return cachedDetections;
|
|
40785
41214
|
}
|
|
41215
|
+
function shippedRegexMatchers() {
|
|
41216
|
+
return bundledDetections().flatMap((pack) => pack.rules).flatMap(
|
|
41217
|
+
(rule) => rule.matcher.type === "regex" ? [{ pattern: rule.matcher.pattern, flags: rule.matcher.flags }] : []
|
|
41218
|
+
);
|
|
41219
|
+
}
|
|
40786
41220
|
|
|
40787
41221
|
// ../../packages/plugin-sdk/src/mask.ts
|
|
40788
41222
|
var packsReady = false;
|
|
@@ -40804,8 +41238,8 @@ function bundledMaskingRules() {
|
|
|
40804
41238
|
}
|
|
40805
41239
|
|
|
40806
41240
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
40807
|
-
import { existsSync as existsSync9, readFileSync as
|
|
40808
|
-
import { basename as basename2, dirname as dirname4, isAbsolute, join as
|
|
41241
|
+
import { existsSync as existsSync9, readFileSync as readFileSync11, statSync as statSync6 } from "fs";
|
|
41242
|
+
import { basename as basename2, dirname as dirname4, isAbsolute, join as join18, sep as sep2 } from "path";
|
|
40809
41243
|
function resolveRepoIdentity(cwd) {
|
|
40810
41244
|
try {
|
|
40811
41245
|
const location = locateRepo(cwd);
|
|
@@ -40824,8 +41258,9 @@ function resolveRepoIdentity(cwd) {
|
|
|
40824
41258
|
var ATTRIBUTION_MEMO_LIMIT = 64;
|
|
40825
41259
|
var attributionMemo = /* @__PURE__ */ new Map();
|
|
40826
41260
|
var NO_ATTRIBUTION = Object.freeze({});
|
|
40827
|
-
function resolveRepoAttribution(cwd) {
|
|
41261
|
+
function resolveRepoAttribution(cwd, options) {
|
|
40828
41262
|
try {
|
|
41263
|
+
if (options?.cache === false) return attributeRepo(cwd);
|
|
40829
41264
|
const remembered = attributionMemo.get(cwd);
|
|
40830
41265
|
if (remembered !== void 0) return remembered;
|
|
40831
41266
|
const attribution = attributeRepo(cwd);
|
|
@@ -40856,36 +41291,36 @@ function resolveWorktreeRoot(cwd) {
|
|
|
40856
41291
|
function findGitRoot(start) {
|
|
40857
41292
|
let dir = start;
|
|
40858
41293
|
for (; ; ) {
|
|
40859
|
-
if (existsSync9(
|
|
41294
|
+
if (existsSync9(join18(dir, ".git"))) return dir;
|
|
40860
41295
|
const parent = dirname4(dir);
|
|
40861
41296
|
if (parent === dir) return void 0;
|
|
40862
41297
|
dir = parent;
|
|
40863
41298
|
}
|
|
40864
41299
|
}
|
|
40865
41300
|
function resolveGitContext(root) {
|
|
40866
|
-
const dotGit =
|
|
41301
|
+
const dotGit = join18(root, ".git");
|
|
40867
41302
|
try {
|
|
40868
41303
|
if (statSync6(dotGit).isDirectory()) {
|
|
40869
|
-
return { configPath:
|
|
41304
|
+
return { configPath: join18(dotGit, "config"), headRoot: root };
|
|
40870
41305
|
}
|
|
40871
41306
|
} catch {
|
|
40872
41307
|
return void 0;
|
|
40873
41308
|
}
|
|
40874
41309
|
const target = /^gitdir:\s*(.+?)\s*$/m.exec(safeRead(dotGit) ?? "")?.[1];
|
|
40875
41310
|
if (!target) return void 0;
|
|
40876
|
-
const gitdir = isAbsolute(target) ? target :
|
|
40877
|
-
if (existsSync9(
|
|
40878
|
-
return { configPath:
|
|
41311
|
+
const gitdir = isAbsolute(target) ? target : join18(root, target);
|
|
41312
|
+
if (existsSync9(join18(gitdir, "config"))) {
|
|
41313
|
+
return { configPath: join18(gitdir, "config"), headRoot: root };
|
|
40879
41314
|
}
|
|
40880
|
-
const commonRaw = safeRead(
|
|
41315
|
+
const commonRaw = safeRead(join18(gitdir, "commondir"))?.trim();
|
|
40881
41316
|
if (!commonRaw) return void 0;
|
|
40882
|
-
const commonGitDir = isAbsolute(commonRaw) ? commonRaw :
|
|
41317
|
+
const commonGitDir = isAbsolute(commonRaw) ? commonRaw : join18(gitdir, commonRaw);
|
|
40883
41318
|
const headRoot = basename2(commonGitDir) === ".git" ? dirname4(commonGitDir) : root;
|
|
40884
|
-
return { configPath:
|
|
41319
|
+
return { configPath: join18(commonGitDir, "config"), headRoot };
|
|
40885
41320
|
}
|
|
40886
41321
|
function safeRead(path) {
|
|
40887
41322
|
try {
|
|
40888
|
-
return
|
|
41323
|
+
return readFileSync11(path, "utf8");
|
|
40889
41324
|
} catch {
|
|
40890
41325
|
return void 0;
|
|
40891
41326
|
}
|
|
@@ -40932,9 +41367,9 @@ function slugFromUrl(url2) {
|
|
|
40932
41367
|
}
|
|
40933
41368
|
|
|
40934
41369
|
// ../../packages/plugin-sdk/src/events.ts
|
|
40935
|
-
import { createHash as
|
|
41370
|
+
import { createHash as createHash6, randomUUID as randomUUID13 } from "crypto";
|
|
40936
41371
|
function contentHashOf(text) {
|
|
40937
|
-
return
|
|
41372
|
+
return createHash6("sha256").update(text).digest("hex");
|
|
40938
41373
|
}
|
|
40939
41374
|
function buildIngestEvent(input2) {
|
|
40940
41375
|
const contentHash = input2.contentHash ?? contentHashOf(input2.content);
|
|
@@ -41109,9 +41544,10 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
41109
41544
|
if (job.timer !== void 0) return;
|
|
41110
41545
|
job.startedAt = performance.now();
|
|
41111
41546
|
job.progressAt = job.startedAt;
|
|
41547
|
+
const budget = job.deadlineAt === void 0 ? job.budgetMs : Math.max(0, Math.min(job.budgetMs, job.deadlineAt - job.startedAt));
|
|
41112
41548
|
job.timer = setTimeout(() => {
|
|
41113
41549
|
onDeadline(job);
|
|
41114
|
-
},
|
|
41550
|
+
}, budget);
|
|
41115
41551
|
}
|
|
41116
41552
|
function runOne(spec, fail) {
|
|
41117
41553
|
if (closed) {
|
|
@@ -41122,6 +41558,12 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
41122
41558
|
fail({ status: "unavailable", reason: `the scan worker crashed: ${broken}` });
|
|
41123
41559
|
return;
|
|
41124
41560
|
}
|
|
41561
|
+
const now = performance.now();
|
|
41562
|
+
const deadlineAt = spec.deadlineAt;
|
|
41563
|
+
if (deadlineAt !== void 0 && deadlineAt <= now) {
|
|
41564
|
+
fail({ status: "timeout", culpritIndex: void 0, elapsedMs: 0 });
|
|
41565
|
+
return;
|
|
41566
|
+
}
|
|
41125
41567
|
const started = ensureWorker();
|
|
41126
41568
|
if (!(started instanceof Worker)) {
|
|
41127
41569
|
broken = started.error;
|
|
@@ -41129,11 +41571,11 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
41129
41571
|
return;
|
|
41130
41572
|
}
|
|
41131
41573
|
const id = nextJobId++;
|
|
41132
|
-
const now = performance.now();
|
|
41133
41574
|
const job = {
|
|
41134
41575
|
id,
|
|
41135
41576
|
worker: started,
|
|
41136
41577
|
budgetMs: spec.budgetMs,
|
|
41578
|
+
deadlineAt,
|
|
41137
41579
|
startedAt: now,
|
|
41138
41580
|
progressIndex: -1,
|
|
41139
41581
|
progressAt: now,
|
|
@@ -41147,14 +41589,19 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
41147
41589
|
if (readyWorker === started) {
|
|
41148
41590
|
beginDeadline(job);
|
|
41149
41591
|
} else {
|
|
41592
|
+
const startBudget = spec.startBudgetMs ?? startBudgetMs;
|
|
41593
|
+
const callerLimited = deadlineAt !== void 0 && deadlineAt - now < startBudget;
|
|
41594
|
+
const startWaitMs = callerLimited ? deadlineAt - now : startBudget;
|
|
41150
41595
|
job.startupTimer = setTimeout(() => {
|
|
41151
41596
|
if (pending !== job) return;
|
|
41152
41597
|
kill(job.worker);
|
|
41153
|
-
failPending(
|
|
41154
|
-
status: "
|
|
41155
|
-
|
|
41156
|
-
|
|
41157
|
-
|
|
41598
|
+
failPending(
|
|
41599
|
+
callerLimited ? { status: "timeout", culpritIndex: void 0, elapsedMs: performance.now() - now } : {
|
|
41600
|
+
status: "unavailable",
|
|
41601
|
+
reason: `the scan worker did not start within ${String(startBudget)}ms`
|
|
41602
|
+
}
|
|
41603
|
+
);
|
|
41604
|
+
}, startWaitMs);
|
|
41158
41605
|
}
|
|
41159
41606
|
try {
|
|
41160
41607
|
started.postMessage(spec.build(id));
|
|
@@ -41183,7 +41630,9 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
41183
41630
|
return enqueue((resolve4) => {
|
|
41184
41631
|
runOne(
|
|
41185
41632
|
{
|
|
41186
|
-
budgetMs,
|
|
41633
|
+
budgetMs: scanOpts?.budgetMs ?? budgetMs,
|
|
41634
|
+
startBudgetMs: scanOpts?.startBudgetMs,
|
|
41635
|
+
deadlineAt: scanOpts?.deadlineAt,
|
|
41187
41636
|
build: (id) => ({
|
|
41188
41637
|
kind: "scan",
|
|
41189
41638
|
id,
|
|
@@ -41377,6 +41826,9 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
41377
41826
|
let unverified = partition.unverified;
|
|
41378
41827
|
let isolated = unverified.length > 0 ? createIsolatedScanner({ verified, unverified }, opts) : void 0;
|
|
41379
41828
|
let retired = false;
|
|
41829
|
+
let bounded;
|
|
41830
|
+
let boundedWarned = false;
|
|
41831
|
+
let closed = false;
|
|
41380
41832
|
function inProcess(text, context) {
|
|
41381
41833
|
return scan(text, verified, context);
|
|
41382
41834
|
}
|
|
@@ -41438,71 +41890,59 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
41438
41890
|
await degrade();
|
|
41439
41891
|
return inProcess(text, context);
|
|
41440
41892
|
}
|
|
41893
|
+
async function scanBounded(text, context, bound) {
|
|
41894
|
+
const remainingMs = bound.remainingMs;
|
|
41895
|
+
let outcome;
|
|
41896
|
+
if (closed) {
|
|
41897
|
+
outcome = { status: "unavailable", reason: "the scan worker is closed" };
|
|
41898
|
+
} else if (remainingMs !== void 0 && !(remainingMs > 0)) {
|
|
41899
|
+
outcome = { status: "timeout", culpritIndex: void 0, elapsedMs: 0 };
|
|
41900
|
+
} else {
|
|
41901
|
+
bounded ??= createIsolatedScanner({ verified, unverified }, opts);
|
|
41902
|
+
const deadlineAt = remainingMs === void 0 ? void 0 : performance.now() + remainingMs;
|
|
41903
|
+
try {
|
|
41904
|
+
outcome = await bounded.scan(text, context, {
|
|
41905
|
+
budgetMs: bound.budgetMs,
|
|
41906
|
+
startBudgetMs: bound.startBudgetMs,
|
|
41907
|
+
deadlineAt
|
|
41908
|
+
});
|
|
41909
|
+
} catch (error62) {
|
|
41910
|
+
outcome = {
|
|
41911
|
+
status: "unavailable",
|
|
41912
|
+
reason: error62 instanceof Error ? error62.message : "the scan worker failed unexpectedly"
|
|
41913
|
+
};
|
|
41914
|
+
}
|
|
41915
|
+
}
|
|
41916
|
+
if (outcome.status !== "ok" && !boundedWarned) {
|
|
41917
|
+
boundedWarned = true;
|
|
41918
|
+
process.stderr.write(
|
|
41919
|
+
outcome.status === "timeout" ? `[aka] a large input could not be scanned within its time limit and was refused.
|
|
41920
|
+
` : `[aka] a large input could not be scanned and was refused: ${outcome.reason}.
|
|
41921
|
+
`
|
|
41922
|
+
);
|
|
41923
|
+
}
|
|
41924
|
+
return outcome;
|
|
41925
|
+
}
|
|
41441
41926
|
return {
|
|
41442
41927
|
scan: guardedScan,
|
|
41928
|
+
scanBounded,
|
|
41443
41929
|
degraded: () => retired,
|
|
41444
41930
|
async close() {
|
|
41445
|
-
|
|
41931
|
+
closed = true;
|
|
41932
|
+
const live = bounded;
|
|
41933
|
+
bounded = void 0;
|
|
41934
|
+
await Promise.all([retire(), live?.close()]);
|
|
41446
41935
|
}
|
|
41447
41936
|
};
|
|
41448
41937
|
}
|
|
41449
41938
|
|
|
41450
|
-
// ../../packages/plugin-sdk/src/hook-fail-opens.ts
|
|
41451
|
-
import { readFileSync as readFileSync12 } from "fs";
|
|
41452
|
-
import { join as join19 } from "path";
|
|
41453
|
-
|
|
41454
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
41455
|
-
import { readFileSync as readFileSync14 } from "fs";
|
|
41456
|
-
import { join as join21 } from "path";
|
|
41457
|
-
|
|
41458
|
-
// ../../packages/plugin-sdk/src/model-governance.ts
|
|
41459
|
-
import {
|
|
41460
|
-
closeSync as closeSync2,
|
|
41461
|
-
fstatSync,
|
|
41462
|
-
mkdirSync as mkdirSync2,
|
|
41463
|
-
openSync as openSync2,
|
|
41464
|
-
readFileSync as readFileSync13,
|
|
41465
|
-
readSync,
|
|
41466
|
-
writeFileSync as writeFileSync5
|
|
41467
|
-
} from "fs";
|
|
41468
|
-
import { join as join20 } from "path";
|
|
41469
|
-
var TAIL_BYTES = 256 * 1024;
|
|
41470
|
-
|
|
41471
|
-
// ../../packages/plugin-sdk/src/host-floor.ts
|
|
41472
|
-
var HOST_FEATURE = {
|
|
41473
|
-
ModelSwitch: "model-switch",
|
|
41474
|
-
VaultPointerDisplay: "vault-pointer-display"
|
|
41475
|
-
};
|
|
41476
|
-
var HOST_FLOORS = {
|
|
41477
|
-
[HOST_FEATURE.ModelSwitch]: {
|
|
41478
|
-
label: "model-switch protection",
|
|
41479
|
-
hookEvents: ["PreModelSwitch", "PostModelSwitch"],
|
|
41480
|
-
since: "2.1.251"
|
|
41481
|
-
},
|
|
41482
|
-
[HOST_FEATURE.VaultPointerDisplay]: {
|
|
41483
|
-
label: "vault pointer display",
|
|
41484
|
-
hookEvents: ["MessageDisplay"],
|
|
41485
|
-
since: "2.1.152"
|
|
41486
|
-
}
|
|
41487
|
-
};
|
|
41488
|
-
var ANTIGRAVITY_HOST_FEATURE = {
|
|
41489
|
-
EndOfTurnCapture: "end-of-turn-capture"
|
|
41490
|
-
};
|
|
41491
|
-
var ANTIGRAVITY_HOST_FLOORS = {
|
|
41492
|
-
[ANTIGRAVITY_HOST_FEATURE.EndOfTurnCapture]: {
|
|
41493
|
-
label: "end-of-turn history capture",
|
|
41494
|
-
hookEvents: ["Stop"],
|
|
41495
|
-
since: "1.1.10"
|
|
41496
|
-
}
|
|
41497
|
-
};
|
|
41498
|
-
|
|
41499
41939
|
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
41500
41940
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
41501
|
-
import { readFileSync as
|
|
41502
|
-
import { join as
|
|
41941
|
+
import { readFileSync as readFileSync12 } from "fs";
|
|
41942
|
+
import { join as join19 } from "path";
|
|
41503
41943
|
function readIgnoreLayer(dir, filename, anchorLen) {
|
|
41504
41944
|
try {
|
|
41505
|
-
return { matcher: (0, import_ignore.default)().add(
|
|
41945
|
+
return { matcher: (0, import_ignore.default)().add(readFileSync12(join19(dir, filename), "utf8")), anchorLen };
|
|
41506
41946
|
} catch {
|
|
41507
41947
|
return void 0;
|
|
41508
41948
|
}
|
|
@@ -41529,16 +41969,9 @@ function withLayer(layers, layer) {
|
|
|
41529
41969
|
return layer ? [...layers, layer] : layers;
|
|
41530
41970
|
}
|
|
41531
41971
|
|
|
41532
|
-
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
41533
|
-
import { arch, hostname as hostname4, platform, release } from "os";
|
|
41534
|
-
|
|
41535
|
-
// ../../packages/plugin-sdk/src/nudge.ts
|
|
41536
|
-
import { mkdirSync as mkdirSync3, readFileSync as readFileSync16, writeFileSync as writeFileSync6 } from "fs";
|
|
41537
|
-
import { join as join23 } from "path";
|
|
41538
|
-
|
|
41539
41972
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
41540
|
-
import { readdirSync as
|
|
41541
|
-
import { basename as
|
|
41973
|
+
import { readdirSync as readdirSync2, realpathSync as realpathSync2 } from "fs";
|
|
41974
|
+
import { basename as basename3, dirname as dirname5, sep as sep3 } from "path";
|
|
41542
41975
|
function toPosix(path) {
|
|
41543
41976
|
return path.split(sep3).join("/");
|
|
41544
41977
|
}
|
|
@@ -41556,7 +41989,7 @@ function findProjectRoot(startDir, recognizeMarker) {
|
|
|
41556
41989
|
}
|
|
41557
41990
|
function directoryHasMarker(dir, recognizeMarker) {
|
|
41558
41991
|
try {
|
|
41559
|
-
for (const entry of
|
|
41992
|
+
for (const entry of readdirSync2(dir, { withFileTypes: true })) {
|
|
41560
41993
|
if (entry.isFile() && recognizeMarker(entry.name) != null) return true;
|
|
41561
41994
|
}
|
|
41562
41995
|
} catch {
|
|
@@ -41566,8 +41999,8 @@ function directoryHasMarker(dir, recognizeMarker) {
|
|
|
41566
41999
|
}
|
|
41567
42000
|
function resolveNonGitProject(startDir, recognizeMarker) {
|
|
41568
42001
|
const projectRoot = findProjectRoot(startDir, recognizeMarker);
|
|
41569
|
-
const realRoot =
|
|
41570
|
-
return { root: projectRoot, projectKey: `path:${realRoot}`, project:
|
|
42002
|
+
const realRoot = realpathSync2(projectRoot);
|
|
42003
|
+
return { root: projectRoot, projectKey: `path:${realRoot}`, project: basename3(realRoot) };
|
|
41571
42004
|
}
|
|
41572
42005
|
|
|
41573
42006
|
// ../../packages/plugin-sdk/src/policy-resolver.ts
|
|
@@ -41614,36 +42047,6 @@ function assignedRulePolicies(installed) {
|
|
|
41614
42047
|
return out;
|
|
41615
42048
|
}
|
|
41616
42049
|
|
|
41617
|
-
// ../../packages/plugin-sdk/src/project-files.ts
|
|
41618
|
-
import { existsSync as existsSync11, readdirSync as readdirSync4 } from "fs";
|
|
41619
|
-
import { basename as basename5, join as join24 } from "path";
|
|
41620
|
-
|
|
41621
|
-
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
41622
|
-
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
41623
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
41624
|
-
return v;
|
|
41625
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
41626
|
-
var optionalFlag = external_exports.preprocess((v) => {
|
|
41627
|
-
if (typeof v !== "string") return false;
|
|
41628
|
-
const normalized = v.trim().toLowerCase();
|
|
41629
|
-
return normalized !== "" && normalized !== "0" && normalized !== "false";
|
|
41630
|
-
}, external_exports.boolean()).catch(false);
|
|
41631
|
-
var antigravityProviderEnvShape = {
|
|
41632
|
-
GOOGLE_GENAI_USE_VERTEXAI: optionalFlag,
|
|
41633
|
-
GOOGLE_GEMINI_BASE_URL: optionalBaseUrl2
|
|
41634
|
-
};
|
|
41635
|
-
var AntigravityProviderEnvSchema = external_exports.object(antigravityProviderEnvShape);
|
|
41636
|
-
|
|
41637
|
-
// ../../packages/plugin-sdk/src/provider-env-codex.ts
|
|
41638
|
-
var optionalBaseUrl3 = external_exports.preprocess((v) => {
|
|
41639
|
-
if (typeof v === "string" && v.trim() === "") return void 0;
|
|
41640
|
-
return v;
|
|
41641
|
-
}, external_exports.string().optional()).catch(void 0);
|
|
41642
|
-
var codexProviderEnvShape = {
|
|
41643
|
-
OPENAI_BASE_URL: optionalBaseUrl3
|
|
41644
|
-
};
|
|
41645
|
-
var CodexProviderEnvSchema = external_exports.object(codexProviderEnvShape);
|
|
41646
|
-
|
|
41647
42050
|
// ../../packages/plugin-sdk/src/runtime.ts
|
|
41648
42051
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
41649
42052
|
var ENFORCEMENT_CEILING_ENABLED = false;
|
|
@@ -41684,6 +42087,16 @@ function conditionsMatch(conditions, ctx) {
|
|
|
41684
42087
|
if (conditions.provider !== void 0) return false;
|
|
41685
42088
|
return true;
|
|
41686
42089
|
}
|
|
42090
|
+
function readRemainingMs(largeInput) {
|
|
42091
|
+
const read = largeInput.remainingMs;
|
|
42092
|
+
if (read === void 0) return void 0;
|
|
42093
|
+
try {
|
|
42094
|
+
const remaining = read();
|
|
42095
|
+
return typeof remaining !== "number" || Number.isNaN(remaining) ? 0 : remaining;
|
|
42096
|
+
} catch {
|
|
42097
|
+
return 0;
|
|
42098
|
+
}
|
|
42099
|
+
}
|
|
41687
42100
|
var bundlesPacked = false;
|
|
41688
42101
|
function createPluginRuntime(gateway, settings, opts) {
|
|
41689
42102
|
if (!bundlesPacked) {
|
|
@@ -41693,6 +42106,7 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
41693
42106
|
const policyMode = settings.policy;
|
|
41694
42107
|
let redactFallback = settings.redactFallback;
|
|
41695
42108
|
const dataDir2 = opts?.dataDir;
|
|
42109
|
+
const largeInput = opts?.largeInput;
|
|
41696
42110
|
let rules = [];
|
|
41697
42111
|
let evidenceOf = evidenceLookup(rules);
|
|
41698
42112
|
let scanner;
|
|
@@ -41905,7 +42319,24 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
41905
42319
|
await ensureInitialized();
|
|
41906
42320
|
if (!scanner) throw new Error("the runtime initialized without a scanner");
|
|
41907
42321
|
const shielded = shieldPointers(text);
|
|
41908
|
-
|
|
42322
|
+
let matched;
|
|
42323
|
+
if (largeInput !== void 0 && shielded.text.length >= largeInput.thresholdChars) {
|
|
42324
|
+
const outcome = await scanner.scanBounded(shielded.text, context, {
|
|
42325
|
+
budgetMs: largeInput.budgetMs,
|
|
42326
|
+
startBudgetMs: largeInput.startBudgetMs,
|
|
42327
|
+
remainingMs: readRemainingMs(largeInput)
|
|
42328
|
+
});
|
|
42329
|
+
if (outcome.status !== "ok") {
|
|
42330
|
+
return {
|
|
42331
|
+
decision: { action: "block", text: null, findings: [], scanIncomplete: outcome.status },
|
|
42332
|
+
excepted: /* @__PURE__ */ new Set(),
|
|
42333
|
+
exceptionIds: []
|
|
42334
|
+
};
|
|
42335
|
+
}
|
|
42336
|
+
matched = outcome.findings;
|
|
42337
|
+
} else {
|
|
42338
|
+
matched = await scanner.scan(shielded.text, context);
|
|
42339
|
+
}
|
|
41909
42340
|
const findings = dropShieldedFindings(matched, shielded.spans);
|
|
41910
42341
|
const fpCache = /* @__PURE__ */ new Map();
|
|
41911
42342
|
const { excepted, exceptionIds } = await applyExceptions(findings, ctx, fpCache);
|
|
@@ -41930,12 +42361,11 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
41930
42361
|
async function processText(text, context, opts2 = {}) {
|
|
41931
42362
|
return (await evaluate(text, context, {}, opts2.rewritable)).decision;
|
|
41932
42363
|
}
|
|
41933
|
-
async function
|
|
42364
|
+
async function evaluateCapture(input2, opts2) {
|
|
41934
42365
|
const timingStartedAt = input2.occurredAt === void 0 ? startTiming() : void 0;
|
|
41935
|
-
const filePath = input2.metadata?.filePath;
|
|
41936
42366
|
const { decision, excepted, exceptionIds } = await evaluate(
|
|
41937
42367
|
input2.text,
|
|
41938
|
-
{ filePath, eventKind: input2.kind },
|
|
42368
|
+
{ filePath: input2.metadata?.filePath, eventKind: input2.kind },
|
|
41939
42369
|
{
|
|
41940
42370
|
sourceTool: input2.sourceTool,
|
|
41941
42371
|
metadata: input2.metadata,
|
|
@@ -41943,20 +42373,28 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
41943
42373
|
},
|
|
41944
42374
|
opts2.rewritable
|
|
41945
42375
|
);
|
|
41946
|
-
|
|
42376
|
+
return { decision, excepted, exceptionIds, timingStartedAt };
|
|
42377
|
+
}
|
|
42378
|
+
async function persistCapture(input2, opts2, { decision, excepted, exceptionIds, timingStartedAt }) {
|
|
42379
|
+
const filePath = input2.metadata?.filePath;
|
|
42380
|
+
if (opts2.persist === "with-findings" && decision.findings.length === 0 && decision.scanIncomplete === void 0) {
|
|
42381
|
+
return;
|
|
42382
|
+
}
|
|
41947
42383
|
try {
|
|
41948
42384
|
const contentHash = contentHashOf(input2.text);
|
|
41949
42385
|
const maskedFindings = decision.findings.filter(
|
|
41950
42386
|
(match) => isActionAtLeast(actionForFinding(match, excepted, opts2.rewritable), "redact")
|
|
41951
42387
|
);
|
|
41952
|
-
const storedContent = maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
|
|
42388
|
+
const storedContent = decision.scanIncomplete !== void 0 ? "" : maskedFindings.length > 0 ? redact(input2.text, maskedFindings) : input2.text;
|
|
41953
42389
|
const inspectionMs = elapsedMs(timingStartedAt);
|
|
41954
42390
|
const redactDegradedTo = decision.redactDegradedTo;
|
|
41955
|
-
const
|
|
42391
|
+
const scanIncomplete = decision.scanIncomplete;
|
|
42392
|
+
const metadata = exceptionIds.length > 0 || inspectionMs !== void 0 || redactDegradedTo !== void 0 || scanIncomplete !== void 0 ? {
|
|
41956
42393
|
...input2.metadata,
|
|
41957
42394
|
...exceptionIds.length > 0 ? { exceptionIds } : {},
|
|
41958
42395
|
...inspectionMs !== void 0 ? { inspectionMs } : {},
|
|
41959
|
-
...redactDegradedTo !== void 0 ? { redactDegradedTo } : {}
|
|
42396
|
+
...redactDegradedTo !== void 0 ? { redactDegradedTo } : {},
|
|
42397
|
+
...scanIncomplete !== void 0 ? { scanIncomplete } : {}
|
|
41960
42398
|
} : input2.metadata;
|
|
41961
42399
|
const event = buildIngestEvent({
|
|
41962
42400
|
kind: input2.kind,
|
|
@@ -41986,6 +42424,8 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
41986
42424
|
// exceptions/blocked_detections when a key is available;
|
|
41987
42425
|
// falls back to the masked match so at-rest findings still get
|
|
41988
42426
|
// a stable (if weaker) identity on a workspace with no dataDir.
|
|
42427
|
+
// Both ignore the same invisible padding, so a clean and a
|
|
42428
|
+
// padded occurrence of one secret key alike on either path.
|
|
41989
42429
|
valueFingerprint: findingKeyFingerprintKey ? fingerprintOf(findingKeyFingerprintKey, match, findingKeyFpCache) : maskedMatch
|
|
41990
42430
|
}) : void 0;
|
|
41991
42431
|
return {
|
|
@@ -42013,7 +42453,37 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
42013
42453
|
}
|
|
42014
42454
|
} catch {
|
|
42015
42455
|
}
|
|
42016
|
-
|
|
42456
|
+
}
|
|
42457
|
+
async function enforcedIn(text, context) {
|
|
42458
|
+
try {
|
|
42459
|
+
await ensureInitialized();
|
|
42460
|
+
if (!scanner) return [];
|
|
42461
|
+
const shielded = shieldPointers(text);
|
|
42462
|
+
const matched = await scanner.scan(shielded.text, context);
|
|
42463
|
+
return dropShieldedFindings(matched, shielded.spans).filter((finding) => {
|
|
42464
|
+
const action = resolveAction(finding.ruleId, finding.category);
|
|
42465
|
+
return action === "block" || action === "redact";
|
|
42466
|
+
});
|
|
42467
|
+
} catch {
|
|
42468
|
+
return [];
|
|
42469
|
+
}
|
|
42470
|
+
}
|
|
42471
|
+
async function capture(input2, opts2 = {}) {
|
|
42472
|
+
const evaluated = await evaluateCapture(input2, opts2);
|
|
42473
|
+
await persistCapture(input2, opts2, evaluated);
|
|
42474
|
+
return evaluated.decision;
|
|
42475
|
+
}
|
|
42476
|
+
async function captureDeferred(input2, opts2 = {}) {
|
|
42477
|
+
const evaluated = await evaluateCapture(input2, opts2);
|
|
42478
|
+
let recorded = false;
|
|
42479
|
+
return {
|
|
42480
|
+
result: evaluated.decision,
|
|
42481
|
+
record: async () => {
|
|
42482
|
+
if (recorded) return;
|
|
42483
|
+
recorded = true;
|
|
42484
|
+
await persistCapture(input2, opts2, evaluated);
|
|
42485
|
+
}
|
|
42486
|
+
};
|
|
42017
42487
|
}
|
|
42018
42488
|
async function rulesetFingerprint() {
|
|
42019
42489
|
try {
|
|
@@ -42034,23 +42504,20 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
42034
42504
|
}
|
|
42035
42505
|
await gateway.close();
|
|
42036
42506
|
}
|
|
42037
|
-
return {
|
|
42507
|
+
return {
|
|
42508
|
+
processText,
|
|
42509
|
+
capture,
|
|
42510
|
+
captureDeferred,
|
|
42511
|
+
enforcedIn,
|
|
42512
|
+
rulesetFingerprint,
|
|
42513
|
+
scanIsolationDegraded,
|
|
42514
|
+
close
|
|
42515
|
+
};
|
|
42038
42516
|
}
|
|
42039
42517
|
|
|
42040
|
-
// ../../packages/plugin-sdk/src/scope-key.ts
|
|
42041
|
-
import { existsSync as existsSync12 } from "fs";
|
|
42042
|
-
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join25, normalize } from "path";
|
|
42043
|
-
|
|
42044
|
-
// ../../packages/plugin-sdk/src/suppressions.ts
|
|
42045
|
-
var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
42046
|
-
|
|
42047
|
-
// ../../packages/plugin-sdk/src/throttle.ts
|
|
42048
|
-
import { mkdirSync as mkdirSync4, statSync as statSync8, writeFileSync as writeFileSync7 } from "fs";
|
|
42049
|
-
import { join as join26 } from "path";
|
|
42050
|
-
|
|
42051
42518
|
// ../../packages/scanner/src/discover.ts
|
|
42052
|
-
import { readdirSync as
|
|
42053
|
-
import { join as
|
|
42519
|
+
import { readdirSync as readdirSync3 } from "fs";
|
|
42520
|
+
import { join as join20 } from "path";
|
|
42054
42521
|
|
|
42055
42522
|
// ../../packages/scanner/src/constants.ts
|
|
42056
42523
|
var COMMON_SKIP_DIRS = ["node_modules", "__pycache__", ".venv", "venv", ".cache"];
|
|
@@ -42079,7 +42546,7 @@ function discoverGitRepos(opts) {
|
|
|
42079
42546
|
if (depth > maxDepth || excludePaths.has(dir)) return;
|
|
42080
42547
|
let entries;
|
|
42081
42548
|
try {
|
|
42082
|
-
entries =
|
|
42549
|
+
entries = readdirSync3(dir, { withFileTypes: true, encoding: "utf8" });
|
|
42083
42550
|
} catch {
|
|
42084
42551
|
return;
|
|
42085
42552
|
}
|
|
@@ -42095,7 +42562,7 @@ function discoverGitRepos(opts) {
|
|
|
42095
42562
|
if (!entry.isDirectory()) continue;
|
|
42096
42563
|
if (DISCOVER_SKIP.has(entry.name)) continue;
|
|
42097
42564
|
if (entry.name.startsWith(".")) continue;
|
|
42098
|
-
visit2(
|
|
42565
|
+
visit2(join20(dir, entry.name), depth + 1);
|
|
42099
42566
|
}
|
|
42100
42567
|
}
|
|
42101
42568
|
for (const root of searchRoots) {
|
|
@@ -42105,7 +42572,7 @@ function discoverGitRepos(opts) {
|
|
|
42105
42572
|
}
|
|
42106
42573
|
|
|
42107
42574
|
// ../../packages/scanner/src/render.ts
|
|
42108
|
-
import { basename as
|
|
42575
|
+
import { basename as basename4, relative } from "path";
|
|
42109
42576
|
var SEVERITY_ORDER = ["critical", "high", "medium", "low"];
|
|
42110
42577
|
var SEVERITY_GLYPH = {
|
|
42111
42578
|
critical: "\u2588",
|
|
@@ -42185,7 +42652,7 @@ function renderMultiRepoSummary(summary, opts = {}) {
|
|
|
42185
42652
|
"\n"
|
|
42186
42653
|
);
|
|
42187
42654
|
}
|
|
42188
|
-
const repoRows = summary.repos.filter((r) => r.summary.scanned > 0 || r.summary.findings > 0).map((r) => [
|
|
42655
|
+
const repoRows = summary.repos.filter((r) => r.summary.scanned > 0 || r.summary.findings > 0).map((r) => [basename4(r.rootDir), String(r.summary.scanned), String(r.summary.findings)]);
|
|
42189
42656
|
const repoSection = repoRows.length > 0 ? ["", indent(table(["REPO", "SCANNED", "FINDINGS"], repoRows))].join("\n") : "";
|
|
42190
42657
|
return [
|
|
42191
42658
|
"\u2713 Multi-repo scan complete",
|
|
@@ -42198,8 +42665,8 @@ function renderMultiRepoSummary(summary, opts = {}) {
|
|
|
42198
42665
|
}
|
|
42199
42666
|
|
|
42200
42667
|
// ../../packages/scanner/src/scan.ts
|
|
42201
|
-
import { existsSync as
|
|
42202
|
-
import { extname as extname2, isAbsolute as
|
|
42668
|
+
import { existsSync as existsSync12, readFileSync as readFileSync18 } from "fs";
|
|
42669
|
+
import { extname as extname2, isAbsolute as isAbsolute2, relative as relative3 } from "path";
|
|
42203
42670
|
|
|
42204
42671
|
// ../../packages/remote/src/http.ts
|
|
42205
42672
|
import { request as httpRequest } from "http";
|
|
@@ -42577,11 +43044,11 @@ function withTimeout(promise2, ms) {
|
|
|
42577
43044
|
}
|
|
42578
43045
|
|
|
42579
43046
|
// ../../packages/plugin-runtime/src/attached/forward-drops.ts
|
|
42580
|
-
import { readFileSync as
|
|
42581
|
-
import { join as
|
|
43047
|
+
import { readFileSync as readFileSync13 } from "fs";
|
|
43048
|
+
import { join as join21 } from "path";
|
|
42582
43049
|
var FORWARD_DROPS_FILENAME = ATTACHED_FORWARD_DROPS_FILENAME;
|
|
42583
43050
|
function forwardDropsPath(dataDir2) {
|
|
42584
|
-
return
|
|
43051
|
+
return join21(dataDir2, FORWARD_DROPS_FILENAME);
|
|
42585
43052
|
}
|
|
42586
43053
|
function recordForwardDrops(dataDir2, count, nowMs) {
|
|
42587
43054
|
if (count <= 0) return;
|
|
@@ -42599,7 +43066,7 @@ function recordForwardDrops(dataDir2, count, nowMs) {
|
|
|
42599
43066
|
}
|
|
42600
43067
|
function readForwardDrops(dataDir2) {
|
|
42601
43068
|
try {
|
|
42602
|
-
const parsed2 = JSON.parse(
|
|
43069
|
+
const parsed2 = JSON.parse(readFileSync13(forwardDropsPath(dataDir2), "utf8"));
|
|
42603
43070
|
if (typeof parsed2 !== "object" || parsed2 === null) return null;
|
|
42604
43071
|
const record2 = parsed2;
|
|
42605
43072
|
if (typeof record2.droppedForwards !== "number" || !Number.isFinite(record2.droppedForwards)) {
|
|
@@ -42618,7 +43085,7 @@ function readForwardDrops(dataDir2) {
|
|
|
42618
43085
|
// ../../packages/plugin-runtime/src/attached/forward-policy.ts
|
|
42619
43086
|
import { randomUUID as randomUUID16 } from "crypto";
|
|
42620
43087
|
import { readFile, rename, writeFile } from "fs/promises";
|
|
42621
|
-
import { join as
|
|
43088
|
+
import { join as join22 } from "path";
|
|
42622
43089
|
function isInvalidRequest(err) {
|
|
42623
43090
|
return typeof err === "object" && err !== null && err.name === "RemoteRequestInvalid";
|
|
42624
43091
|
}
|
|
@@ -42637,7 +43104,7 @@ var FORWARD_STATE_FILENAME = ATTACHED_FORWARD_STATE_FILENAME;
|
|
|
42637
43104
|
var STATE_FILENAME = FORWARD_STATE_FILENAME;
|
|
42638
43105
|
function createForwardPolicy(deps) {
|
|
42639
43106
|
const now = deps.now ?? (() => Date.now());
|
|
42640
|
-
const file2 =
|
|
43107
|
+
const file2 = join22(deps.dir, STATE_FILENAME);
|
|
42641
43108
|
let state = null;
|
|
42642
43109
|
let loading = null;
|
|
42643
43110
|
async function readState() {
|
|
@@ -42803,6 +43270,9 @@ var AttachedDataGateway = class {
|
|
|
42803
43270
|
*
|
|
42804
43271
|
* Machine mode answers before any key is read, so a machine attachment pays
|
|
42805
43272
|
* nothing for scoping and forwards exactly what it always has.
|
|
43273
|
+
*
|
|
43274
|
+
* `governanceAppliesTo` answers from this same verdict, so it agrees with
|
|
43275
|
+
* forwarding key for key.
|
|
42806
43276
|
*/
|
|
42807
43277
|
verdictFor(keyOf) {
|
|
42808
43278
|
try {
|
|
@@ -42819,24 +43289,27 @@ var AttachedDataGateway = class {
|
|
|
42819
43289
|
* the key its row holds in the local store, recorded per root (see
|
|
42820
43290
|
* `rootVerdict`), not the key on the root event just handed in: roots are
|
|
42821
43291
|
* first-write-wins in the store, so when two producers record a root for one
|
|
42822
|
-
* session (the session-start hook, then a reconcile pass) the second leaves
|
|
42823
|
-
*
|
|
42824
|
-
*
|
|
42825
|
-
*
|
|
42826
|
-
*
|
|
42827
|
-
*
|
|
42828
|
-
*
|
|
42829
|
-
*
|
|
42830
|
-
*
|
|
42831
|
-
*
|
|
42832
|
-
*
|
|
42833
|
-
*
|
|
42834
|
-
*
|
|
42835
|
-
*
|
|
42836
|
-
*
|
|
42837
|
-
*
|
|
42838
|
-
*
|
|
42839
|
-
*
|
|
43292
|
+
* session (the session-start hook, then a reconcile pass) the second leaves the
|
|
43293
|
+
* stored row as it was. That stored row, not this event, is what a history
|
|
43294
|
+
* drain pass would decide, if the root started before the attach; the drain
|
|
43295
|
+
* never offers one that started after it (`started_at < backlogBefore`).
|
|
43296
|
+
* Whether this root EVENT is itself sent takes both keys: the stored one AND
|
|
43297
|
+
* its own. The event's attributes (cwd, project, repo) describe where it was
|
|
43298
|
+
* recorded from, so a root event keyed to a personal directory is never sent
|
|
43299
|
+
* under an enrolled stored root, though the enrolled leaves still forward under
|
|
43300
|
+
* it: the instance that wrote the stored root is expected to have forwarded it.
|
|
43301
|
+
* If it did not (the root was written while standalone or under another
|
|
43302
|
+
* attachment, or its forward failed), the plane refuses those leaves. A root
|
|
43303
|
+
* that started before the attach is shipped, ahead of its leaves, by the
|
|
43304
|
+
* history drain; one that started after it is never offered by the drain. Any
|
|
43305
|
+
* other row with a root reference (`rootSessionId`, else `parentId`) forwards
|
|
43306
|
+
* only when its own key is in scope AND this instance recorded an in-scope
|
|
43307
|
+
* verdict for that root. The audit-event route has real foreign keys on both
|
|
43308
|
+
* columns and stubs no missing root, so a leaf sent after its root was kept
|
|
43309
|
+
* local is refused there, and a refused forward counts toward the breaker that
|
|
43310
|
+
* guards every other one. A root this instance never recorded is therefore
|
|
43311
|
+
* `'local'`: the only answer that cannot orphan a row. A row with no root
|
|
43312
|
+
* reference at all has nothing to orphan, and is decided by its own key.
|
|
42840
43313
|
*
|
|
42841
43314
|
* What this costs is stated rather than discovered. A session whose stored
|
|
42842
43315
|
* root is not keyed to an enrolled repository keeps its token and tool
|
|
@@ -42907,6 +43380,87 @@ var AttachedDataGateway = class {
|
|
|
42907
43380
|
return [];
|
|
42908
43381
|
}
|
|
42909
43382
|
}
|
|
43383
|
+
/**
|
|
43384
|
+
* The verdict for the repositories nested in a scanned project, answered
|
|
43385
|
+
* TOTALLY: `'forward'` or `'local'`, never a throw.
|
|
43386
|
+
*
|
|
43387
|
+
* A walk descends into a nested clone or submodule and folds its files into
|
|
43388
|
+
* the project it is walking, so one register can carry several
|
|
43389
|
+
* repositories' call sites under one project key. Each of them must be in
|
|
43390
|
+
* scope for it to forward. One key out of scope, or a nested repository with
|
|
43391
|
+
* no remote (an `undefined` key), keeps the whole register local.
|
|
43392
|
+
*
|
|
43393
|
+
* An ABSENT list is `'local'` too. Only the code that walked the tree can say
|
|
43394
|
+
* what is nested in it, and every scan passes the list, empty when nothing
|
|
43395
|
+
* is nested. A register nobody vouched for is not one a scoped attachment
|
|
43396
|
+
* may send.
|
|
43397
|
+
*
|
|
43398
|
+
* Machine mode answers before reading the context, so a machine attachment
|
|
43399
|
+
* forwards exactly what it always has.
|
|
43400
|
+
*/
|
|
43401
|
+
nestedVerdict(context) {
|
|
43402
|
+
try {
|
|
43403
|
+
if (this.deps.attachment.mode === "machine") return "forward";
|
|
43404
|
+
const keys = context?.nestedScopeKeys;
|
|
43405
|
+
if (keys === void 0) return "local";
|
|
43406
|
+
for (const key of keys) {
|
|
43407
|
+
if (this.verdictFor(() => key) === "local") return "local";
|
|
43408
|
+
}
|
|
43409
|
+
return "forward";
|
|
43410
|
+
} catch {
|
|
43411
|
+
return "local";
|
|
43412
|
+
}
|
|
43413
|
+
}
|
|
43414
|
+
/**
|
|
43415
|
+
* The register a scoped attachment sends, once the project and the repositories
|
|
43416
|
+
* nested in it are in scope: the register itself, with `reconcile.deletedFiles`
|
|
43417
|
+
* cut to the deleted paths whose own repository is in scope. `undefined` sends
|
|
43418
|
+
* nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
43419
|
+
*
|
|
43420
|
+
* The deletion sweep takes its paths from the scan ledger, not from the walk,
|
|
43421
|
+
* and the ledger holds every file the scanner ever read under the root, nested
|
|
43422
|
+
* clones' included. So a clone that was removed, or one an ignore file now
|
|
43423
|
+
* hides, is in no walk and never reaches `nestedVerdict`, yet its ledgered
|
|
43424
|
+
* paths come back as deleted. The scan names the repository of each deleted
|
|
43425
|
+
* path (`context.deletedFileKeys`, one entry per path in the register's order)
|
|
43426
|
+
* and each is held to the same verdict as any other key. A path whose key is
|
|
43427
|
+
* absent, or out of scope, is not sent.
|
|
43428
|
+
*
|
|
43429
|
+
* The list is asked for here, and only here: it is an async read of the scan
|
|
43430
|
+
* ledger that the scan makes on being called, so a machine attachment, which
|
|
43431
|
+
* returns before this, and a register already kept local never cause it.
|
|
43432
|
+
*
|
|
43433
|
+
* Anything the scan did not vouch for sends no deleted path, and the register
|
|
43434
|
+
* itself still goes: no list, a list that throws or whose read is rejected, or a
|
|
43435
|
+
* list whose length is not the register's. Deleting is the only thing a dropped
|
|
43436
|
+
* path could have done on the server, so the cost of a refusal is a stored row
|
|
43437
|
+
* that stays, never a path that leaves.
|
|
43438
|
+
*
|
|
43439
|
+
* Machine mode returns `input` itself, the same object and unread, so a machine
|
|
43440
|
+
* attachment's request is exactly what it was. A register that lists no deleted
|
|
43441
|
+
* path, or that is not a ledger register, has nothing to cut and is returned
|
|
43442
|
+
* as it came, with the list unread.
|
|
43443
|
+
*/
|
|
43444
|
+
async registerForWire(input2, context) {
|
|
43445
|
+
try {
|
|
43446
|
+
if (this.deps.attachment.mode === "machine") return input2;
|
|
43447
|
+
const { reconcile } = input2;
|
|
43448
|
+
if (reconcile.mode !== "ledger" || reconcile.deletedFiles.length === 0) return input2;
|
|
43449
|
+
const deleted = reconcile.deletedFiles;
|
|
43450
|
+
let kept = [];
|
|
43451
|
+
try {
|
|
43452
|
+
const keys = await context?.deletedFileKeys?.();
|
|
43453
|
+
if (keys?.length === deleted.length) {
|
|
43454
|
+
kept = deleted.filter((_path, at) => this.verdictFor(() => keys[at]) === "forward");
|
|
43455
|
+
}
|
|
43456
|
+
} catch {
|
|
43457
|
+
kept = [];
|
|
43458
|
+
}
|
|
43459
|
+
return { ...input2, reconcile: { ...reconcile, deletedFiles: kept } };
|
|
43460
|
+
} catch {
|
|
43461
|
+
return void 0;
|
|
43462
|
+
}
|
|
43463
|
+
}
|
|
42910
43464
|
/**
|
|
42911
43465
|
* The event `recordCapture` sends for a capture the verdict let through, or
|
|
42912
43466
|
* `undefined` to send nothing. TOTAL, like `verdictFor`, and for its reasons.
|
|
@@ -43232,12 +43786,24 @@ var AttachedDataGateway = class {
|
|
|
43232
43786
|
* payload onto the wire-boundary-safe shape (no snippet, hashed
|
|
43233
43787
|
* projectKey), and its result is discarded: `forward.run` never throws or
|
|
43234
43788
|
* rejects, so there is nothing here to act on.
|
|
43789
|
+
*
|
|
43790
|
+
* `context.nestedScopeKeys` is what the scanner knows and the register does
|
|
43791
|
+
* not say: the key of every repository nested below the scan root, whose
|
|
43792
|
+
* files the walk folded into this register. On a scoped attachment the
|
|
43793
|
+
* register is forwarded only when the project's own key AND every one of
|
|
43794
|
+
* those is in scope (see `nestedVerdict`), and its deleted paths are cut to the
|
|
43795
|
+
* ones whose own repository is in scope (`context.deletedFileKeys`, see
|
|
43796
|
+
* `registerForWire`). Machine mode never reads either, and the local write
|
|
43797
|
+
* never receives the context and gets the register whole.
|
|
43235
43798
|
*/
|
|
43236
|
-
async recordProjectEgress(input2) {
|
|
43799
|
+
async recordProjectEgress(input2, context) {
|
|
43237
43800
|
const summary = await this.deps.local.recordProjectEgress(input2);
|
|
43238
43801
|
if (this.verdictFor(() => scopeKeyOfProjectKey(input2.projectKey)) === "local") return summary;
|
|
43802
|
+
if (this.nestedVerdict(context) === "local") return summary;
|
|
43803
|
+
const register = await this.registerForWire(input2, context);
|
|
43804
|
+
if (register === void 0) return summary;
|
|
43239
43805
|
await this.deps.forward.run(
|
|
43240
|
-
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(
|
|
43806
|
+
() => this.deps.client.recordProjectEgress(toEgressIngestRequest(register))
|
|
43241
43807
|
);
|
|
43242
43808
|
return summary;
|
|
43243
43809
|
}
|
|
@@ -43291,6 +43857,11 @@ var AttachedDataGateway = class {
|
|
|
43291
43857
|
async scanLedgerPaths() {
|
|
43292
43858
|
return this.deps.local.scanLedgerPaths();
|
|
43293
43859
|
}
|
|
43860
|
+
// Delegated, like the path list. An inner gateway that cannot say answers an
|
|
43861
|
+
// empty map, which gives every deleted path no key.
|
|
43862
|
+
async scanLedgerPathKeys() {
|
|
43863
|
+
return await this.deps.local.scanLedgerPathKeys?.() ?? /* @__PURE__ */ new Map();
|
|
43864
|
+
}
|
|
43294
43865
|
async recordScanned(entries) {
|
|
43295
43866
|
return this.deps.local.recordScanned(entries);
|
|
43296
43867
|
}
|
|
@@ -43357,6 +43928,12 @@ var AttachedDataGateway = class {
|
|
|
43357
43928
|
// and the spread above would otherwise drop the field silently — which is
|
|
43358
43929
|
// exactly what it did, leaving the whole control inert on every device
|
|
43359
43930
|
// while every test around it stayed green.
|
|
43931
|
+
//
|
|
43932
|
+
// WHOLE ON EVERY ATTACHMENT. A scoped attachment does not narrow the list
|
|
43933
|
+
// here: the port's `getPolicyBundle()` takes no event, and the runtime
|
|
43934
|
+
// reads this bundle once to build detection, so the detections it carries
|
|
43935
|
+
// apply to every event on the machine. Where a prohibition applies is
|
|
43936
|
+
// answered per event by `governanceAppliesTo` below.
|
|
43360
43937
|
prohibitedModels: cached2.prohibitedModels,
|
|
43361
43938
|
// NAMED for the same reason as the line above, and it is the same defect
|
|
43362
43939
|
// if it is not: `...local` above spreads the DEVICE's bundle, so a field
|
|
@@ -43416,6 +43993,30 @@ var AttachedDataGateway = class {
|
|
|
43416
43993
|
};
|
|
43417
43994
|
}
|
|
43418
43995
|
// ---------------------------------------------------------------------
|
|
43996
|
+
// GovernanceScope — where the organization's model policy applies
|
|
43997
|
+
// ---------------------------------------------------------------------
|
|
43998
|
+
/**
|
|
43999
|
+
* Whether the organization's governance applies to an event keyed `scopeKey`:
|
|
44000
|
+
* the question a model-guard site asks once it has decided to refuse.
|
|
44001
|
+
*
|
|
44002
|
+
* THE FORWARD VERDICT, through `verdictFor`: the answer is whether a capture
|
|
44003
|
+
* with the same key would be forwarded. A machine-wide attachment governs
|
|
44004
|
+
* every event, keyless included, exactly as before. A scoped one governs an
|
|
44005
|
+
* event only when its key names an enrolled repository. An event in a
|
|
44006
|
+
* personal repository, in no repository, with an empty key, or met by a fault
|
|
44007
|
+
* is not governed.
|
|
44008
|
+
*
|
|
44009
|
+
* The event's OWN key, never its session root's. The root rule in
|
|
44010
|
+
* `auditVerdict` decides whether a row can be forwarded without orphaning it;
|
|
44011
|
+
* this decides whether a refusal applies, which is a question about where the
|
|
44012
|
+
* event happened.
|
|
44013
|
+
*
|
|
44014
|
+
* Answered from memory: no store read, no bundle read, nothing sent.
|
|
44015
|
+
*/
|
|
44016
|
+
governanceAppliesTo(scopeKey) {
|
|
44017
|
+
return this.verdictFor(() => scopeKey) === "forward";
|
|
44018
|
+
}
|
|
44019
|
+
// ---------------------------------------------------------------------
|
|
43419
44020
|
// LocalStoreMaintenance — by delegation (D3).
|
|
43420
44021
|
//
|
|
43421
44022
|
// Implementing these is what actually closes the skipped-local-maintenance
|
|
@@ -43524,14 +44125,15 @@ function toWireInspection(insp) {
|
|
|
43524
44125
|
}
|
|
43525
44126
|
|
|
43526
44127
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
43527
|
-
import { createHash as
|
|
43528
|
-
import { hostname as
|
|
44128
|
+
import { createHash as createHash7 } from "crypto";
|
|
44129
|
+
import { hostname as hostname4 } from "os";
|
|
43529
44130
|
|
|
43530
44131
|
// ../../packages/plugin-runtime/src/attached/capture-rebuild.ts
|
|
43531
44132
|
var CORRELATION_ID = EventMetadata.shape.correlationId;
|
|
43532
44133
|
var TRACE_ID = EventMetadata.shape.traceId;
|
|
43533
44134
|
var EXCEPTION_ID = EventMetadata.shape.exceptionIds.unwrap().element;
|
|
43534
44135
|
var REDACT_DEGRADED_TO = EventMetadata.shape.redactDegradedTo.unwrap();
|
|
44136
|
+
var SCAN_INCOMPLETE = EventMetadata.shape.scanIncomplete.unwrap();
|
|
43535
44137
|
|
|
43536
44138
|
// ../../packages/plugin-runtime/src/attached/history-sync.ts
|
|
43537
44139
|
var CAPTURE_BATCH_BYTES = 1024 * 1024;
|
|
@@ -43543,17 +44145,17 @@ var HISTORY_SYNC_THROTTLE_MS = 5 * 60 * 1e3;
|
|
|
43543
44145
|
|
|
43544
44146
|
// ../../packages/plugin-runtime/src/attached/install-record.ts
|
|
43545
44147
|
import { readFile as readFile2, stat } from "fs/promises";
|
|
43546
|
-
import { basename as
|
|
44148
|
+
import { basename as basename5, dirname as dirname6, join as join23, resolve as resolve2 } from "path";
|
|
43547
44149
|
async function readInstalledVersion(installRoot) {
|
|
43548
44150
|
try {
|
|
43549
44151
|
const versionDir = resolve2(installRoot);
|
|
43550
|
-
const pluginDir =
|
|
43551
|
-
const marketplaceDir =
|
|
43552
|
-
const cacheDir =
|
|
43553
|
-
if (
|
|
43554
|
-
const key = `${
|
|
44152
|
+
const pluginDir = dirname6(versionDir);
|
|
44153
|
+
const marketplaceDir = dirname6(pluginDir);
|
|
44154
|
+
const cacheDir = dirname6(marketplaceDir);
|
|
44155
|
+
if (basename5(cacheDir) !== "cache") return null;
|
|
44156
|
+
const key = `${basename5(pluginDir)}@${basename5(marketplaceDir)}`;
|
|
43555
44157
|
const record2 = JSON.parse(
|
|
43556
|
-
await readFile2(
|
|
44158
|
+
await readFile2(join23(dirname6(cacheDir), "installed_plugins.json"), "utf8")
|
|
43557
44159
|
);
|
|
43558
44160
|
const plugins = record2?.plugins;
|
|
43559
44161
|
if (typeof plugins !== "object" || plugins === null || !Object.hasOwn(plugins, key)) {
|
|
@@ -43585,7 +44187,7 @@ async function exists(path) {
|
|
|
43585
44187
|
}
|
|
43586
44188
|
|
|
43587
44189
|
// ../../packages/plugin-runtime/src/attached/plugin-block.ts
|
|
43588
|
-
import { readFileSync as
|
|
44190
|
+
import { readFileSync as readFileSync14 } from "fs";
|
|
43589
44191
|
var INSTALL_RECORD_READ_TIMEOUT_MS = REQUEST_TIMEOUT_MS / 2;
|
|
43590
44192
|
function createPluginBlock(build, policyStore) {
|
|
43591
44193
|
return async () => {
|
|
@@ -43615,7 +44217,7 @@ async function readInstalledVersionBounded(installRoot) {
|
|
|
43615
44217
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
43616
44218
|
import { randomUUID as randomUUID17 } from "crypto";
|
|
43617
44219
|
import { readFile as readFile3, rm, writeFile as writeFile2 } from "fs/promises";
|
|
43618
|
-
import { join as
|
|
44220
|
+
import { join as join24 } from "path";
|
|
43619
44221
|
|
|
43620
44222
|
// ../../packages/plugin-runtime/src/attached/atomic-publish.ts
|
|
43621
44223
|
import { rename as rename2 } from "fs/promises";
|
|
@@ -43644,7 +44246,7 @@ async function publishByRename(tmp, file2, move = rename2) {
|
|
|
43644
44246
|
|
|
43645
44247
|
// ../../packages/plugin-runtime/src/attached/policy-store.ts
|
|
43646
44248
|
function createPolicyStore(dir = dataDir()) {
|
|
43647
|
-
const file2 =
|
|
44249
|
+
const file2 = join24(dir, "policy-cache.json");
|
|
43648
44250
|
async function read() {
|
|
43649
44251
|
try {
|
|
43650
44252
|
const raw = await readFile3(file2, "utf8");
|
|
@@ -43714,8 +44316,8 @@ function createPolicyStore(dir = dataDir()) {
|
|
|
43714
44316
|
}
|
|
43715
44317
|
|
|
43716
44318
|
// ../../packages/plugin-runtime/src/attached/posture-report-state.ts
|
|
43717
|
-
import { readFileSync as
|
|
43718
|
-
import { join as
|
|
44319
|
+
import { readFileSync as readFileSync15 } from "fs";
|
|
44320
|
+
import { join as join25 } from "path";
|
|
43719
44321
|
var POSTURE_REPORT_STATE_FILENAME = ATTACHED_POSTURE_REPORT_FILENAME;
|
|
43720
44322
|
var OUTCOME_KEYS = {
|
|
43721
44323
|
ok: true,
|
|
@@ -43729,7 +44331,7 @@ var OUTCOME_KEYS = {
|
|
|
43729
44331
|
};
|
|
43730
44332
|
var OUTCOMES = new Set(Object.keys(OUTCOME_KEYS));
|
|
43731
44333
|
function postureReportStatePath(dataDir2) {
|
|
43732
|
-
return
|
|
44334
|
+
return join25(dataDir2, POSTURE_REPORT_STATE_FILENAME);
|
|
43733
44335
|
}
|
|
43734
44336
|
function writePostureReportState(dataDir2, state) {
|
|
43735
44337
|
try {
|
|
@@ -43770,10 +44372,19 @@ function createPostureReporter(deps) {
|
|
|
43770
44372
|
hostname: deps.hostname(),
|
|
43771
44373
|
capturedAt: nowMs,
|
|
43772
44374
|
...measurement,
|
|
43773
|
-
// Omit the key rather than spread an explicit `undefined
|
|
43774
|
-
//
|
|
43775
|
-
//
|
|
43776
|
-
|
|
44375
|
+
// Omit the key rather than spread an explicit `undefined`. The type
|
|
44376
|
+
// admits `undefined` here (the schema's optional member), and
|
|
44377
|
+
// JSON.stringify sends the same bytes either way. Omitting keeps the
|
|
44378
|
+
// in-memory object free of an explicit `undefined` member, which the
|
|
44379
|
+
// tests pin by key presence.
|
|
44380
|
+
...plugin === void 0 ? {} : { plugin },
|
|
44381
|
+
// LAST, and only for a scoped attachment. A machine attachment omits
|
|
44382
|
+
// the key the same way, so its body is byte for byte the one it sent
|
|
44383
|
+
// before the member existed. Anything but exactly `machine` reports the
|
|
44384
|
+
// constant `scoped`, never the raw value: that is resolveScope's own
|
|
44385
|
+
// fail direction, and a value outside the wire's vocabulary would fail
|
|
44386
|
+
// the whole snapshot at the receiver, the wipe signal with it.
|
|
44387
|
+
...deps.attachmentMode === "machine" ? {} : { attachmentMode: "scoped" }
|
|
43777
44388
|
};
|
|
43778
44389
|
} catch {
|
|
43779
44390
|
return null;
|
|
@@ -43796,8 +44407,8 @@ function createPostureReporter(deps) {
|
|
|
43796
44407
|
}
|
|
43797
44408
|
|
|
43798
44409
|
// ../../packages/plugin-runtime/src/attached/posture-snapshot.ts
|
|
43799
|
-
import { statSync as
|
|
43800
|
-
import { DatabaseSync as
|
|
44410
|
+
import { statSync as statSync7 } from "fs";
|
|
44411
|
+
import { DatabaseSync as DatabaseSync3 } from "node:sqlite";
|
|
43801
44412
|
|
|
43802
44413
|
// ../../packages/plugin-runtime/src/attached/action-counts.ts
|
|
43803
44414
|
function emptyActionCounts() {
|
|
@@ -43827,7 +44438,7 @@ function emptyReadout(readError = false) {
|
|
|
43827
44438
|
}
|
|
43828
44439
|
function readStorePosture(dbPath2) {
|
|
43829
44440
|
try {
|
|
43830
|
-
|
|
44441
|
+
statSync7(dbPath2);
|
|
43831
44442
|
} catch (err) {
|
|
43832
44443
|
const code = err.code;
|
|
43833
44444
|
if (code === "ENOENT" || code === "ENOTDIR") return emptyReadout();
|
|
@@ -43855,7 +44466,7 @@ function readStorePosture(dbPath2) {
|
|
|
43855
44466
|
readError: false
|
|
43856
44467
|
});
|
|
43857
44468
|
try {
|
|
43858
|
-
db = new
|
|
44469
|
+
db = new DatabaseSync3(dbPath2, { readOnly: true });
|
|
43859
44470
|
db.exec("PRAGMA busy_timeout = 2000");
|
|
43860
44471
|
version2 = db.prepare("PRAGMA user_version").get().user_version;
|
|
43861
44472
|
try {
|
|
@@ -43909,11 +44520,11 @@ function readStorePosture(dbPath2) {
|
|
|
43909
44520
|
// ../../packages/plugin-runtime/src/attached/posture-store.ts
|
|
43910
44521
|
import { randomUUID as randomUUID18 } from "crypto";
|
|
43911
44522
|
import { readFile as readFile4, rm as rm2, writeFile as writeFile3 } from "fs/promises";
|
|
43912
|
-
import { join as
|
|
44523
|
+
import { join as join26 } from "path";
|
|
43913
44524
|
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
43914
44525
|
function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
43915
|
-
const file2 =
|
|
43916
|
-
const legacyFile = legacyDir === void 0 ? null :
|
|
44526
|
+
const file2 = join26(dir, "posture-state.json");
|
|
44527
|
+
const legacyFile = legacyDir === void 0 ? null : join26(legacyDir, "posture-state.json");
|
|
43917
44528
|
async function persist(state) {
|
|
43918
44529
|
await ensureDataDir(dir);
|
|
43919
44530
|
const tmp = `${file2}.${randomUUID18()}.tmp`;
|
|
@@ -43981,8 +44592,8 @@ function createPostureStore(dir = settingsDir(), legacyDir) {
|
|
|
43981
44592
|
}
|
|
43982
44593
|
|
|
43983
44594
|
// ../../packages/plugin-runtime/src/attached/sync-state.ts
|
|
43984
|
-
import { readFileSync as
|
|
43985
|
-
import { join as
|
|
44595
|
+
import { readFileSync as readFileSync16 } from "fs";
|
|
44596
|
+
import { join as join27 } from "path";
|
|
43986
44597
|
|
|
43987
44598
|
// ../../packages/plugin-runtime/src/attached/status.ts
|
|
43988
44599
|
var REFUSAL_LINES = {
|
|
@@ -44012,7 +44623,7 @@ import { fileURLToPath as fileURLToPath4 } from "url";
|
|
|
44012
44623
|
var CONTENT_RETENTION_THROTTLE_MS = 60 * 60 * 1e3;
|
|
44013
44624
|
|
|
44014
44625
|
// ../../packages/plugin-runtime/src/attached/factory.ts
|
|
44015
|
-
import { hostname as
|
|
44626
|
+
import { hostname as hostname5 } from "os";
|
|
44016
44627
|
|
|
44017
44628
|
// ../../packages/plugin-runtime/src/recorder.ts
|
|
44018
44629
|
var PLUGIN_RECORDER_BINARY = "plugin";
|
|
@@ -44025,7 +44636,7 @@ var StandaloneDataGateway = class {
|
|
|
44025
44636
|
// One notice per gateway — see warnRulesetDiscarded.
|
|
44026
44637
|
warnedRulesetDiscarded = false;
|
|
44027
44638
|
constructor(dataDir2, detections = [], meta4) {
|
|
44028
|
-
this.db = openLocalDatabase(dataDir2);
|
|
44639
|
+
this.db = openLocalDatabase(dataDir2, { shippedRegexMatchers: shippedRegexMatchers() });
|
|
44029
44640
|
this.dataDir = dataDir2;
|
|
44030
44641
|
this.db.installedPacks.recordInventory(detections, meta4);
|
|
44031
44642
|
}
|
|
@@ -44374,6 +44985,9 @@ var StandaloneDataGateway = class {
|
|
|
44374
44985
|
scanLedgerPaths() {
|
|
44375
44986
|
return Promise.resolve(this.db.scanLedger.allPaths());
|
|
44376
44987
|
}
|
|
44988
|
+
scanLedgerPathKeys() {
|
|
44989
|
+
return Promise.resolve(this.db.scanLedger.pathKeys());
|
|
44990
|
+
}
|
|
44377
44991
|
recordScanned(entries) {
|
|
44378
44992
|
this.db.scanLedger.upsertEntries(entries);
|
|
44379
44993
|
return Promise.resolve();
|
|
@@ -44459,13 +45073,17 @@ function resolveGatewayForConfig(config2, meta4) {
|
|
|
44459
45073
|
},
|
|
44460
45074
|
store: postureStore,
|
|
44461
45075
|
readStore: () => readStorePosture(config2.dbPath),
|
|
44462
|
-
hostname: () =>
|
|
45076
|
+
hostname: () => hostname5(),
|
|
44463
45077
|
now: () => Date.now(),
|
|
45078
|
+
// The mode THIS gateway enforces, from the attachment resolved above,
|
|
45079
|
+
// so the report cannot name a mode the forward paths are not using.
|
|
45080
|
+
attachmentMode: attachment.mode,
|
|
44464
45081
|
// The reporting build's identity, when the caller knows it (the plugin
|
|
44465
45082
|
// adapters do; an embedder or a test may not). Composed with the SAME
|
|
44466
45083
|
// policy store the sync child writes, so the block names the bundle
|
|
44467
|
-
// actually in force.
|
|
44468
|
-
// reporter
|
|
45084
|
+
// actually in force. The dependency key is omitted when no build is
|
|
45085
|
+
// known, and the reporter's optional call (`deps.pluginBlock?.()`)
|
|
45086
|
+
// then adds no block.
|
|
44469
45087
|
...meta4?.pluginBuild === void 0 ? {} : { pluginBlock: createPluginBlock(meta4.pluginBuild, store) }
|
|
44470
45088
|
})
|
|
44471
45089
|
});
|
|
@@ -44486,11 +45104,11 @@ import { randomUUID as randomUUID19 } from "crypto";
|
|
|
44486
45104
|
var EXCEPTION_RETENTION_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
44487
45105
|
|
|
44488
45106
|
// ../../packages/scanner/src/manifests.ts
|
|
44489
|
-
import { statSync as
|
|
45107
|
+
import { statSync as statSync9 } from "fs";
|
|
44490
45108
|
|
|
44491
45109
|
// ../../packages/scanner/src/walk.ts
|
|
44492
|
-
import { readdirSync as
|
|
44493
|
-
import { extname, join as
|
|
45110
|
+
import { readdirSync as readdirSync4, readFileSync as readFileSync17, statSync as statSync8 } from "fs";
|
|
45111
|
+
import { extname, join as join28, relative as relative2, sep as sep4 } from "path";
|
|
44494
45112
|
var import_ignore2 = __toESM(require_ignore(), 1);
|
|
44495
45113
|
var SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
44496
45114
|
".ts",
|
|
@@ -44523,14 +45141,18 @@ var SKIP_DIRS = /* @__PURE__ */ new Set([
|
|
|
44523
45141
|
var DEFAULT_MAX_BYTES = 512 * 1024;
|
|
44524
45142
|
function* walkTree(rootDir, opts = {}) {
|
|
44525
45143
|
const trackGitignore = opts.trackGitignore ?? false;
|
|
45144
|
+
const onRepositoryRoot = opts.onRepositoryRoot;
|
|
44526
45145
|
const rootSkipLayers = opts.excludePatterns && opts.excludePatterns.length > 0 ? [{ matcher: (0, import_ignore2.default)().add(opts.excludePatterns), anchorLen: 0 }] : [];
|
|
44527
45146
|
function* visit2(dir, dirRel, markLayers, skipLayers, inIgnoredDir) {
|
|
44528
45147
|
let dirents;
|
|
44529
45148
|
try {
|
|
44530
|
-
dirents =
|
|
45149
|
+
dirents = readdirSync4(dir, { withFileTypes: true, encoding: "utf8" });
|
|
44531
45150
|
} catch {
|
|
44532
45151
|
return;
|
|
44533
45152
|
}
|
|
45153
|
+
if (onRepositoryRoot !== void 0 && dirRel !== "" && dirents.some((entry) => entry.name === ".git")) {
|
|
45154
|
+
onRepositoryRoot(dirRel);
|
|
45155
|
+
}
|
|
44534
45156
|
const dirMarkLayers = withLayer(
|
|
44535
45157
|
markLayers,
|
|
44536
45158
|
trackGitignore && !inIgnoredDir ? readIgnoreLayer(dir, ".gitignore", dirRel.length) : void 0
|
|
@@ -44541,7 +45163,7 @@ function* walkTree(rootDir, opts = {}) {
|
|
|
44541
45163
|
);
|
|
44542
45164
|
for (const entry of dirents) {
|
|
44543
45165
|
const name = entry.name;
|
|
44544
|
-
const fullPath =
|
|
45166
|
+
const fullPath = join28(dir, name);
|
|
44545
45167
|
if (entry.isDirectory()) {
|
|
44546
45168
|
const skipState = evaluateIgnore(dirSkipLayers, dirRel, name, true);
|
|
44547
45169
|
if (skipState !== "unignored" && (SKIP_DIRS.has(name) || skipState === "ignored")) {
|
|
@@ -44568,14 +45190,15 @@ function* walkSourceFiles(opts = {}) {
|
|
|
44568
45190
|
const maxBytes = opts.maxFileSizeBytes ?? DEFAULT_MAX_BYTES;
|
|
44569
45191
|
for (const file2 of walkTree(rootDir, {
|
|
44570
45192
|
excludePatterns: opts.excludePatterns,
|
|
44571
|
-
trackGitignore: true
|
|
45193
|
+
trackGitignore: true,
|
|
45194
|
+
onRepositoryRoot: opts.onRepositoryRoot
|
|
44572
45195
|
})) {
|
|
44573
45196
|
const ext = extname(file2.name);
|
|
44574
45197
|
if (!extensions.has(ext)) continue;
|
|
44575
45198
|
let size;
|
|
44576
45199
|
let mtime;
|
|
44577
45200
|
try {
|
|
44578
|
-
const st =
|
|
45201
|
+
const st = statSync8(file2.path);
|
|
44579
45202
|
size = st.size;
|
|
44580
45203
|
mtime = st.mtime;
|
|
44581
45204
|
} catch {
|
|
@@ -44595,7 +45218,7 @@ function* walkSourceFiles(opts = {}) {
|
|
|
44595
45218
|
if (opts.shouldRead && !opts.shouldRead(meta4)) continue;
|
|
44596
45219
|
let content;
|
|
44597
45220
|
try {
|
|
44598
|
-
content =
|
|
45221
|
+
content = readFileSync17(file2.path, "utf8");
|
|
44599
45222
|
} catch {
|
|
44600
45223
|
continue;
|
|
44601
45224
|
}
|
|
@@ -44611,13 +45234,13 @@ function* walkSourceFiles(opts = {}) {
|
|
|
44611
45234
|
|
|
44612
45235
|
// ../../packages/scanner/src/manifests.ts
|
|
44613
45236
|
var MAX_MANIFEST_BYTES = 512 * 1024;
|
|
44614
|
-
function collectManifests(rootDir, maxFileSizeBytes = MAX_MANIFEST_BYTES) {
|
|
45237
|
+
function collectManifests(rootDir, maxFileSizeBytes = MAX_MANIFEST_BYTES, onRepositoryRoot) {
|
|
44615
45238
|
const found = [];
|
|
44616
|
-
for (const file2 of walkTree(rootDir)) {
|
|
45239
|
+
for (const file2 of walkTree(rootDir, { onRepositoryRoot })) {
|
|
44617
45240
|
const kind = manifestKindOf(file2.name);
|
|
44618
45241
|
if (kind === null) continue;
|
|
44619
45242
|
try {
|
|
44620
|
-
const st =
|
|
45243
|
+
const st = statSync9(file2.path);
|
|
44621
45244
|
if (st.size > maxFileSizeBytes) continue;
|
|
44622
45245
|
found.push({ path: file2.path, kind, mtime: st.mtime.toISOString(), size: st.size });
|
|
44623
45246
|
} catch {
|
|
@@ -44634,35 +45257,66 @@ function computeResolutions(prior, current) {
|
|
|
44634
45257
|
}
|
|
44635
45258
|
|
|
44636
45259
|
// ../../packages/scanner/src/scope-key.ts
|
|
44637
|
-
import { existsSync as
|
|
44638
|
-
import { join as
|
|
45260
|
+
import { existsSync as existsSync11 } from "fs";
|
|
45261
|
+
import { dirname as dirname7, join as join29, posix as posix2, resolve as resolve3 } from "path";
|
|
44639
45262
|
function scopeKeysUnder(rootDir) {
|
|
44640
45263
|
const base = resolve3(rootDir);
|
|
44641
|
-
|
|
44642
|
-
|
|
45264
|
+
let aboveBase;
|
|
45265
|
+
const rootAtOrAboveBase = () => {
|
|
45266
|
+
if (aboveBase === void 0) {
|
|
45267
|
+
let dir = base;
|
|
45268
|
+
let root;
|
|
45269
|
+
for (; ; ) {
|
|
45270
|
+
if (existsSync11(join29(dir, ".git"))) {
|
|
45271
|
+
root = dir;
|
|
45272
|
+
break;
|
|
45273
|
+
}
|
|
45274
|
+
const parent = dirname7(dir);
|
|
45275
|
+
if (parent === dir) break;
|
|
45276
|
+
dir = parent;
|
|
45277
|
+
}
|
|
45278
|
+
aboveBase = { root };
|
|
45279
|
+
}
|
|
45280
|
+
return aboveBase.root;
|
|
45281
|
+
};
|
|
45282
|
+
const confirmed = (root, key) => existsSync11(join29(root, ".git")) ? { root, key } : { root: void 0, key: void 0 };
|
|
45283
|
+
const repositoryByDir = /* @__PURE__ */ new Map();
|
|
45284
|
+
const repositoryOf = (relativePath) => {
|
|
44643
45285
|
const climbed = [];
|
|
44644
45286
|
let dir = posix2.dirname(relativePath);
|
|
44645
|
-
let
|
|
45287
|
+
let found;
|
|
44646
45288
|
for (; ; ) {
|
|
44647
|
-
|
|
44648
|
-
|
|
45289
|
+
const known = repositoryByDir.get(dir);
|
|
45290
|
+
if (known !== void 0) {
|
|
45291
|
+
found = known;
|
|
44649
45292
|
break;
|
|
44650
45293
|
}
|
|
44651
45294
|
climbed.push(dir);
|
|
44652
45295
|
const parent = posix2.dirname(dir);
|
|
44653
45296
|
if (parent === dir) {
|
|
44654
|
-
|
|
45297
|
+
const root = rootAtOrAboveBase();
|
|
45298
|
+
found = root === void 0 ? { root, key: resolveRepoAttribution(base, { cache: false }).scopeKey } : confirmed(root, resolveRepoAttribution(root, { cache: false }).scopeKey);
|
|
44655
45299
|
break;
|
|
44656
45300
|
}
|
|
44657
|
-
if (
|
|
44658
|
-
|
|
45301
|
+
if (existsSync11(join29(base, dir, ".git"))) {
|
|
45302
|
+
const root = join29(base, dir);
|
|
45303
|
+
found = confirmed(root, resolveRepoAttribution(root, { cache: false }).scopeKey);
|
|
44659
45304
|
break;
|
|
44660
45305
|
}
|
|
44661
45306
|
dir = parent;
|
|
44662
45307
|
}
|
|
44663
|
-
for (const at of climbed)
|
|
44664
|
-
return
|
|
45308
|
+
for (const at of climbed) repositoryByDir.set(at, found);
|
|
45309
|
+
return found;
|
|
45310
|
+
};
|
|
45311
|
+
const keyOfFile = (relativePath) => repositoryOf(relativePath).key;
|
|
45312
|
+
const ofRepositoryRoot = (relativeDir) => {
|
|
45313
|
+
const root = join29(base, relativeDir);
|
|
45314
|
+
const dotGit = join29(root, ".git");
|
|
45315
|
+
if (!existsSync11(dotGit)) return void 0;
|
|
45316
|
+
const key = resolveRepoAttribution(root, { cache: false }).scopeKey;
|
|
45317
|
+
return existsSync11(dotGit) ? key : void 0;
|
|
44665
45318
|
};
|
|
45319
|
+
return Object.assign(keyOfFile, { repositoryOf, ofRepositoryRoot });
|
|
44666
45320
|
}
|
|
44667
45321
|
|
|
44668
45322
|
// ../../packages/scanner/src/scan.ts
|
|
@@ -44697,7 +45351,14 @@ function egressKey(root, absPath) {
|
|
|
44697
45351
|
function startEgress(rootDir) {
|
|
44698
45352
|
const project = resolveEgressProject(rootDir);
|
|
44699
45353
|
if (project === null) return null;
|
|
44700
|
-
return {
|
|
45354
|
+
return {
|
|
45355
|
+
project,
|
|
45356
|
+
files: [],
|
|
45357
|
+
scannedFiles: [],
|
|
45358
|
+
deletedFiles: [],
|
|
45359
|
+
deletedPaths: [],
|
|
45360
|
+
nestedRoots: []
|
|
45361
|
+
};
|
|
44701
45362
|
}
|
|
44702
45363
|
function collectFileEgress(acc, absPath, content, manifestKind) {
|
|
44703
45364
|
const file2 = egressKey(acc.project.root, absPath);
|
|
@@ -44746,17 +45407,39 @@ async function reopenRedetectedFindings(gateway, path, currentKeys, evidence, re
|
|
|
44746
45407
|
}
|
|
44747
45408
|
function isUnderRoot(path, rootDir) {
|
|
44748
45409
|
const rel = relative3(rootDir, path);
|
|
44749
|
-
return rel !== "" && !rel.startsWith("..") && !
|
|
45410
|
+
return rel !== "" && !rel.startsWith("..") && !isAbsolute2(rel);
|
|
44750
45411
|
}
|
|
44751
45412
|
async function sweepDeletedFiles(gateway, rootDir, paths) {
|
|
44752
45413
|
const deleted = [];
|
|
44753
45414
|
for (const path of paths) {
|
|
44754
|
-
if (!isUnderRoot(path, rootDir) ||
|
|
45415
|
+
if (!isUnderRoot(path, rootDir) || existsSync12(path)) continue;
|
|
44755
45416
|
deleted.push(path);
|
|
44756
45417
|
await resolveRemovedFindings(gateway, path, [], { deleted: true });
|
|
44757
45418
|
}
|
|
44758
45419
|
return deleted;
|
|
44759
45420
|
}
|
|
45421
|
+
function repositoryToRecord(prev, now) {
|
|
45422
|
+
const recordedRoot = prev?.scopeRoot;
|
|
45423
|
+
if (recordedRoot === void 0) return now;
|
|
45424
|
+
if (now.root !== void 0 && isAtOrBelow(recordedRoot, now.root)) return now;
|
|
45425
|
+
return { root: recordedRoot, key: prev?.scopeKey };
|
|
45426
|
+
}
|
|
45427
|
+
function isAtOrBelow(ancestor, dir) {
|
|
45428
|
+
const rel = relative3(ancestor, dir);
|
|
45429
|
+
if (isAbsolute2(rel)) return false;
|
|
45430
|
+
const posixRel = toPosix(rel);
|
|
45431
|
+
return posixRel === "" || posixRel !== ".." && !posixRel.startsWith("../");
|
|
45432
|
+
}
|
|
45433
|
+
function repositoryColumns(repository) {
|
|
45434
|
+
return {
|
|
45435
|
+
...repository.key !== void 0 ? { scopeKey: repository.key } : {},
|
|
45436
|
+
...repository.root !== void 0 ? { scopeRoot: repository.root } : {}
|
|
45437
|
+
};
|
|
45438
|
+
}
|
|
45439
|
+
function repositoryDiffers(prev, decided) {
|
|
45440
|
+
return decided.key !== prev.scopeKey || decided.root !== prev.scopeRoot;
|
|
45441
|
+
}
|
|
45442
|
+
var NO_REPOSITORY = { root: void 0, key: void 0 };
|
|
44760
45443
|
async function scanDir(runtime, gateway, config2, seen, ledger, rootDir, opts) {
|
|
44761
45444
|
const byRule = {};
|
|
44762
45445
|
const bySeverity = {};
|
|
@@ -44767,10 +45450,25 @@ async function scanDir(runtime, gateway, config2, seen, ledger, rootDir, opts) {
|
|
|
44767
45450
|
let gitignoredFindings = 0;
|
|
44768
45451
|
const egress = config2.settings.dataSharesInPlace ? startEgress(rootDir) : null;
|
|
44769
45452
|
const scopeKeyOf2 = scopeKeysUnder(rootDir);
|
|
45453
|
+
const noteNestedRoot = (relativeDir) => {
|
|
45454
|
+
egress?.nestedRoots.push(relativeDir);
|
|
45455
|
+
};
|
|
44770
45456
|
const shouldRead = (meta4) => {
|
|
44771
45457
|
const prev = ledger.previous.get(meta4.path);
|
|
44772
45458
|
if (prev?.mtime === meta4.mtime) {
|
|
44773
45459
|
skipped++;
|
|
45460
|
+
if (egress !== null) {
|
|
45461
|
+
const decided = repositoryToRecord(prev, scopeKeyOf2.repositoryOf(meta4.relativePath));
|
|
45462
|
+
if (repositoryDiffers(prev, decided)) {
|
|
45463
|
+
updates.push({
|
|
45464
|
+
path: meta4.path,
|
|
45465
|
+
mtime: prev.mtime,
|
|
45466
|
+
contentHash: prev.contentHash,
|
|
45467
|
+
rulesetHash: ledger.rulesetHash,
|
|
45468
|
+
...repositoryColumns(decided)
|
|
45469
|
+
});
|
|
45470
|
+
}
|
|
45471
|
+
}
|
|
44774
45472
|
return false;
|
|
44775
45473
|
}
|
|
44776
45474
|
return true;
|
|
@@ -44778,16 +45476,19 @@ async function scanDir(runtime, gateway, config2, seen, ledger, rootDir, opts) {
|
|
|
44778
45476
|
for (const file2 of walkSourceFiles({
|
|
44779
45477
|
...opts,
|
|
44780
45478
|
rootDir,
|
|
44781
|
-
shouldRead: (meta4) => (opts.shouldRead?.(meta4) ?? true) && shouldRead(meta4)
|
|
45479
|
+
shouldRead: (meta4) => (opts.shouldRead?.(meta4) ?? true) && shouldRead(meta4),
|
|
45480
|
+
onRepositoryRoot: egress === null ? void 0 : noteNestedRoot
|
|
44782
45481
|
})) {
|
|
44783
45482
|
const hash2 = contentHashOf(file2.content);
|
|
45483
|
+
const prev = ledger.previous.get(file2.path);
|
|
45484
|
+
const repository = egress === null ? NO_REPOSITORY : repositoryToRecord(prev, scopeKeyOf2.repositoryOf(file2.relativePath));
|
|
44784
45485
|
const ledgerEntry = {
|
|
44785
45486
|
path: file2.path,
|
|
44786
45487
|
mtime: file2.mtime,
|
|
44787
45488
|
contentHash: hash2,
|
|
44788
|
-
rulesetHash: ledger.rulesetHash
|
|
45489
|
+
rulesetHash: ledger.rulesetHash,
|
|
45490
|
+
...repositoryColumns(repository)
|
|
44789
45491
|
};
|
|
44790
|
-
const prev = ledger.previous.get(file2.path);
|
|
44791
45492
|
if (prev?.contentHash === hash2) {
|
|
44792
45493
|
skipped++;
|
|
44793
45494
|
updates.push(ledgerEntry);
|
|
@@ -44839,15 +45540,17 @@ async function scanDir(runtime, gateway, config2, seen, ledger, rootDir, opts) {
|
|
|
44839
45540
|
contentHash: hash2
|
|
44840
45541
|
});
|
|
44841
45542
|
}
|
|
44842
|
-
if (egress) scanManifests(egress, ledger, updates, rootDir);
|
|
45543
|
+
if (egress) scanManifests(egress, ledger, updates, rootDir, scopeKeyOf2, noteNestedRoot);
|
|
44843
45544
|
const deleted = await sweepDeletedFiles(gateway, rootDir, ledger.paths);
|
|
44844
45545
|
if (egress) {
|
|
44845
45546
|
for (const path of deleted) {
|
|
44846
45547
|
const key = egressKey(egress.project.root, path);
|
|
44847
|
-
if (key
|
|
45548
|
+
if (key === null) continue;
|
|
45549
|
+
egress.deletedFiles.push(key);
|
|
45550
|
+
egress.deletedPaths.push(path);
|
|
44848
45551
|
}
|
|
44849
45552
|
}
|
|
44850
|
-
const committed = await commitEgress(gateway, egress);
|
|
45553
|
+
const committed = await commitEgress(gateway, egress, scopeKeyOf2);
|
|
44851
45554
|
if (committed === null) {
|
|
44852
45555
|
return { rootDir, scanned, skipped, findings, gitignoredFindings, byRule, bySeverity };
|
|
44853
45556
|
}
|
|
@@ -44857,13 +45560,28 @@ async function scanDir(runtime, gateway, config2, seen, ledger, rootDir, opts) {
|
|
|
44857
45560
|
await gateway.recordScanned(ledgerable(updates, egress, committed));
|
|
44858
45561
|
return { rootDir, scanned, skipped, findings, gitignoredFindings, byRule, bySeverity };
|
|
44859
45562
|
}
|
|
44860
|
-
function scanManifests(egress, ledger, updates, rootDir) {
|
|
44861
|
-
for (const manifest of collectManifests(rootDir)) {
|
|
45563
|
+
function scanManifests(egress, ledger, updates, rootDir, scopeKeyOf2, onRepositoryRoot) {
|
|
45564
|
+
for (const manifest of collectManifests(rootDir, void 0, onRepositoryRoot)) {
|
|
44862
45565
|
const prev = ledger.previous.get(manifest.path);
|
|
44863
|
-
|
|
45566
|
+
const repository = repositoryToRecord(
|
|
45567
|
+
prev,
|
|
45568
|
+
scopeKeyOf2.repositoryOf(toPosix(relative3(rootDir, manifest.path)))
|
|
45569
|
+
);
|
|
45570
|
+
if (prev?.mtime === manifest.mtime) {
|
|
45571
|
+
if (repositoryDiffers(prev, repository)) {
|
|
45572
|
+
updates.push({
|
|
45573
|
+
path: manifest.path,
|
|
45574
|
+
mtime: prev.mtime,
|
|
45575
|
+
contentHash: prev.contentHash,
|
|
45576
|
+
rulesetHash: ledger.rulesetHash,
|
|
45577
|
+
...repositoryColumns(repository)
|
|
45578
|
+
});
|
|
45579
|
+
}
|
|
45580
|
+
continue;
|
|
45581
|
+
}
|
|
44864
45582
|
let content;
|
|
44865
45583
|
try {
|
|
44866
|
-
content =
|
|
45584
|
+
content = readFileSync18(manifest.path, "utf8");
|
|
44867
45585
|
} catch {
|
|
44868
45586
|
continue;
|
|
44869
45587
|
}
|
|
@@ -44872,31 +45590,82 @@ function scanManifests(egress, ledger, updates, rootDir) {
|
|
|
44872
45590
|
path: manifest.path,
|
|
44873
45591
|
mtime: manifest.mtime,
|
|
44874
45592
|
contentHash: hash2,
|
|
44875
|
-
rulesetHash: ledger.rulesetHash
|
|
45593
|
+
rulesetHash: ledger.rulesetHash,
|
|
45594
|
+
...repositoryColumns(repository)
|
|
44876
45595
|
});
|
|
44877
45596
|
if (prev?.contentHash === hash2) continue;
|
|
44878
45597
|
collectFileEgress(egress, manifest.path, content, manifest.kind);
|
|
44879
45598
|
}
|
|
44880
45599
|
}
|
|
44881
|
-
async function commitEgress(gateway, egress) {
|
|
45600
|
+
async function commitEgress(gateway, egress, scopeKeyOf2) {
|
|
44882
45601
|
if (!egress) return EMPTY_DROPPED;
|
|
44883
|
-
const { project, files, scannedFiles, deletedFiles } = egress;
|
|
45602
|
+
const { project, files, scannedFiles, deletedFiles, deletedPaths, nestedRoots } = egress;
|
|
44884
45603
|
if (scannedFiles.length === 0 && deletedFiles.length === 0 && files.length === 0) {
|
|
44885
45604
|
return EMPTY_DROPPED;
|
|
44886
45605
|
}
|
|
45606
|
+
let nestedKeys;
|
|
45607
|
+
let deletedKeys;
|
|
44887
45608
|
try {
|
|
44888
|
-
const summary = await gateway.recordProjectEgress(
|
|
44889
|
-
|
|
44890
|
-
|
|
44891
|
-
|
|
44892
|
-
|
|
44893
|
-
|
|
44894
|
-
|
|
45609
|
+
const summary = await gateway.recordProjectEgress(
|
|
45610
|
+
{
|
|
45611
|
+
projectKey: project.projectKey,
|
|
45612
|
+
project: project.project,
|
|
45613
|
+
projectId: null,
|
|
45614
|
+
reconcile: { mode: "ledger", scannedFiles, deletedFiles },
|
|
45615
|
+
hits: resolveEgress(files)
|
|
45616
|
+
},
|
|
45617
|
+
{
|
|
45618
|
+
// One key per nested root, from this scan's own lookup of a
|
|
45619
|
+
// repository ROOT (./scope-key.ts): the directory's own key, found
|
|
45620
|
+
// without climbing. A nested directory whose `.git` is a link to
|
|
45621
|
+
// nowhere, or is gone by the time a gateway asks, is `undefined` here
|
|
45622
|
+
// rather than the key of the repository around it; so is a nested
|
|
45623
|
+
// repository with no forge remote. Each root is read fresh, never from
|
|
45624
|
+
// the resolver's memory of an earlier answer for that directory. Always
|
|
45625
|
+
// a list, even an empty one: a scoped gateway reads a missing list as a
|
|
45626
|
+
// register nobody vouched for. The repository lookups it makes do not
|
|
45627
|
+
// throw on these inputs, and the gateway reads any throw in this read as
|
|
45628
|
+
// local anyway.
|
|
45629
|
+
//
|
|
45630
|
+
// A getter, memoized: only a gateway that reads the list causes a
|
|
45631
|
+
// repository read. The standalone gateway ignores it, and a
|
|
45632
|
+
// machine-wide attachment answers before reading it.
|
|
45633
|
+
get nestedScopeKeys() {
|
|
45634
|
+
nestedKeys ??= [...new Set(nestedRoots)].map((dir) => scopeKeyOf2.ofRepositoryRoot(dir));
|
|
45635
|
+
return nestedKeys;
|
|
45636
|
+
},
|
|
45637
|
+
// One key per entry of `reconcile.deletedFiles`, in its order: what the
|
|
45638
|
+
// ledger recorded when the path was last read, and none for a row that
|
|
45639
|
+
// recorded none. ASYNC and lazy, because the read of every row's key is a
|
|
45640
|
+
// read of the whole ledger: only a gateway that forwards by scope asks, and
|
|
45641
|
+
// only once it has found the register sendable at all, so the standalone
|
|
45642
|
+
// gateway and a machine-wide attachment never cause it. Memoized, so a
|
|
45643
|
+
// gateway that asks twice reads once. A scan that deleted nothing has no
|
|
45644
|
+
// keys to look up and reads nothing.
|
|
45645
|
+
deletedFileKeys: () => {
|
|
45646
|
+
deletedKeys ??= keysOfDeleted(gateway, deletedPaths);
|
|
45647
|
+
return deletedKeys;
|
|
45648
|
+
}
|
|
45649
|
+
}
|
|
45650
|
+
);
|
|
44895
45651
|
return new Set(summary.droppedFiles);
|
|
44896
45652
|
} catch {
|
|
44897
45653
|
return null;
|
|
44898
45654
|
}
|
|
44899
45655
|
}
|
|
45656
|
+
async function keysOfDeleted(gateway, deletedPaths) {
|
|
45657
|
+
if (deletedPaths.length === 0) return [];
|
|
45658
|
+
const recorded = await readRecordedKeys(gateway);
|
|
45659
|
+
return deletedPaths.map((path) => recorded.get(path));
|
|
45660
|
+
}
|
|
45661
|
+
async function readRecordedKeys(gateway) {
|
|
45662
|
+
try {
|
|
45663
|
+
return await gateway.scanLedgerPathKeys?.() ?? NO_RECORDED_KEYS;
|
|
45664
|
+
} catch {
|
|
45665
|
+
return NO_RECORDED_KEYS;
|
|
45666
|
+
}
|
|
45667
|
+
}
|
|
45668
|
+
var NO_RECORDED_KEYS = /* @__PURE__ */ new Map();
|
|
44900
45669
|
var EMPTY_DROPPED = /* @__PURE__ */ new Set();
|
|
44901
45670
|
function ledgerable(updates, egress, dropped) {
|
|
44902
45671
|
if (!egress || dropped.size === 0) return [...updates];
|