@akasecurity/ai-tc-claude-code 0.9.5 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/package.json +7 -6
- package/scripts/apply-suppressions.js +1480 -974
- package/scripts/backfill.js +1589 -1023
- package/scripts/dashboard.js +131 -10
- package/scripts/filescan.js +1519 -1021
- package/scripts/firstrun.js +1358 -908
- package/scripts/intro.js +1048 -898
- package/scripts/message-display.js +1453 -980
- package/scripts/onboard.js +1378 -895
- package/scripts/post-tool-use.js +1575 -1009
- package/scripts/pre-tool-use.js +1580 -1014
- package/scripts/query.js +1420 -965
- package/scripts/reconcile.js +1538 -1013
- package/scripts/remediate.js +1585 -1019
- package/scripts/scan-worker.js +1056 -927
- package/scripts/session-start.js +1499 -1014
- package/scripts/start-light.js +1058 -909
- package/scripts/statusline.js +1357 -907
- package/scripts/stop.js +1113 -898
- package/scripts/user-prompt-submit.js +1791 -1207
package/scripts/pre-tool-use.js
CHANGED
|
@@ -585,6 +585,10 @@ var SQLITE_MIGRATIONS = [
|
|
|
585
585
|
{
|
|
586
586
|
tag: "0020_secret_vault_pagination_indexes",
|
|
587
587
|
sql: "CREATE INDEX `idx_secret_vault_last_seen` ON `secret_vault` (`last_seen`,`pointer_id`);--> statement-breakpoint\nCREATE INDEX `idx_secret_vault_reuse` ON `secret_vault` (`occurrence_count`,`pointer_id`);--> statement-breakpoint\nCREATE INDEX `idx_secret_vault_deref_at` ON `secret_vault_deref` (`at`,`id`);--> statement-breakpoint\nCREATE INDEX `idx_secret_vault_deref_signal` ON `secret_vault_deref` (`at`,`id`) WHERE `reason` NOT IN ('display', 'view-render');"
|
|
588
|
+
},
|
|
589
|
+
{
|
|
590
|
+
tag: "0021_finding_resolution_resolved_at_index",
|
|
591
|
+
sql: "CREATE INDEX `idx_finding_resolution_resolved_at` ON `finding_resolution` (`resolved_at`);\n"
|
|
588
592
|
}
|
|
589
593
|
];
|
|
590
594
|
|
|
@@ -15300,6 +15304,47 @@ function date4(params) {
|
|
|
15300
15304
|
// ../../node_modules/.pnpm/zod@4.4.3/node_modules/zod/v4/classic/external.js
|
|
15301
15305
|
config(en_default());
|
|
15302
15306
|
|
|
15307
|
+
// ../../packages/schema/src/zod/harness-map.ts
|
|
15308
|
+
var HARNESS = {
|
|
15309
|
+
ClaudeCode: "claudecode",
|
|
15310
|
+
Cursor: "cursor",
|
|
15311
|
+
Copilot: "copilot",
|
|
15312
|
+
Codex: "codex",
|
|
15313
|
+
Antigravity: "antigravity",
|
|
15314
|
+
Windsurf: "windsurf",
|
|
15315
|
+
ClaudeDesktop: "claudedesktop",
|
|
15316
|
+
ChatGpt: "chatgpt",
|
|
15317
|
+
ClaudeAi: "claudeai",
|
|
15318
|
+
Api: "api"
|
|
15319
|
+
};
|
|
15320
|
+
var Harness = external_exports.enum(HARNESS).meta({ id: "Harness" });
|
|
15321
|
+
var SOURCE_TOOL = {
|
|
15322
|
+
ClaudeCode: "claude-code",
|
|
15323
|
+
ClaudeDesktop: "claude-desktop",
|
|
15324
|
+
Cursor: "cursor",
|
|
15325
|
+
ChatGpt: "chatgpt",
|
|
15326
|
+
ClaudeAi: "claude-ai",
|
|
15327
|
+
Copilot: "github-copilot",
|
|
15328
|
+
Codex: "codex",
|
|
15329
|
+
Antigravity: "antigravity",
|
|
15330
|
+
// No harness counterpart, deliberately: the CLI's own captures and a capture
|
|
15331
|
+
// whose tool could not be identified both render through the read side's
|
|
15332
|
+
// miss path rather than as a harness of their own.
|
|
15333
|
+
Cli: "cli",
|
|
15334
|
+
Unknown: "unknown"
|
|
15335
|
+
};
|
|
15336
|
+
var SourceTool = external_exports.enum(SOURCE_TOOL).meta({ id: "SourceTool" });
|
|
15337
|
+
var TOOL_TO_HARNESS = {
|
|
15338
|
+
[SOURCE_TOOL.ClaudeCode]: HARNESS.ClaudeCode,
|
|
15339
|
+
[SOURCE_TOOL.ClaudeDesktop]: HARNESS.ClaudeDesktop,
|
|
15340
|
+
[SOURCE_TOOL.Copilot]: HARNESS.Copilot,
|
|
15341
|
+
[SOURCE_TOOL.Cursor]: HARNESS.Cursor,
|
|
15342
|
+
[SOURCE_TOOL.ChatGpt]: HARNESS.ChatGpt,
|
|
15343
|
+
[SOURCE_TOOL.Codex]: HARNESS.Codex,
|
|
15344
|
+
[SOURCE_TOOL.Antigravity]: HARNESS.Antigravity,
|
|
15345
|
+
[SOURCE_TOOL.ClaudeAi]: HARNESS.ClaudeAi
|
|
15346
|
+
};
|
|
15347
|
+
|
|
15303
15348
|
// ../../packages/schema/src/zod/finding.ts
|
|
15304
15349
|
var DetectionCategory = external_exports.enum(["pii", "financial", "secret", "phi", "code_context", "code_flaw", "custom", "config"]).meta({ id: "DetectionCategory" });
|
|
15305
15350
|
var Severity = external_exports.enum(["critical", "high", "medium", "low"]).meta({ id: "Severity" });
|
|
@@ -15322,21 +15367,22 @@ var Finding = external_exports.object({
|
|
|
15322
15367
|
}).meta({ id: "Finding" });
|
|
15323
15368
|
var DetectedFinding = Finding.meta({ id: "DetectedFinding" });
|
|
15324
15369
|
var FindingAction = external_exports.enum(["blocked", "redacted", "warned", "allowed", "quarantined", "monitored"]).meta({ id: "FindingAction" });
|
|
15325
|
-
var FindingProvider =
|
|
15326
|
-
"
|
|
15327
|
-
"
|
|
15328
|
-
"
|
|
15329
|
-
"
|
|
15330
|
-
"
|
|
15331
|
-
"
|
|
15332
|
-
"
|
|
15333
|
-
"
|
|
15334
|
-
"
|
|
15370
|
+
var FindingProvider = Harness.extract([
|
|
15371
|
+
"ClaudeCode",
|
|
15372
|
+
"ClaudeDesktop",
|
|
15373
|
+
"Cursor",
|
|
15374
|
+
"Copilot",
|
|
15375
|
+
"ChatGpt",
|
|
15376
|
+
"ClaudeAi",
|
|
15377
|
+
"Codex",
|
|
15378
|
+
"Antigravity",
|
|
15379
|
+
"Api"
|
|
15335
15380
|
]).meta({ id: "FindingProvider" });
|
|
15336
15381
|
var FindingCategory = external_exports.enum([
|
|
15337
15382
|
"secret",
|
|
15338
15383
|
"pii",
|
|
15339
15384
|
"source_code",
|
|
15385
|
+
"code_flaw",
|
|
15340
15386
|
"external_share",
|
|
15341
15387
|
"mcp_server",
|
|
15342
15388
|
"customer_data",
|
|
@@ -15516,6 +15562,7 @@ var FindingInstanceDetail = FindingInstance.extend({
|
|
|
15516
15562
|
policy: FindingPolicyRef
|
|
15517
15563
|
}).meta({ id: "FindingInstanceDetail" });
|
|
15518
15564
|
var DEFAULT_FLAT_FINDINGS_LIMIT = 50;
|
|
15565
|
+
var MAX_FLAT_FINDINGS_LIMIT = 200;
|
|
15519
15566
|
var ListFindingInstancesQuery = external_exports.object({
|
|
15520
15567
|
severity: external_exports.array(Severity).optional(),
|
|
15521
15568
|
// Rule ids, the same vocabulary the grouped list's `subtype` carries.
|
|
@@ -15535,7 +15582,7 @@ var ListFindingInstancesQuery = external_exports.object({
|
|
|
15535
15582
|
q: external_exports.string().optional(),
|
|
15536
15583
|
sessionId: external_exports.string().optional(),
|
|
15537
15584
|
from: external_exports.iso.datetime().optional(),
|
|
15538
|
-
limit: external_exports.coerce.number().int().min(1).max(
|
|
15585
|
+
limit: external_exports.coerce.number().int().min(1).max(MAX_FLAT_FINDINGS_LIMIT).optional(),
|
|
15539
15586
|
cursor: external_exports.string().optional()
|
|
15540
15587
|
});
|
|
15541
15588
|
var ListFindingInstancesResponse = external_exports.object({
|
|
@@ -15597,30 +15644,6 @@ var ListFindingLocationsResponse = external_exports.object({
|
|
|
15597
15644
|
hasMore: external_exports.boolean()
|
|
15598
15645
|
}).meta({ id: "ListFindingLocationsResponse" });
|
|
15599
15646
|
|
|
15600
|
-
// ../../packages/schema/src/zod/harness-map.ts
|
|
15601
|
-
var Harness = external_exports.enum([
|
|
15602
|
-
"claudecode",
|
|
15603
|
-
"cursor",
|
|
15604
|
-
"copilot",
|
|
15605
|
-
"codex",
|
|
15606
|
-
"antigravity",
|
|
15607
|
-
"windsurf",
|
|
15608
|
-
"claudedesktop",
|
|
15609
|
-
"chatgpt",
|
|
15610
|
-
"claudeai",
|
|
15611
|
-
"api"
|
|
15612
|
-
]).meta({ id: "Harness" });
|
|
15613
|
-
var TOOL_TO_HARNESS = {
|
|
15614
|
-
"claude-code": "claudecode",
|
|
15615
|
-
"claude-desktop": "claudedesktop",
|
|
15616
|
-
"github-copilot": "copilot",
|
|
15617
|
-
cursor: "cursor",
|
|
15618
|
-
chatgpt: "chatgpt",
|
|
15619
|
-
codex: "codex",
|
|
15620
|
-
antigravity: "antigravity",
|
|
15621
|
-
"claude-ai": "claudeai"
|
|
15622
|
-
};
|
|
15623
|
-
|
|
15624
15647
|
// ../../packages/schema/src/zod/meta.ts
|
|
15625
15648
|
var InventoryObjectType = external_exports.enum(["host", "harness", "user", "skill", "hook", "mcp_server", "config_file"]).meta({ id: "InventoryObjectType" });
|
|
15626
15649
|
var AuditEventType = external_exports.enum([
|
|
@@ -16073,686 +16096,37 @@ var ActivityOverviewResponse = external_exports.object({
|
|
|
16073
16096
|
sessions: ListActivitySessionsResponse
|
|
16074
16097
|
}).meta({ id: "ActivityOverviewResponse" });
|
|
16075
16098
|
|
|
16076
|
-
// ../../packages/schema/src/zod/
|
|
16077
|
-
var
|
|
16078
|
-
var
|
|
16079
|
-
|
|
16080
|
-
|
|
16081
|
-
|
|
16082
|
-
|
|
16083
|
-
|
|
16084
|
-
|
|
16085
|
-
|
|
16086
|
-
|
|
16087
|
-
|
|
16088
|
-
|
|
16089
|
-
|
|
16090
|
-
|
|
16091
|
-
|
|
16092
|
-
|
|
16093
|
-
|
|
16094
|
-
filePath: external_exports.string().optional(),
|
|
16095
|
-
// The host tool whose input/output was scanned (e.g. 'Bash', 'WebFetch'),
|
|
16096
|
-
// set by the tool-scanning hooks. The tool NAME only — never the tool's
|
|
16097
|
-
// arguments or output, which can carry the very value a finding masked
|
|
16098
|
-
// (metadata is stored unredacted). Gives findings on non-file captures a
|
|
16099
|
-
// display location ("via Bash") when no filePath exists.
|
|
16100
|
-
toolName: external_exports.string().optional(),
|
|
16101
|
-
// Set (true) by the worktree scanner when the file is excluded by the
|
|
16102
|
-
// repo's .gitignore. Gitignored files ARE still scanned — local scratch and
|
|
16103
|
-
// generated code can leak real secrets — but the provenance is recorded so
|
|
16104
|
-
// policy/dashboards can treat those findings as informational rather than
|
|
16105
|
-
// blocking. Omitted (not false) for tracked files and non-scan events.
|
|
16106
|
-
gitignored: external_exports.boolean().optional(),
|
|
16107
|
-
// Set (true) ONLY when the event's `content` is the COMPLETE file at
|
|
16108
|
-
// capture time (a worktree scan reading from disk). Hook-captured edits
|
|
16109
|
-
// (e.g. an Edit tool's new_string) are partial fragments and MUST NOT set
|
|
16110
|
-
// this. The resolver-on-ingest keys its fixed-at-source dropout
|
|
16111
|
-
// diff on this marker: only a whole-file snapshot can prove a previously
|
|
16112
|
-
// open finding is gone; a fragment's absence proves nothing (the secret
|
|
16113
|
-
// may live outside the hunk). Omitted (not false) for fragments and
|
|
16114
|
-
// non-scan events, so pre-marker clients safely default to the
|
|
16115
|
-
// non-authoritative path.
|
|
16116
|
-
wholeFile: external_exports.boolean().optional(),
|
|
16117
|
-
model: external_exports.string().optional(),
|
|
16118
|
-
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
16119
|
-
// Distributed-tracing correlation. `correlationId` ties a recorded event back
|
|
16120
|
-
// to the request that captured/ingested it (a UUID, generated independently of
|
|
16121
|
-
// the trace id); `traceId` is the W3C trace id (32 lowercase hex chars) of the
|
|
16122
|
-
// originating span when telemetry is enabled. Both optional + backward
|
|
16123
|
-
// compatible — populated by the plugin (see @akasecurity/plugin-sdk).
|
|
16124
|
-
correlationId: external_exports.uuid().optional(),
|
|
16125
|
-
traceId: external_exports.string().regex(/^[0-9a-f]{32}$/).optional(),
|
|
16126
|
-
// Ids of the detection exceptions that downgraded findings in this capture
|
|
16127
|
-
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
16128
|
-
// authorized the bypass. Absent on captures where no exception applied.
|
|
16129
|
-
exceptionIds: external_exports.array(external_exports.guid()).optional()
|
|
16130
|
-
}).meta({ id: "EventMetadata" });
|
|
16131
|
-
var Event = external_exports.object({
|
|
16132
|
-
id: external_exports.guid(),
|
|
16133
|
-
sourceTool: SourceTool,
|
|
16134
|
-
kind: EventKind,
|
|
16135
|
-
occurredAt: external_exports.iso.datetime(),
|
|
16136
|
-
contentHash: external_exports.string(),
|
|
16137
|
-
content: external_exports.string(),
|
|
16138
|
-
metadata: EventMetadata.optional()
|
|
16139
|
-
}).meta({ id: "Event" });
|
|
16140
|
-
var IngestEvent = Event.meta({ id: "IngestEvent" });
|
|
16141
|
-
var IngestBatch = external_exports.object({
|
|
16142
|
-
events: external_exports.array(IngestEvent).min(1).max(100),
|
|
16143
|
-
// Dedup policy for this batch. Id-dedup ALWAYS applies. 'content-hash'
|
|
16144
|
-
// additionally rejects any event whose contentHash the store has already
|
|
16145
|
-
// recorded — for re-runnable bulk ingest (worktree scan, transcript
|
|
16146
|
-
// backfill), where a re-run mints fresh event ids for identical content and
|
|
16147
|
-
// would otherwise accumulate duplicates. Live hook traffic must NOT set it:
|
|
16148
|
-
// two genuinely separate prompts can be byte-identical and both belong on
|
|
16149
|
-
// the timeline.
|
|
16150
|
-
dedupe: external_exports.literal("content-hash").optional()
|
|
16151
|
-
}).meta({ id: "IngestBatch" });
|
|
16152
|
-
|
|
16153
|
-
// ../../packages/schema/src/zod/inventory.ts
|
|
16154
|
-
var AssetType = external_exports.enum(["project", "skill", "mcp", "hook", "config"]).meta({ id: "AssetType" });
|
|
16155
|
-
var AccessLevel = external_exports.enum(["open", "approved", "blocked"]).meta({ id: "AccessLevel" });
|
|
16156
|
-
var Origin = external_exports.enum(["source", "public-dep", "vendored", "config", "data", "docs", "generated"]).meta({ id: "Origin" });
|
|
16157
|
-
var TrustLevel = external_exports.enum(["known-good", "risky", "unapproved"]).meta({ id: "TrustLevel" });
|
|
16158
|
-
var Flag = external_exports.enum(["update", "stale", "conflict", "unknown", "change", "untracked", "risk", "findings"]).meta({ id: "Flag" });
|
|
16159
|
-
var Visibility = external_exports.enum(["public", "private"]).meta({ id: "Visibility" });
|
|
16160
|
-
var HarnessEventKind = external_exports.enum(["block", "redact", "warn"]).meta({ id: "HarnessEventKind" });
|
|
16161
|
-
var HarnessId = external_exports.enum(["claudecode", "cursor", "codex", "antigravity"]).meta({ id: "HarnessId" });
|
|
16162
|
-
var AccessCounts = external_exports.object({
|
|
16163
|
-
open: external_exports.number().int().nonnegative(),
|
|
16164
|
-
approved: external_exports.number().int().nonnegative(),
|
|
16165
|
-
blocked: external_exports.number().int().nonnegative(),
|
|
16166
|
-
total: external_exports.number().int().nonnegative()
|
|
16167
|
-
}).meta({ id: "AccessCounts" });
|
|
16168
|
-
var AssetSummary = external_exports.object({
|
|
16169
|
-
id: external_exports.string(),
|
|
16170
|
-
type: AssetType,
|
|
16171
|
-
name: external_exports.string(),
|
|
16172
|
-
sub: external_exports.string(),
|
|
16173
|
-
flags: external_exports.array(Flag),
|
|
16174
|
-
/** MCP servers only — omitted for all other types. */
|
|
16175
|
-
trust: TrustLevel.optional()
|
|
16176
|
-
}).meta({ id: "AssetSummary" });
|
|
16177
|
-
var ProjectSummary = external_exports.object({
|
|
16178
|
-
id: external_exports.string(),
|
|
16179
|
-
name: external_exports.string(),
|
|
16180
|
-
repo: external_exports.string(),
|
|
16181
|
-
visibility: Visibility,
|
|
16182
|
-
language: external_exports.string(),
|
|
16183
|
-
policyDefault: AccessLevel,
|
|
16184
|
-
updatedAt: external_exports.iso.datetime(),
|
|
16185
|
-
accessCounts: AccessCounts,
|
|
16186
|
-
findingsCount: external_exports.number().int().nonnegative()
|
|
16187
|
-
}).meta({ id: "ProjectSummary" });
|
|
16188
|
-
var HarnessCategory = external_exports.object({
|
|
16189
|
-
/** One of config/skill/mcp/hook — never project (enforced at service layer). */
|
|
16190
|
-
type: AssetType,
|
|
16191
|
-
assets: external_exports.array(AssetSummary)
|
|
16099
|
+
// ../../packages/schema/src/zod/config-inventory.ts
|
|
16100
|
+
var ConfigScope = external_exports.enum(["user", "project", "local", "plugin"]);
|
|
16101
|
+
var SkillScanEntry = external_exports.object({
|
|
16102
|
+
name: external_exports.string().min(1),
|
|
16103
|
+
// The identity source: a marketplace repo for plugin skills (e.g.
|
|
16104
|
+
// 'anthropics/skills'), 'local' for personal ~/.claude/skills, or
|
|
16105
|
+
// 'project:<repo-identity>' for checked-in project skills. The surrogate keeps
|
|
16106
|
+
// a personal skill named 'pdf' from colliding with the marketplace 'pdf'.
|
|
16107
|
+
source: external_exports.string().min(1),
|
|
16108
|
+
scope: ConfigScope,
|
|
16109
|
+
pluginName: external_exports.string().optional(),
|
|
16110
|
+
// Volatile — rides the attribute bag, never the identity hash.
|
|
16111
|
+
version: external_exports.string().optional(),
|
|
16112
|
+
description: external_exports.string().optional(),
|
|
16113
|
+
// Skill directory mtime (ISO) — the "updated Nd ago" freshness signal.
|
|
16114
|
+
updatedAt: external_exports.iso.datetime().optional(),
|
|
16115
|
+
// Filesystem path — the promoted inventory `location` column.
|
|
16116
|
+
location: external_exports.string().optional()
|
|
16192
16117
|
});
|
|
16193
|
-
var
|
|
16194
|
-
|
|
16195
|
-
|
|
16196
|
-
|
|
16197
|
-
|
|
16198
|
-
|
|
16199
|
-
|
|
16200
|
-
|
|
16201
|
-
|
|
16202
|
-
|
|
16203
|
-
|
|
16204
|
-
|
|
16205
|
-
var AssetGroup = external_exports.object({
|
|
16206
|
-
/** Group key — never project (enforced at service layer). */
|
|
16207
|
-
type: AssetType,
|
|
16208
|
-
total: external_exports.number().int().nonnegative(),
|
|
16209
|
-
/**
|
|
16210
|
-
* MCP group only — omitted for all other types.
|
|
16211
|
-
* Partial: only TrustLevel keys with non-zero counts are included.
|
|
16212
|
-
* Strict: unknown keys are rejected — only TrustLevel values are valid keys.
|
|
16213
|
-
*/
|
|
16214
|
-
trustRollup: external_exports.object({
|
|
16215
|
-
"known-good": external_exports.number().int().nonnegative(),
|
|
16216
|
-
risky: external_exports.number().int().nonnegative(),
|
|
16217
|
-
unapproved: external_exports.number().int().nonnegative()
|
|
16218
|
-
}).partial().strict().optional(),
|
|
16219
|
-
/**
|
|
16220
|
-
* Partial: only Flag keys with non-zero counts are included.
|
|
16221
|
-
* Strict: unknown keys are rejected — only Flag values are valid keys.
|
|
16222
|
-
*/
|
|
16223
|
-
flagRollup: external_exports.object({
|
|
16224
|
-
update: external_exports.number().int().nonnegative(),
|
|
16225
|
-
stale: external_exports.number().int().nonnegative(),
|
|
16226
|
-
conflict: external_exports.number().int().nonnegative(),
|
|
16227
|
-
unknown: external_exports.number().int().nonnegative(),
|
|
16228
|
-
change: external_exports.number().int().nonnegative(),
|
|
16229
|
-
untracked: external_exports.number().int().nonnegative(),
|
|
16230
|
-
risk: external_exports.number().int().nonnegative(),
|
|
16231
|
-
findings: external_exports.number().int().nonnegative()
|
|
16232
|
-
}).partial().strict(),
|
|
16233
|
-
items: external_exports.array(AssetSummary)
|
|
16234
|
-
}).meta({ id: "AssetGroup" });
|
|
16235
|
-
var ListAssetsResponse = external_exports.object({ groups: external_exports.array(AssetGroup) }).meta({ id: "ListAssetsResponse" });
|
|
16236
|
-
var McpTool = external_exports.object({
|
|
16237
|
-
name: external_exports.string(),
|
|
16238
|
-
signature: external_exports.string(),
|
|
16239
|
-
description: external_exports.string(),
|
|
16240
|
-
write: external_exports.boolean(),
|
|
16241
|
-
/** Non-null string when tool is dangerous / blocked; null otherwise. */
|
|
16242
|
-
risk: external_exports.string().nullable()
|
|
16243
|
-
}).meta({ id: "McpTool" });
|
|
16244
|
-
var AssetFindingRef = external_exports.object({
|
|
16245
|
-
id: external_exports.string(),
|
|
16246
|
-
title: external_exports.string(),
|
|
16247
|
-
note: external_exports.string()
|
|
16248
|
-
});
|
|
16249
|
-
var AssetDetail = AssetSummary.extend({
|
|
16250
|
-
/** string | null — null when no description is available. */
|
|
16251
|
-
description: external_exports.string().nullable(),
|
|
16252
|
-
/** trustLevel | null — null for non-MCP assets. */
|
|
16253
|
-
trust: TrustLevel.nullable(),
|
|
16254
|
-
/** Type-specific raw key/values — FE renders the grid. */
|
|
16255
|
-
meta: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
16256
|
-
/** always present — object when there is an active finding, null when absent. */
|
|
16257
|
-
finding: AssetFindingRef.nullable(),
|
|
16258
|
-
/** MCP exposed-tools list — omitted for non-mcp. */
|
|
16259
|
-
tools: external_exports.array(McpTool).optional()
|
|
16260
|
-
}).meta({ id: "AssetDetail" });
|
|
16261
|
-
var ListProjectsResponse = external_exports.object({ items: external_exports.array(ProjectSummary) }).meta({ id: "ListProjectsResponse" });
|
|
16262
|
-
var InventoryStats = external_exports.object({
|
|
16263
|
-
/** Total assets/projects with ≥1 flag or finding (drives the attention header chip). */
|
|
16264
|
-
attention: external_exports.number().int().nonnegative(),
|
|
16265
|
-
byType: external_exports.object({
|
|
16266
|
-
project: external_exports.number().int().nonnegative(),
|
|
16267
|
-
skill: external_exports.number().int().nonnegative(),
|
|
16268
|
-
mcp: external_exports.number().int().nonnegative(),
|
|
16269
|
-
hook: external_exports.number().int().nonnegative(),
|
|
16270
|
-
config: external_exports.number().int().nonnegative()
|
|
16271
|
-
}),
|
|
16272
|
-
harnesses: external_exports.number().int().nonnegative(),
|
|
16273
|
-
mcpTrust: external_exports.object({
|
|
16274
|
-
"known-good": external_exports.number().int().nonnegative(),
|
|
16275
|
-
risky: external_exports.number().int().nonnegative(),
|
|
16276
|
-
unapproved: external_exports.number().int().nonnegative()
|
|
16277
|
-
})
|
|
16278
|
-
}).meta({ id: "InventoryStats" });
|
|
16279
|
-
var FileSummary = external_exports.object({
|
|
16280
|
-
path: external_exports.string(),
|
|
16281
|
-
name: external_exports.string(),
|
|
16282
|
-
origin: Origin,
|
|
16283
|
-
/** Effective access (override applied). */
|
|
16284
|
-
access: AccessLevel,
|
|
16285
|
-
/** True when a file_access_override differs from the computed default. */
|
|
16286
|
-
isCustom: external_exports.boolean(),
|
|
16287
|
-
findings: external_exports.number().int().nonnegative(),
|
|
16288
|
-
/** When the file was auto-blocked by a detection; null when not blocked. */
|
|
16289
|
-
blockedAt: external_exports.iso.datetime().nullable().optional(),
|
|
16290
|
-
/** Why the file was blocked; null when absent. */
|
|
16291
|
-
note: external_exports.string().nullable().optional()
|
|
16292
|
-
}).meta({ id: "FileSummary" });
|
|
16293
|
-
var FolderSummary = external_exports.object({
|
|
16294
|
-
name: external_exports.string(),
|
|
16295
|
-
path: external_exports.string(),
|
|
16296
|
-
/** Rollup of effective access across all descendants. */
|
|
16297
|
-
accessCounts: AccessCounts
|
|
16298
|
-
}).meta({ id: "FolderSummary" });
|
|
16299
|
-
var ProjectTreeResponse = external_exports.object({
|
|
16300
|
-
project: external_exports.object({
|
|
16301
|
-
id: external_exports.string(),
|
|
16302
|
-
repo: external_exports.string(),
|
|
16303
|
-
visibility: Visibility
|
|
16304
|
-
}),
|
|
16305
|
-
path: external_exports.string(),
|
|
16306
|
-
/** Browse mode: one-level folders at the current path. Omitted in search mode. */
|
|
16307
|
-
folders: external_exports.array(FolderSummary).optional(),
|
|
16308
|
-
files: external_exports.array(FileSummary)
|
|
16309
|
-
}).meta({ id: "ProjectTreeResponse" });
|
|
16310
|
-
var FileDetail = FileSummary.extend({
|
|
16311
|
-
project: external_exports.object({
|
|
16312
|
-
repo: external_exports.string(),
|
|
16313
|
-
visibility: Visibility,
|
|
16314
|
-
language: external_exports.string(),
|
|
16315
|
-
policyDefault: AccessLevel,
|
|
16316
|
-
updatedAt: external_exports.iso.datetime()
|
|
16317
|
-
}),
|
|
16318
|
-
findingsRefs: external_exports.array(external_exports.object({ id: external_exports.string(), title: external_exports.string() }))
|
|
16319
|
-
}).meta({ id: "FileDetail" });
|
|
16320
|
-
var SetFileAccessBody = external_exports.object({
|
|
16321
|
-
path: external_exports.string(),
|
|
16322
|
-
access: AccessLevel
|
|
16323
|
-
}).meta({ id: "SetFileAccessBody" });
|
|
16324
|
-
var SetFileAccessResponse = external_exports.object({
|
|
16325
|
-
file: FileSummary,
|
|
16326
|
-
accessCounts: AccessCounts
|
|
16327
|
-
}).meta({ id: "SetFileAccessResponse" });
|
|
16328
|
-
var SetMcpTrustBody = external_exports.object({ trust: TrustLevel }).meta({ id: "SetMcpTrustBody" });
|
|
16329
|
-
var HarnessEventItem = external_exports.object({
|
|
16330
|
-
kind: HarnessEventKind,
|
|
16331
|
-
title: external_exports.string(),
|
|
16332
|
-
detail: external_exports.string(),
|
|
16333
|
-
occurredAt: external_exports.iso.datetime(),
|
|
16334
|
-
findingId: external_exports.string().nullable().optional()
|
|
16335
|
-
}).meta({ id: "HarnessEventItem" });
|
|
16336
|
-
var HarnessEventsResponse = external_exports.object({
|
|
16337
|
-
counts: external_exports.object({
|
|
16338
|
-
block: external_exports.number().int().nonnegative(),
|
|
16339
|
-
redact: external_exports.number().int().nonnegative(),
|
|
16340
|
-
warn: external_exports.number().int().nonnegative()
|
|
16341
|
-
}),
|
|
16342
|
-
items: external_exports.array(HarnessEventItem)
|
|
16343
|
-
}).meta({ id: "HarnessEventsResponse" });
|
|
16344
|
-
var RescanResponse = external_exports.object({
|
|
16345
|
-
jobId: external_exports.string(),
|
|
16346
|
-
startedAt: external_exports.iso.datetime()
|
|
16347
|
-
}).meta({ id: "RescanResponse" });
|
|
16348
|
-
var ConnectProjectBody = external_exports.object({ repo: external_exports.string() }).meta({ id: "ConnectProjectBody" });
|
|
16349
|
-
var ListAssetsQuery = external_exports.object({
|
|
16350
|
-
/** Filter by one or more AssetType values; absent means all types. */
|
|
16351
|
-
type: external_exports.array(AssetType).optional(),
|
|
16352
|
-
/** Free-text search term. */
|
|
16353
|
-
q: external_exports.string().optional()
|
|
16354
|
-
});
|
|
16355
|
-
var GetProjectTreeQuery = external_exports.object({
|
|
16356
|
-
/** Subtree root path; defaults to repository root when absent. */
|
|
16357
|
-
path: external_exports.string().optional(),
|
|
16358
|
-
/** Free-text filter applied to file paths. */
|
|
16359
|
-
q: external_exports.string().optional(),
|
|
16360
|
-
/**
|
|
16361
|
-
* Special listing mode. `blocked` returns every effectively-blocked, auto-blocked
|
|
16362
|
-
* file across the whole repo (folders omitted, most-recent first), ignoring
|
|
16363
|
-
* `path`/`q` — powers the project-wide "recently blocked" strip.
|
|
16364
|
-
*/
|
|
16365
|
-
filter: external_exports.enum(["blocked"]).optional()
|
|
16366
|
-
});
|
|
16367
|
-
var GetProjectFileQuery = external_exports.object({
|
|
16368
|
-
/** Repository-relative file path; absent or empty → 400. */
|
|
16369
|
-
path: external_exports.string()
|
|
16370
|
-
});
|
|
16371
|
-
var GetHarnessEventsQuery = external_exports.object({
|
|
16372
|
-
/** Maximum number of events to return. Range: 1–50; default: 7. */
|
|
16373
|
-
limit: external_exports.coerce.number().int().min(1).max(50).default(7)
|
|
16374
|
-
});
|
|
16375
|
-
|
|
16376
|
-
// ../../packages/schema/src/zod/exception.ts
|
|
16377
|
-
var ExceptionScope = external_exports.enum(["once", "temporary", "permanent"]);
|
|
16378
|
-
var ExceptionConditions = external_exports.object({
|
|
16379
|
-
repo: external_exports.string().optional(),
|
|
16380
|
-
sourceTool: external_exports.string().optional(),
|
|
16381
|
-
provider: external_exports.string().optional()
|
|
16382
|
-
}).strict();
|
|
16383
|
-
var ExceptionCapability = external_exports.enum(["suppress", "reveal_to_model"]);
|
|
16384
|
-
var DetectionException = external_exports.object({
|
|
16385
|
-
id: external_exports.guid(),
|
|
16386
|
-
ruleId: external_exports.string(),
|
|
16387
|
-
// Denormalized from the rule, for reporting — never matched on.
|
|
16388
|
-
category: DetectionCategory,
|
|
16389
|
-
// HMAC-SHA256 hex of the raw match under a machine-local key: a KEYED
|
|
16390
|
-
// fingerprint, never the raw value, and never reversible. Matching recomputes
|
|
16391
|
-
// the fingerprint from a fresh capture; the value itself is never stored.
|
|
16392
|
-
// Shape-constrained so a malformed — or accidentally raw — value is rejected
|
|
16393
|
-
// at the boundary rather than persisted.
|
|
16394
|
-
valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
16395
|
-
// Version of the fingerprint key the grant was written under; a rotated key
|
|
16396
|
-
// invalidates old grants rather than silently mismatching them.
|
|
16397
|
-
keyVersion: external_exports.number().int().positive(),
|
|
16398
|
-
// maskMatch() preview of the approved value — never the raw value.
|
|
16399
|
-
maskedValue: external_exports.string(),
|
|
16400
|
-
capability: ExceptionCapability.default("suppress"),
|
|
16401
|
-
scope: ExceptionScope,
|
|
16402
|
-
expiresAt: external_exports.iso.datetime().nullable(),
|
|
16403
|
-
maxUses: external_exports.number().int().positive().nullable(),
|
|
16404
|
-
useCount: external_exports.number().int().nonnegative(),
|
|
16405
|
-
lastUsedAt: external_exports.iso.datetime().nullable(),
|
|
16406
|
-
// Mandatory: every grant carries the human reason it exists.
|
|
16407
|
-
justification: external_exports.string().min(1),
|
|
16408
|
-
conditions: ExceptionConditions.nullable(),
|
|
16409
|
-
createdBy: external_exports.string(),
|
|
16410
|
-
createdVia: external_exports.enum(["cli-approve", "cli-add", "web-approve", "web-add", "api", "setup-triage"]),
|
|
16411
|
-
createdAt: external_exports.iso.datetime(),
|
|
16412
|
-
updatedAt: external_exports.iso.datetime(),
|
|
16413
|
-
// Revocation is terminal and retained — consumed/expired/revoked rows are
|
|
16414
|
-
// audit evidence; nothing in the exception lifecycle hard-deletes.
|
|
16415
|
-
revokedAt: external_exports.iso.datetime().nullable(),
|
|
16416
|
-
revokedBy: external_exports.string().nullable(),
|
|
16417
|
-
revokeReason: external_exports.string().nullable()
|
|
16418
|
-
});
|
|
16419
|
-
var ExceptionBundleEntry = DetectionException.pick({
|
|
16420
|
-
id: true,
|
|
16421
|
-
ruleId: true,
|
|
16422
|
-
valueFingerprint: true,
|
|
16423
|
-
keyVersion: true,
|
|
16424
|
-
capability: true,
|
|
16425
|
-
expiresAt: true,
|
|
16426
|
-
maxUses: true,
|
|
16427
|
-
useCount: true,
|
|
16428
|
-
conditions: true
|
|
16429
|
-
});
|
|
16430
|
-
var ExceptionDescriptor = DetectionException.omit({ valueFingerprint: true });
|
|
16431
|
-
|
|
16432
|
-
// ../../packages/schema/src/zod/rule.ts
|
|
16433
|
-
var MatcherType = external_exports.enum(["keyword", "regex", "validator"]).meta({ id: "MatcherType" });
|
|
16434
|
-
var RuleProbeVerdict = external_exports.enum(["safe", "quarantined"]).meta({ id: "RuleProbeVerdict" });
|
|
16435
|
-
var KeywordMatcher = external_exports.object({
|
|
16436
|
-
type: external_exports.literal("keyword"),
|
|
16437
|
-
// An empty keyword matches at every position, yielding one zero-length span
|
|
16438
|
-
// per character. Rejected here because a keyword that matches everything is
|
|
16439
|
-
// never intentional.
|
|
16440
|
-
keywords: external_exports.array(external_exports.string().min(1)).min(1),
|
|
16441
|
-
caseSensitive: external_exports.boolean().default(false)
|
|
16442
|
-
});
|
|
16443
|
-
function isValidRegex(pattern, flags) {
|
|
16444
|
-
try {
|
|
16445
|
-
new RegExp(pattern, flags);
|
|
16446
|
-
return true;
|
|
16447
|
-
} catch {
|
|
16448
|
-
return false;
|
|
16449
|
-
}
|
|
16450
|
-
}
|
|
16451
|
-
function matchesEmptyString(pattern, flags) {
|
|
16452
|
-
try {
|
|
16453
|
-
const re = new RegExp(pattern, flags.replace(/[gy]/g, ""));
|
|
16454
|
-
return re.exec("")?.[0].length === 0;
|
|
16455
|
-
} catch {
|
|
16456
|
-
return false;
|
|
16457
|
-
}
|
|
16458
|
-
}
|
|
16459
|
-
var MAX_PATTERN_LENGTH = 2e3;
|
|
16460
|
-
var RegexMatcher = external_exports.object({
|
|
16461
|
-
type: external_exports.literal("regex"),
|
|
16462
|
-
pattern: external_exports.string().min(1).max(MAX_PATTERN_LENGTH),
|
|
16463
|
-
flags: external_exports.string().default("gi"),
|
|
16464
|
-
captureGroup: external_exports.number().int().nonnegative().optional()
|
|
16465
|
-
}).refine((v) => isValidRegex(v.pattern, v.flags), {
|
|
16466
|
-
message: "pattern/flags do not form a valid JavaScript regular expression",
|
|
16467
|
-
path: ["pattern"]
|
|
16468
|
-
}).refine((v) => v.captureGroup !== void 0 || !matchesEmptyString(v.pattern, v.flags), {
|
|
16469
|
-
message: 'a whole-match regex that can match the empty string (e.g. "\\d*", "a?", "(?:)") can hang the matcher \u2014 scope the quantifier to a captureGroup, or require at least one character',
|
|
16470
|
-
path: ["pattern"]
|
|
16471
|
-
});
|
|
16472
|
-
var ValidatorMatcher = external_exports.object({
|
|
16473
|
-
type: external_exports.literal("validator"),
|
|
16474
|
-
name: external_exports.enum(["luhn", "entropy", "ssn-checksum"]),
|
|
16475
|
-
config: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
16476
|
-
});
|
|
16477
|
-
var Matcher = external_exports.discriminatedUnion("type", [KeywordMatcher, RegexMatcher, ValidatorMatcher]).meta({ id: "Matcher" });
|
|
16478
|
-
var AppliesTo = external_exports.object({
|
|
16479
|
-
// Dot-prefixed, e.g. ".py" — matches the scanner's SOURCE_EXTENSIONS shape.
|
|
16480
|
-
extensions: external_exports.array(external_exports.string().regex(/^\.[A-Za-z0-9]+$/)).min(1)
|
|
16481
|
-
}).meta({ id: "AppliesTo" });
|
|
16482
|
-
var PostValidatorRef = external_exports.union([
|
|
16483
|
-
external_exports.string(),
|
|
16484
|
-
external_exports.object({
|
|
16485
|
-
name: external_exports.string(),
|
|
16486
|
-
config: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
16487
|
-
})
|
|
16488
|
-
]).meta({ id: "PostValidatorRef" });
|
|
16489
|
-
var RequiresNearby = external_exports.object({
|
|
16490
|
-
// Each array, when present, must be non-empty and contain non-empty strings —
|
|
16491
|
-
// an empty/blank criterion would either never fire or (for labels) match
|
|
16492
|
-
// everything.
|
|
16493
|
-
categories: external_exports.array(DetectionCategory).min(1).optional(),
|
|
16494
|
-
ruleIds: external_exports.array(external_exports.string().min(1)).min(1).optional(),
|
|
16495
|
-
labels: external_exports.array(external_exports.string().min(1)).min(1).optional(),
|
|
16496
|
-
windowChars: external_exports.number().int().positive().default(160),
|
|
16497
|
-
// Optional confidence bump applied when a gated match is corroborated. Capped
|
|
16498
|
-
// small: it nudges confidence, it does not assert certainty.
|
|
16499
|
-
confidenceBoost: external_exports.number().min(0).max(0.3).optional()
|
|
16500
|
-
}).refine(
|
|
16501
|
-
(v) => (v.categories?.length ?? 0) + (v.ruleIds?.length ?? 0) + (v.labels?.length ?? 0) > 0,
|
|
16502
|
-
{ message: "requiresNearby needs at least one of categories, ruleIds, or labels" }
|
|
16503
|
-
).meta({ id: "RequiresNearby" });
|
|
16504
|
-
var RuleFixture = external_exports.object({
|
|
16505
|
-
label: external_exports.string(),
|
|
16506
|
-
text: external_exports.string().max(5e4),
|
|
16507
|
-
shouldMatch: external_exports.boolean(),
|
|
16508
|
-
// Simulated file context for the scan, so fixtures can assert `appliesTo`
|
|
16509
|
-
// gating (e.g. a Python-only pattern must NOT fire in a .ts file).
|
|
16510
|
-
filePath: external_exports.string().optional(),
|
|
16511
|
-
expectedSpans: external_exports.array(external_exports.object({ start: external_exports.number(), end: external_exports.number() })).optional()
|
|
16512
|
-
}).meta({ id: "RuleFixture" });
|
|
16513
|
-
var Rule = external_exports.object({
|
|
16514
|
-
specVersion: external_exports.literal(1),
|
|
16515
|
-
// `packId/ruleName` (e.g. `secrets/aws-access-key`). NOTE the first segment is
|
|
16516
|
-
// the PACK id, NOT a namespace — this is a DIFFERENT slug space from a
|
|
16517
|
-
// detection id (`namespace/packId`, decoded by splitDetectionId). A Rule.id
|
|
16518
|
-
// therefore carries no namespace and is not globally unique across publishers;
|
|
16519
|
-
// never feed one to splitDetectionId. `category` below (per-rule) is the
|
|
16520
|
-
// taxonomy axis; the pack's enforcement policy is installed_packs.policy_id.
|
|
16521
|
-
id: external_exports.string().regex(/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/),
|
|
16522
|
-
name: external_exports.string(),
|
|
16523
|
-
category: DetectionCategory,
|
|
16524
|
-
severity: Severity,
|
|
16525
|
-
matcher: Matcher,
|
|
16526
|
-
appliesTo: AppliesTo.optional(),
|
|
16527
|
-
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
16528
|
-
requiresNearby: RequiresNearby.optional(),
|
|
16529
|
-
examples: external_exports.array(external_exports.string()).optional()
|
|
16530
|
-
}).meta({ id: "Rule" });
|
|
16531
|
-
var Author = external_exports.object({
|
|
16532
|
-
name: external_exports.string(),
|
|
16533
|
-
email: external_exports.email().optional(),
|
|
16534
|
-
url: external_exports.url().optional()
|
|
16535
|
-
}).meta({ id: "Author" });
|
|
16536
|
-
var PackManifest = external_exports.object({
|
|
16537
|
-
specVersion: external_exports.literal(1),
|
|
16538
|
-
id: external_exports.string(),
|
|
16539
|
-
name: external_exports.string(),
|
|
16540
|
-
version: external_exports.string(),
|
|
16541
|
-
rules: external_exports.array(external_exports.string()),
|
|
16542
|
-
// Optional attribution/provenance — consumed by the rule marketplace.
|
|
16543
|
-
description: external_exports.string().optional(),
|
|
16544
|
-
author: Author.optional(),
|
|
16545
|
-
license: external_exports.string().optional(),
|
|
16546
|
-
sourceUrl: external_exports.url().optional()
|
|
16547
|
-
}).meta({ id: "PackManifest" });
|
|
16548
|
-
|
|
16549
|
-
// ../../packages/schema/src/zod/policy.ts
|
|
16550
|
-
var PolicyScope = external_exports.enum(["global", "repo", "user"]).meta({ id: "PolicyScope" });
|
|
16551
|
-
var PolicyTarget = external_exports.union([external_exports.object({ ruleId: external_exports.string() }), external_exports.object({ category: DetectionCategory })]).meta({ id: "PolicyTarget" });
|
|
16552
|
-
var Policy = external_exports.object({
|
|
16553
|
-
id: external_exports.guid(),
|
|
16554
|
-
scope: PolicyScope,
|
|
16555
|
-
target: PolicyTarget,
|
|
16556
|
-
action: ActionTaken,
|
|
16557
|
-
enabled: external_exports.boolean().default(true),
|
|
16558
|
-
customKeywords: external_exports.array(external_exports.string()).optional(),
|
|
16559
|
-
// Display name — optional so older policy rows without name still parse.
|
|
16560
|
-
// Added for the findings API (policy.name column migration).
|
|
16561
|
-
name: external_exports.string().optional()
|
|
16562
|
-
}).meta({ id: "Policy" });
|
|
16563
|
-
var PolicyBundle = external_exports.object({
|
|
16564
|
-
version: external_exports.string(),
|
|
16565
|
-
policies: external_exports.array(Policy),
|
|
16566
|
-
// Rules from the installed marketplace packs (snapshotted by the
|
|
16567
|
-
// control plane). The plugin registers these in addition to its bundled
|
|
16568
|
-
// packs. Optional so older backends — and older on-disk caches — that omit
|
|
16569
|
-
// the field still parse; consumers read `bundle.rules ?? []`.
|
|
16570
|
-
rules: external_exports.array(Rule).optional(),
|
|
16571
|
-
// When true, `rules` IS the complete effective ruleset and the runtime must
|
|
16572
|
-
// NOT merge its compiled-in bundled packs — the standalone gateway sets this
|
|
16573
|
-
// after reading the user's installed snapshot (installed_packs, enabled
|
|
16574
|
-
// packs only), which is how detection updates stay manual: new bundled
|
|
16575
|
-
// rules run only after the user applies the pack update. Absent/false keeps
|
|
16576
|
-
// the historical composition (bundled packs + rules) — older caches.
|
|
16577
|
-
rulesComplete: external_exports.boolean().optional(),
|
|
16578
|
-
// Active detection exceptions, evaluation subset only (see
|
|
16579
|
-
// ExceptionBundleEntry). Optional so older bundle producers — and older
|
|
16580
|
-
// on-disk caches — that omit the field still parse; consumers read
|
|
16581
|
-
// `bundle.exceptions ?? []`.
|
|
16582
|
-
exceptions: external_exports.array(ExceptionBundleEntry).optional(),
|
|
16583
|
-
// Installed pack version, keyed by ruleId, for rules in `rules` that came
|
|
16584
|
-
// from a versioned installed pack. Optional so older backends — and older
|
|
16585
|
-
// on-disk caches — that omit the field still parse; consumers fall back to
|
|
16586
|
-
// the rule's own spec version. NOT the bundle version above — see
|
|
16587
|
-
// installedRuleset's ruleVersions for the source of truth.
|
|
16588
|
-
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
16589
|
-
customKeywords: external_exports.array(external_exports.string()),
|
|
16590
|
-
fetchedAt: external_exports.iso.datetime()
|
|
16591
|
-
}).meta({ id: "PolicyBundle" });
|
|
16592
|
-
var OBSERVE_ONLY_CATEGORIES = ["config"];
|
|
16593
|
-
var ENFORCEABLE_CATEGORIES = DetectionCategory.options.filter((c) => !OBSERVE_ONLY_CATEGORIES.includes(c));
|
|
16594
|
-
var CATEGORY_PEAK_SEVERITY = {
|
|
16595
|
-
secret: "critical",
|
|
16596
|
-
financial: "critical",
|
|
16597
|
-
// core-financial/credit-card
|
|
16598
|
-
code_flaw: "critical",
|
|
16599
|
-
pii: "high",
|
|
16600
|
-
phi: "high",
|
|
16601
|
-
custom: "high",
|
|
16602
|
-
// user-defined; conservative
|
|
16603
|
-
code_context: "low",
|
|
16604
|
-
config: "low"
|
|
16605
|
-
// observe-only; floors to monitor regardless
|
|
16606
|
-
};
|
|
16607
|
-
function severityFloorPolicy(category) {
|
|
16608
|
-
if (OBSERVE_ONLY_CATEGORIES.includes(category)) return "monitor";
|
|
16609
|
-
const peak = CATEGORY_PEAK_SEVERITY[category];
|
|
16610
|
-
return peak === "critical" || peak === "high" ? "warn" : "monitor";
|
|
16611
|
-
}
|
|
16612
|
-
var PolicyKind = external_exports.enum(["builtin", "custom"]).meta({ id: "PolicyKind" });
|
|
16613
|
-
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "block"];
|
|
16614
|
-
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
16615
|
-
var BUILTIN_ORDER = KNOWN_BUILTIN_IDS;
|
|
16616
|
-
var BUILTIN_POLICY_SPECS = {
|
|
16617
|
-
monitor: {
|
|
16618
|
-
name: "Monitor",
|
|
16619
|
-
action: "log",
|
|
16620
|
-
description: "Log every match for audit. The request is allowed through untouched."
|
|
16621
|
-
},
|
|
16622
|
-
warn: {
|
|
16623
|
-
name: "Warn",
|
|
16624
|
-
action: "warn",
|
|
16625
|
-
description: "Allow the request, but warn the user inline before it is sent."
|
|
16626
|
-
},
|
|
16627
|
-
redact: {
|
|
16628
|
-
name: "Redact",
|
|
16629
|
-
action: "redact",
|
|
16630
|
-
description: "Automatically strip the matched value from the request, then continue."
|
|
16631
|
-
},
|
|
16632
|
-
block: {
|
|
16633
|
-
name: "Block",
|
|
16634
|
-
action: "block",
|
|
16635
|
-
description: "Refuse the request entirely whenever any rule in this detection matches."
|
|
16636
|
-
}
|
|
16637
|
-
};
|
|
16638
|
-
function builtinPolicyToAction(id) {
|
|
16639
|
-
return BUILTIN_POLICY_SPECS[id].action;
|
|
16640
|
-
}
|
|
16641
|
-
var DEFAULT_ACTIONS = Object.fromEntries(
|
|
16642
|
-
DetectionCategory.options.map((c) => [c, builtinPolicyToAction(severityFloorPolicy(c))])
|
|
16643
|
-
);
|
|
16644
|
-
var BUILTIN_POLICIES = Object.fromEntries(
|
|
16645
|
-
KNOWN_BUILTIN_IDS.map((id) => [id, { id, ...BUILTIN_POLICY_SPECS[id] }])
|
|
16646
|
-
);
|
|
16647
|
-
var DEFAULT_PACK_POLICY_ID = "monitor";
|
|
16648
|
-
function policyIdToAction(policyId) {
|
|
16649
|
-
const parsed = BuiltinPolicyId.safeParse(policyId ?? DEFAULT_PACK_POLICY_ID);
|
|
16650
|
-
const id = parsed.success ? parsed.data : DEFAULT_PACK_POLICY_ID;
|
|
16651
|
-
return BUILTIN_POLICIES[id].action;
|
|
16652
|
-
}
|
|
16653
|
-
var UsedByItem = external_exports.object({
|
|
16654
|
-
id: external_exports.string(),
|
|
16655
|
-
name: external_exports.string(),
|
|
16656
|
-
ruleCount: external_exports.number().int().nonnegative(),
|
|
16657
|
-
enabled: external_exports.boolean()
|
|
16658
|
-
}).meta({ id: "UsedByItem" });
|
|
16659
|
-
var PolicyListItem = external_exports.object({
|
|
16660
|
-
id: external_exports.string(),
|
|
16661
|
-
kind: PolicyKind,
|
|
16662
|
-
name: external_exports.string(),
|
|
16663
|
-
enabled: external_exports.boolean(),
|
|
16664
|
-
usedByCount: external_exports.number().int().nonnegative()
|
|
16665
|
-
}).meta({ id: "PolicyListItem" });
|
|
16666
|
-
var PolicyDetail = external_exports.object({
|
|
16667
|
-
specVersion: external_exports.literal(1),
|
|
16668
|
-
id: external_exports.string(),
|
|
16669
|
-
kind: PolicyKind,
|
|
16670
|
-
name: external_exports.string(),
|
|
16671
|
-
enabled: external_exports.boolean(),
|
|
16672
|
-
description: external_exports.string(),
|
|
16673
|
-
usedBy: external_exports.array(UsedByItem)
|
|
16674
|
-
}).meta({ id: "PolicyDetail" });
|
|
16675
|
-
var PolicyStatsResponse = external_exports.object({
|
|
16676
|
-
policies: external_exports.number().int().nonnegative(),
|
|
16677
|
-
builtin: external_exports.number().int().nonnegative(),
|
|
16678
|
-
custom: external_exports.number().int().nonnegative(),
|
|
16679
|
-
detectionsGoverned: external_exports.number().int().nonnegative()
|
|
16680
|
-
}).meta({ id: "PolicyStatsResponse" });
|
|
16681
|
-
|
|
16682
|
-
// ../../packages/schema/src/zod/api.ts
|
|
16683
|
-
var LIST_QUERY_MAX_LIMIT = 200;
|
|
16684
|
-
var ListEventsQuery = external_exports.object({
|
|
16685
|
-
cursor: external_exports.string().optional(),
|
|
16686
|
-
limit: external_exports.coerce.number().int().min(1).max(LIST_QUERY_MAX_LIMIT).default(50),
|
|
16687
|
-
sourceTool: external_exports.string().optional(),
|
|
16688
|
-
kind: external_exports.string().optional(),
|
|
16689
|
-
from: external_exports.iso.datetime().optional(),
|
|
16690
|
-
to: external_exports.iso.datetime().optional()
|
|
16691
|
-
});
|
|
16692
|
-
var ListEventsResponse = external_exports.object({
|
|
16693
|
-
items: external_exports.array(Event),
|
|
16694
|
-
nextCursor: external_exports.string().nullable()
|
|
16695
|
-
}).meta({ id: "ListEventsResponse" });
|
|
16696
|
-
var IngestResponse = external_exports.object({
|
|
16697
|
-
accepted: external_exports.number().int().nonnegative(),
|
|
16698
|
-
duplicates: external_exports.number().int().nonnegative()
|
|
16699
|
-
}).meta({ id: "IngestResponse" });
|
|
16700
|
-
var ListFindingsQuery = external_exports.object({
|
|
16701
|
-
cursor: external_exports.string().optional(),
|
|
16702
|
-
limit: external_exports.coerce.number().int().min(1).max(LIST_QUERY_MAX_LIMIT).default(50),
|
|
16703
|
-
severity: external_exports.string().optional(),
|
|
16704
|
-
category: external_exports.string().optional(),
|
|
16705
|
-
eventId: external_exports.guid().optional()
|
|
16706
|
-
});
|
|
16707
|
-
var ListFindingsResponse = external_exports.object({
|
|
16708
|
-
items: external_exports.array(Finding),
|
|
16709
|
-
nextCursor: external_exports.string().nullable()
|
|
16710
|
-
}).meta({ id: "ListFindingsResponse" });
|
|
16711
|
-
var ListPoliciesResponse = external_exports.object({ items: external_exports.array(PolicyListItem) }).meta({ id: "ListPoliciesResponse" });
|
|
16712
|
-
var CreatePolicyRequest = Policy.omit({ id: true }).meta({
|
|
16713
|
-
id: "CreatePolicyRequest"
|
|
16714
|
-
});
|
|
16715
|
-
var UpdatePolicyRequest = Policy.partial().required({ id: true }).meta({ id: "UpdatePolicyRequest" });
|
|
16716
|
-
var RecordAuditEventResponse = external_exports.object({ accepted: external_exports.boolean() }).meta({ id: "RecordAuditEventResponse" });
|
|
16717
|
-
var ErrorResponse = external_exports.object({
|
|
16718
|
-
error: external_exports.object({
|
|
16719
|
-
code: external_exports.string(),
|
|
16720
|
-
message: external_exports.string(),
|
|
16721
|
-
details: external_exports.unknown().optional()
|
|
16722
|
-
})
|
|
16723
|
-
}).meta({ id: "ErrorResponse" });
|
|
16724
|
-
|
|
16725
|
-
// ../../packages/schema/src/zod/config-inventory.ts
|
|
16726
|
-
var ConfigScope = external_exports.enum(["user", "project", "local", "plugin"]);
|
|
16727
|
-
var SkillScanEntry = external_exports.object({
|
|
16728
|
-
name: external_exports.string().min(1),
|
|
16729
|
-
// The identity source: a marketplace repo for plugin skills (e.g.
|
|
16730
|
-
// 'anthropics/skills'), 'local' for personal ~/.claude/skills, or
|
|
16731
|
-
// 'project:<repo-identity>' for checked-in project skills. The surrogate keeps
|
|
16732
|
-
// a personal skill named 'pdf' from colliding with the marketplace 'pdf'.
|
|
16733
|
-
source: external_exports.string().min(1),
|
|
16734
|
-
scope: ConfigScope,
|
|
16735
|
-
pluginName: external_exports.string().optional(),
|
|
16736
|
-
// Volatile — rides the attribute bag, never the identity hash.
|
|
16737
|
-
version: external_exports.string().optional(),
|
|
16738
|
-
description: external_exports.string().optional(),
|
|
16739
|
-
// Skill directory mtime (ISO) — the "updated Nd ago" freshness signal.
|
|
16740
|
-
updatedAt: external_exports.iso.datetime().optional(),
|
|
16741
|
-
// Filesystem path — the promoted inventory `location` column.
|
|
16742
|
-
location: external_exports.string().optional()
|
|
16743
|
-
});
|
|
16744
|
-
var HookScanEntry = external_exports.object({
|
|
16745
|
-
// Hook event name (PreToolUse, PostToolUse, …). Open string, not an enum: the
|
|
16746
|
-
// set is harness-defined and grows without a schema change.
|
|
16747
|
-
event: external_exports.string().min(1),
|
|
16748
|
-
// The tool matcher ('Bash', 'Edit|Write', …). Absent = matches all tools.
|
|
16749
|
-
matcher: external_exports.string().optional(),
|
|
16750
|
-
command: external_exports.string().min(1),
|
|
16751
|
-
timeout: external_exports.number().optional(),
|
|
16752
|
-
scope: ConfigScope,
|
|
16753
|
-
pluginName: external_exports.string().optional(),
|
|
16754
|
-
// The settings file / hooks.json the entry came from.
|
|
16755
|
-
location: external_exports.string().optional()
|
|
16118
|
+
var HookScanEntry = external_exports.object({
|
|
16119
|
+
// Hook event name (PreToolUse, PostToolUse, …). Open string, not an enum: the
|
|
16120
|
+
// set is harness-defined and grows without a schema change.
|
|
16121
|
+
event: external_exports.string().min(1),
|
|
16122
|
+
// The tool matcher ('Bash', 'Edit|Write', …). Absent = matches all tools.
|
|
16123
|
+
matcher: external_exports.string().optional(),
|
|
16124
|
+
command: external_exports.string().min(1),
|
|
16125
|
+
timeout: external_exports.number().optional(),
|
|
16126
|
+
scope: ConfigScope,
|
|
16127
|
+
pluginName: external_exports.string().optional(),
|
|
16128
|
+
// The settings file / hooks.json the entry came from.
|
|
16129
|
+
location: external_exports.string().optional()
|
|
16756
16130
|
});
|
|
16757
16131
|
var McpServerScanEntry = external_exports.object({
|
|
16758
16132
|
// The server's config key ("github", "filesystem", …) — identity, with the
|
|
@@ -16834,6 +16208,164 @@ var PackId = external_exports.string().regex(/^[a-z][a-z0-9-]*$/);
|
|
|
16834
16208
|
var SemVer = external_exports.string().regex(/^\d+\.\d+\.\d+(?:-[0-9A-Za-z-.]+)?$/);
|
|
16835
16209
|
var PublisherKind = external_exports.enum(["labs", "user", "org"]);
|
|
16836
16210
|
|
|
16211
|
+
// ../../packages/schema/src/zod/rule.ts
|
|
16212
|
+
var MatcherType = external_exports.enum(["keyword", "regex"]).meta({ id: "MatcherType" });
|
|
16213
|
+
var RuleProbeVerdict = external_exports.enum(["safe", "quarantined"]).meta({ id: "RuleProbeVerdict" });
|
|
16214
|
+
var KeywordMatcher = external_exports.strictObject({
|
|
16215
|
+
type: external_exports.literal("keyword"),
|
|
16216
|
+
// An empty keyword matches at every position, yielding one zero-length span
|
|
16217
|
+
// per character. Rejected here because a keyword that matches everything is
|
|
16218
|
+
// never intentional.
|
|
16219
|
+
keywords: external_exports.array(external_exports.string().min(1)).min(1),
|
|
16220
|
+
caseSensitive: external_exports.boolean().default(false)
|
|
16221
|
+
});
|
|
16222
|
+
function isValidRegex(pattern, flags) {
|
|
16223
|
+
try {
|
|
16224
|
+
new RegExp(pattern, flags);
|
|
16225
|
+
return true;
|
|
16226
|
+
} catch {
|
|
16227
|
+
return false;
|
|
16228
|
+
}
|
|
16229
|
+
}
|
|
16230
|
+
function probeFlags(flags) {
|
|
16231
|
+
return flags.replace(/[gy]/g, "");
|
|
16232
|
+
}
|
|
16233
|
+
function matchesEmptyString(pattern, flags) {
|
|
16234
|
+
try {
|
|
16235
|
+
const re = new RegExp(pattern, probeFlags(flags));
|
|
16236
|
+
return re.exec("")?.[0].length === 0;
|
|
16237
|
+
} catch {
|
|
16238
|
+
return false;
|
|
16239
|
+
}
|
|
16240
|
+
}
|
|
16241
|
+
function spansWholeMatch(captureGroup) {
|
|
16242
|
+
return captureGroup === void 0 || captureGroup === 0;
|
|
16243
|
+
}
|
|
16244
|
+
function captureGroupCount(pattern, flags) {
|
|
16245
|
+
try {
|
|
16246
|
+
const probe = new RegExp(`${pattern}|`, probeFlags(flags));
|
|
16247
|
+
const result = probe.exec("");
|
|
16248
|
+
return result ? result.length - 1 : void 0;
|
|
16249
|
+
} catch {
|
|
16250
|
+
return void 0;
|
|
16251
|
+
}
|
|
16252
|
+
}
|
|
16253
|
+
var MAX_PATTERN_LENGTH = 2e3;
|
|
16254
|
+
var RegexMatcher = external_exports.strictObject({
|
|
16255
|
+
type: external_exports.literal("regex"),
|
|
16256
|
+
pattern: external_exports.string().min(1).max(MAX_PATTERN_LENGTH),
|
|
16257
|
+
flags: external_exports.string().default("gi"),
|
|
16258
|
+
captureGroup: external_exports.number().int().nonnegative().optional()
|
|
16259
|
+
}).refine((v) => isValidRegex(v.pattern, v.flags), {
|
|
16260
|
+
message: "pattern/flags do not form a valid JavaScript regular expression",
|
|
16261
|
+
path: ["pattern"]
|
|
16262
|
+
}).refine((v) => !spansWholeMatch(v.captureGroup) || !matchesEmptyString(v.pattern, v.flags), {
|
|
16263
|
+
message: 'a whole-match regex that can match the empty string (e.g. "\\d*", "a?", "(?:)") can hang the matcher \u2014 scope the quantifier to a captureGroup, or require at least one character',
|
|
16264
|
+
path: ["pattern"]
|
|
16265
|
+
}).superRefine((v, ctx) => {
|
|
16266
|
+
if (v.captureGroup === void 0) return;
|
|
16267
|
+
const groups = captureGroupCount(v.pattern, v.flags);
|
|
16268
|
+
if (groups === void 0 || v.captureGroup <= groups) return;
|
|
16269
|
+
ctx.addIssue({
|
|
16270
|
+
code: "custom",
|
|
16271
|
+
path: ["captureGroup"],
|
|
16272
|
+
message: `captureGroup ${String(v.captureGroup)} is out of range \u2014 the pattern declares ${String(groups)} capture group(s), so valid values are 0-${String(groups)}. An out-of-range group never matches, which would make the rule silently never fire.`
|
|
16273
|
+
});
|
|
16274
|
+
});
|
|
16275
|
+
var Matcher = external_exports.discriminatedUnion("type", [KeywordMatcher, RegexMatcher]).meta({ id: "Matcher" });
|
|
16276
|
+
var MATCHER_TYPES = MatcherType.options;
|
|
16277
|
+
var AppliesTo = external_exports.strictObject({
|
|
16278
|
+
// Dot-prefixed, e.g. ".py" — matches the scanner's SOURCE_EXTENSIONS shape.
|
|
16279
|
+
extensions: external_exports.array(external_exports.string().regex(/^\.[A-Za-z0-9]+$/)).min(1)
|
|
16280
|
+
}).meta({ id: "AppliesTo" });
|
|
16281
|
+
var PostValidatorName = external_exports.enum(["entropy", "luhn"]).meta({ id: "PostValidatorName" });
|
|
16282
|
+
var PostValidatorRef = external_exports.union(
|
|
16283
|
+
[
|
|
16284
|
+
PostValidatorName,
|
|
16285
|
+
external_exports.strictObject({
|
|
16286
|
+
name: PostValidatorName,
|
|
16287
|
+
config: external_exports.record(external_exports.string(), external_exports.unknown()).optional()
|
|
16288
|
+
})
|
|
16289
|
+
],
|
|
16290
|
+
{
|
|
16291
|
+
// A union reports one collapsed issue for every way its arms can fail, so
|
|
16292
|
+
// this has to describe the whole shape rather than just the name — it is
|
|
16293
|
+
// what an author sees for a misspelled name AND for a stray key in the
|
|
16294
|
+
// object form. The names come from the enum so the message cannot go
|
|
16295
|
+
// stale. Without it Zod says only "Invalid input", which is precisely the
|
|
16296
|
+
// no-feedback outcome this schema exists to remove.
|
|
16297
|
+
error: () => `not a valid post-validator: use a bare name (${PostValidatorName.options.map((name) => JSON.stringify(name)).join(
|
|
16298
|
+
" or "
|
|
16299
|
+
)}) or { "name": ..., "config": { ... } }. An unrecognized name would be a false-positive guard that never runs.`
|
|
16300
|
+
}
|
|
16301
|
+
).meta({ id: "PostValidatorRef" });
|
|
16302
|
+
var RequiresNearby = external_exports.strictObject({
|
|
16303
|
+
// Each array, when present, must be non-empty and contain non-empty strings —
|
|
16304
|
+
// an empty/blank criterion would either never fire or (for labels) match
|
|
16305
|
+
// everything.
|
|
16306
|
+
categories: external_exports.array(DetectionCategory).min(1).optional(),
|
|
16307
|
+
ruleIds: external_exports.array(external_exports.string().min(1)).min(1).optional(),
|
|
16308
|
+
labels: external_exports.array(external_exports.string().min(1)).min(1).optional(),
|
|
16309
|
+
windowChars: external_exports.number().int().positive().default(160),
|
|
16310
|
+
// Optional confidence bump applied when a gated match is corroborated. Capped
|
|
16311
|
+
// small: it nudges confidence, it does not assert certainty.
|
|
16312
|
+
confidenceBoost: external_exports.number().min(0).max(0.3).optional()
|
|
16313
|
+
}).refine(
|
|
16314
|
+
(v) => (v.categories?.length ?? 0) + (v.ruleIds?.length ?? 0) + (v.labels?.length ?? 0) > 0,
|
|
16315
|
+
{ message: "requiresNearby needs at least one of categories, ruleIds, or labels" }
|
|
16316
|
+
).meta({ id: "RequiresNearby" });
|
|
16317
|
+
var RuleFixture = external_exports.strictObject({
|
|
16318
|
+
label: external_exports.string(),
|
|
16319
|
+
text: external_exports.string().max(5e4),
|
|
16320
|
+
shouldMatch: external_exports.boolean(),
|
|
16321
|
+
// Simulated file context for the scan, so fixtures can assert `appliesTo`
|
|
16322
|
+
// gating (e.g. a Python-only pattern must NOT fire in a .ts file).
|
|
16323
|
+
filePath: external_exports.string().optional(),
|
|
16324
|
+
expectedSpans: external_exports.array(external_exports.strictObject({ start: external_exports.number(), end: external_exports.number() })).optional()
|
|
16325
|
+
}).meta({ id: "RuleFixture" });
|
|
16326
|
+
var Rule = external_exports.strictObject({
|
|
16327
|
+
// A pinned literal over a STRICT object, and the two together decide how this
|
|
16328
|
+
// format may grow. A rule carrying a key not listed below is refused with
|
|
16329
|
+
// `unrecognized_keys`; a rule declaring `specVersion: 2` is refused with
|
|
16330
|
+
// `invalid_value`. So the only additive path is adding an OPTIONAL field here
|
|
16331
|
+
// — that keeps every rule authored before it valid — and a rule author has no
|
|
16332
|
+
// way to introduce a field of their own or to opt into a later version.
|
|
16333
|
+
// Widening the format means changing this literal and every consumer of it.
|
|
16334
|
+
specVersion: external_exports.literal(1),
|
|
16335
|
+
// `packId/ruleName` (e.g. `secrets/aws-access-key`). NOTE the first segment is
|
|
16336
|
+
// the PACK id, NOT a namespace — this is a DIFFERENT slug space from a
|
|
16337
|
+
// detection id (`namespace/packId`, decoded by splitDetectionId). A Rule.id
|
|
16338
|
+
// therefore carries no namespace and is not globally unique across publishers;
|
|
16339
|
+
// never feed one to splitDetectionId. `category` below (per-rule) is the
|
|
16340
|
+
// taxonomy axis; the pack's enforcement policy is installed_packs.policy_id.
|
|
16341
|
+
id: external_exports.string().regex(/^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/),
|
|
16342
|
+
name: external_exports.string(),
|
|
16343
|
+
category: DetectionCategory,
|
|
16344
|
+
severity: Severity,
|
|
16345
|
+
matcher: Matcher,
|
|
16346
|
+
appliesTo: AppliesTo.optional(),
|
|
16347
|
+
postValidators: external_exports.array(PostValidatorRef).optional(),
|
|
16348
|
+
requiresNearby: RequiresNearby.optional(),
|
|
16349
|
+
examples: external_exports.array(external_exports.string()).optional()
|
|
16350
|
+
}).meta({ id: "Rule" });
|
|
16351
|
+
var Author = external_exports.object({
|
|
16352
|
+
name: external_exports.string(),
|
|
16353
|
+
email: external_exports.email().optional(),
|
|
16354
|
+
url: external_exports.url().optional()
|
|
16355
|
+
}).meta({ id: "Author" });
|
|
16356
|
+
var PackManifest = external_exports.object({
|
|
16357
|
+
specVersion: external_exports.literal(1),
|
|
16358
|
+
id: external_exports.string(),
|
|
16359
|
+
name: external_exports.string(),
|
|
16360
|
+
version: external_exports.string(),
|
|
16361
|
+
rules: external_exports.array(external_exports.string()),
|
|
16362
|
+
// Optional attribution/provenance — consumed by the rule marketplace.
|
|
16363
|
+
description: external_exports.string().optional(),
|
|
16364
|
+
author: Author.optional(),
|
|
16365
|
+
license: external_exports.string().optional(),
|
|
16366
|
+
sourceUrl: external_exports.url().optional()
|
|
16367
|
+
}).meta({ id: "PackManifest" });
|
|
16368
|
+
|
|
16837
16369
|
// ../../packages/schema/src/zod/detection.ts
|
|
16838
16370
|
var OriginEnum = external_exports.enum(["library"]).meta({ id: "OriginEnum" });
|
|
16839
16371
|
var DetectionFilterEnum = external_exports.enum(["all", "library", "custom", "customized", "updates"]);
|
|
@@ -17032,6 +16564,231 @@ function buildDetectionsList(summaries, query) {
|
|
|
17032
16564
|
return { counts, items: filtered.map(summaryToDetectionListItem) };
|
|
17033
16565
|
}
|
|
17034
16566
|
|
|
16567
|
+
// ../../packages/schema/src/zod/inventory.ts
|
|
16568
|
+
var AssetType = external_exports.enum(["project", "skill", "mcp", "hook", "config"]).meta({ id: "AssetType" });
|
|
16569
|
+
var AccessLevel = external_exports.enum(["open", "approved", "blocked"]).meta({ id: "AccessLevel" });
|
|
16570
|
+
var Origin = external_exports.enum(["source", "public-dep", "vendored", "config", "data", "docs", "generated"]).meta({ id: "Origin" });
|
|
16571
|
+
var TrustLevel = external_exports.enum(["known-good", "risky", "unapproved"]).meta({ id: "TrustLevel" });
|
|
16572
|
+
var Flag = external_exports.enum(["update", "stale", "conflict", "unknown", "change", "untracked", "risk", "findings"]).meta({ id: "Flag" });
|
|
16573
|
+
var Visibility = external_exports.enum(["public", "private"]).meta({ id: "Visibility" });
|
|
16574
|
+
var HarnessEventKind = external_exports.enum(["block", "redact", "warn"]).meta({ id: "HarnessEventKind" });
|
|
16575
|
+
var HarnessId = Harness.extract(["ClaudeCode", "Cursor", "Codex", "Antigravity"]).meta({
|
|
16576
|
+
id: "HarnessId"
|
|
16577
|
+
});
|
|
16578
|
+
var AccessCounts = external_exports.object({
|
|
16579
|
+
open: external_exports.number().int().nonnegative(),
|
|
16580
|
+
approved: external_exports.number().int().nonnegative(),
|
|
16581
|
+
blocked: external_exports.number().int().nonnegative(),
|
|
16582
|
+
total: external_exports.number().int().nonnegative()
|
|
16583
|
+
}).meta({ id: "AccessCounts" });
|
|
16584
|
+
var AssetSummary = external_exports.object({
|
|
16585
|
+
id: external_exports.string(),
|
|
16586
|
+
type: AssetType,
|
|
16587
|
+
name: external_exports.string(),
|
|
16588
|
+
sub: external_exports.string(),
|
|
16589
|
+
flags: external_exports.array(Flag),
|
|
16590
|
+
/** MCP servers only — omitted for all other types. */
|
|
16591
|
+
trust: TrustLevel.optional()
|
|
16592
|
+
}).meta({ id: "AssetSummary" });
|
|
16593
|
+
var ProjectSummary = external_exports.object({
|
|
16594
|
+
id: external_exports.string(),
|
|
16595
|
+
name: external_exports.string(),
|
|
16596
|
+
repo: external_exports.string(),
|
|
16597
|
+
visibility: Visibility,
|
|
16598
|
+
language: external_exports.string(),
|
|
16599
|
+
policyDefault: AccessLevel,
|
|
16600
|
+
updatedAt: external_exports.iso.datetime(),
|
|
16601
|
+
accessCounts: AccessCounts,
|
|
16602
|
+
findingsCount: external_exports.number().int().nonnegative()
|
|
16603
|
+
}).meta({ id: "ProjectSummary" });
|
|
16604
|
+
var HarnessCategory = external_exports.object({
|
|
16605
|
+
/** One of config/skill/mcp/hook — never project (enforced at service layer). */
|
|
16606
|
+
type: AssetType,
|
|
16607
|
+
assets: external_exports.array(AssetSummary)
|
|
16608
|
+
});
|
|
16609
|
+
var HarnessSummary = external_exports.object({
|
|
16610
|
+
id: HarnessId,
|
|
16611
|
+
label: external_exports.string(),
|
|
16612
|
+
kind: external_exports.string(),
|
|
16613
|
+
version: external_exports.string(),
|
|
16614
|
+
sessions: external_exports.number().int().nonnegative(),
|
|
16615
|
+
assetCount: external_exports.number().int().nonnegative(),
|
|
16616
|
+
flagCount: external_exports.number().int().nonnegative(),
|
|
16617
|
+
projects: external_exports.array(ProjectSummary),
|
|
16618
|
+
categories: external_exports.array(HarnessCategory)
|
|
16619
|
+
}).meta({ id: "HarnessSummary" });
|
|
16620
|
+
var ListHarnessesResponse = external_exports.object({ items: external_exports.array(HarnessSummary) }).meta({ id: "ListHarnessesResponse" });
|
|
16621
|
+
var AssetGroup = external_exports.object({
|
|
16622
|
+
/** Group key — never project (enforced at service layer). */
|
|
16623
|
+
type: AssetType,
|
|
16624
|
+
total: external_exports.number().int().nonnegative(),
|
|
16625
|
+
/**
|
|
16626
|
+
* MCP group only — omitted for all other types.
|
|
16627
|
+
* Partial: only TrustLevel keys with non-zero counts are included.
|
|
16628
|
+
* Strict: unknown keys are rejected — only TrustLevel values are valid keys.
|
|
16629
|
+
*/
|
|
16630
|
+
trustRollup: external_exports.object({
|
|
16631
|
+
"known-good": external_exports.number().int().nonnegative(),
|
|
16632
|
+
risky: external_exports.number().int().nonnegative(),
|
|
16633
|
+
unapproved: external_exports.number().int().nonnegative()
|
|
16634
|
+
}).partial().strict().optional(),
|
|
16635
|
+
/**
|
|
16636
|
+
* Partial: only Flag keys with non-zero counts are included.
|
|
16637
|
+
* Strict: unknown keys are rejected — only Flag values are valid keys.
|
|
16638
|
+
*/
|
|
16639
|
+
flagRollup: external_exports.object({
|
|
16640
|
+
update: external_exports.number().int().nonnegative(),
|
|
16641
|
+
stale: external_exports.number().int().nonnegative(),
|
|
16642
|
+
conflict: external_exports.number().int().nonnegative(),
|
|
16643
|
+
unknown: external_exports.number().int().nonnegative(),
|
|
16644
|
+
change: external_exports.number().int().nonnegative(),
|
|
16645
|
+
untracked: external_exports.number().int().nonnegative(),
|
|
16646
|
+
risk: external_exports.number().int().nonnegative(),
|
|
16647
|
+
findings: external_exports.number().int().nonnegative()
|
|
16648
|
+
}).partial().strict(),
|
|
16649
|
+
items: external_exports.array(AssetSummary)
|
|
16650
|
+
}).meta({ id: "AssetGroup" });
|
|
16651
|
+
var ListAssetsResponse = external_exports.object({ groups: external_exports.array(AssetGroup) }).meta({ id: "ListAssetsResponse" });
|
|
16652
|
+
var McpTool = external_exports.object({
|
|
16653
|
+
name: external_exports.string(),
|
|
16654
|
+
signature: external_exports.string(),
|
|
16655
|
+
description: external_exports.string(),
|
|
16656
|
+
write: external_exports.boolean(),
|
|
16657
|
+
/** Non-null string when tool is dangerous / blocked; null otherwise. */
|
|
16658
|
+
risk: external_exports.string().nullable()
|
|
16659
|
+
}).meta({ id: "McpTool" });
|
|
16660
|
+
var AssetFindingRef = external_exports.object({
|
|
16661
|
+
id: external_exports.string(),
|
|
16662
|
+
title: external_exports.string(),
|
|
16663
|
+
note: external_exports.string()
|
|
16664
|
+
});
|
|
16665
|
+
var AssetDetail = AssetSummary.extend({
|
|
16666
|
+
/** string | null — null when no description is available. */
|
|
16667
|
+
description: external_exports.string().nullable(),
|
|
16668
|
+
/** trustLevel | null — null for non-MCP assets. */
|
|
16669
|
+
trust: TrustLevel.nullable(),
|
|
16670
|
+
/** Type-specific raw key/values — FE renders the grid. */
|
|
16671
|
+
meta: external_exports.record(external_exports.string(), external_exports.unknown()),
|
|
16672
|
+
/** always present — object when there is an active finding, null when absent. */
|
|
16673
|
+
finding: AssetFindingRef.nullable(),
|
|
16674
|
+
/** MCP exposed-tools list — omitted for non-mcp. */
|
|
16675
|
+
tools: external_exports.array(McpTool).optional()
|
|
16676
|
+
}).meta({ id: "AssetDetail" });
|
|
16677
|
+
var ListProjectsResponse = external_exports.object({ items: external_exports.array(ProjectSummary) }).meta({ id: "ListProjectsResponse" });
|
|
16678
|
+
var InventoryStats = external_exports.object({
|
|
16679
|
+
/** Total assets/projects with ≥1 flag or finding (drives the attention header chip). */
|
|
16680
|
+
attention: external_exports.number().int().nonnegative(),
|
|
16681
|
+
byType: external_exports.object({
|
|
16682
|
+
project: external_exports.number().int().nonnegative(),
|
|
16683
|
+
skill: external_exports.number().int().nonnegative(),
|
|
16684
|
+
mcp: external_exports.number().int().nonnegative(),
|
|
16685
|
+
hook: external_exports.number().int().nonnegative(),
|
|
16686
|
+
config: external_exports.number().int().nonnegative()
|
|
16687
|
+
}),
|
|
16688
|
+
harnesses: external_exports.number().int().nonnegative(),
|
|
16689
|
+
mcpTrust: external_exports.object({
|
|
16690
|
+
"known-good": external_exports.number().int().nonnegative(),
|
|
16691
|
+
risky: external_exports.number().int().nonnegative(),
|
|
16692
|
+
unapproved: external_exports.number().int().nonnegative()
|
|
16693
|
+
})
|
|
16694
|
+
}).meta({ id: "InventoryStats" });
|
|
16695
|
+
var FileSummary = external_exports.object({
|
|
16696
|
+
path: external_exports.string(),
|
|
16697
|
+
name: external_exports.string(),
|
|
16698
|
+
origin: Origin,
|
|
16699
|
+
/** Effective access (override applied). */
|
|
16700
|
+
access: AccessLevel,
|
|
16701
|
+
/** True when a file_access_override differs from the computed default. */
|
|
16702
|
+
isCustom: external_exports.boolean(),
|
|
16703
|
+
findings: external_exports.number().int().nonnegative(),
|
|
16704
|
+
/** When the file was auto-blocked by a detection; null when not blocked. */
|
|
16705
|
+
blockedAt: external_exports.iso.datetime().nullable().optional(),
|
|
16706
|
+
/** Why the file was blocked; null when absent. */
|
|
16707
|
+
note: external_exports.string().nullable().optional()
|
|
16708
|
+
}).meta({ id: "FileSummary" });
|
|
16709
|
+
var FolderSummary = external_exports.object({
|
|
16710
|
+
name: external_exports.string(),
|
|
16711
|
+
path: external_exports.string(),
|
|
16712
|
+
/** Rollup of effective access across all descendants. */
|
|
16713
|
+
accessCounts: AccessCounts
|
|
16714
|
+
}).meta({ id: "FolderSummary" });
|
|
16715
|
+
var ProjectTreeResponse = external_exports.object({
|
|
16716
|
+
project: external_exports.object({
|
|
16717
|
+
id: external_exports.string(),
|
|
16718
|
+
repo: external_exports.string(),
|
|
16719
|
+
visibility: Visibility
|
|
16720
|
+
}),
|
|
16721
|
+
path: external_exports.string(),
|
|
16722
|
+
/** Browse mode: one-level folders at the current path. Omitted in search mode. */
|
|
16723
|
+
folders: external_exports.array(FolderSummary).optional(),
|
|
16724
|
+
files: external_exports.array(FileSummary)
|
|
16725
|
+
}).meta({ id: "ProjectTreeResponse" });
|
|
16726
|
+
var FileDetail = FileSummary.extend({
|
|
16727
|
+
project: external_exports.object({
|
|
16728
|
+
repo: external_exports.string(),
|
|
16729
|
+
visibility: Visibility,
|
|
16730
|
+
language: external_exports.string(),
|
|
16731
|
+
policyDefault: AccessLevel,
|
|
16732
|
+
updatedAt: external_exports.iso.datetime()
|
|
16733
|
+
}),
|
|
16734
|
+
findingsRefs: external_exports.array(external_exports.object({ id: external_exports.string(), title: external_exports.string() }))
|
|
16735
|
+
}).meta({ id: "FileDetail" });
|
|
16736
|
+
var SetFileAccessBody = external_exports.object({
|
|
16737
|
+
path: external_exports.string(),
|
|
16738
|
+
access: AccessLevel
|
|
16739
|
+
}).meta({ id: "SetFileAccessBody" });
|
|
16740
|
+
var SetFileAccessResponse = external_exports.object({
|
|
16741
|
+
file: FileSummary,
|
|
16742
|
+
accessCounts: AccessCounts
|
|
16743
|
+
}).meta({ id: "SetFileAccessResponse" });
|
|
16744
|
+
var SetMcpTrustBody = external_exports.object({ trust: TrustLevel }).meta({ id: "SetMcpTrustBody" });
|
|
16745
|
+
var HarnessEventItem = external_exports.object({
|
|
16746
|
+
kind: HarnessEventKind,
|
|
16747
|
+
title: external_exports.string(),
|
|
16748
|
+
detail: external_exports.string(),
|
|
16749
|
+
occurredAt: external_exports.iso.datetime(),
|
|
16750
|
+
findingId: external_exports.string().nullable().optional()
|
|
16751
|
+
}).meta({ id: "HarnessEventItem" });
|
|
16752
|
+
var HarnessEventsResponse = external_exports.object({
|
|
16753
|
+
counts: external_exports.object({
|
|
16754
|
+
block: external_exports.number().int().nonnegative(),
|
|
16755
|
+
redact: external_exports.number().int().nonnegative(),
|
|
16756
|
+
warn: external_exports.number().int().nonnegative()
|
|
16757
|
+
}),
|
|
16758
|
+
items: external_exports.array(HarnessEventItem)
|
|
16759
|
+
}).meta({ id: "HarnessEventsResponse" });
|
|
16760
|
+
var RescanResponse = external_exports.object({
|
|
16761
|
+
jobId: external_exports.string(),
|
|
16762
|
+
startedAt: external_exports.iso.datetime()
|
|
16763
|
+
}).meta({ id: "RescanResponse" });
|
|
16764
|
+
var ConnectProjectBody = external_exports.object({ repo: external_exports.string() }).meta({ id: "ConnectProjectBody" });
|
|
16765
|
+
var ListAssetsQuery = external_exports.object({
|
|
16766
|
+
/** Filter by one or more AssetType values; absent means all types. */
|
|
16767
|
+
type: external_exports.array(AssetType).optional(),
|
|
16768
|
+
/** Free-text search term. */
|
|
16769
|
+
q: external_exports.string().optional()
|
|
16770
|
+
});
|
|
16771
|
+
var GetProjectTreeQuery = external_exports.object({
|
|
16772
|
+
/** Subtree root path; defaults to repository root when absent. */
|
|
16773
|
+
path: external_exports.string().optional(),
|
|
16774
|
+
/** Free-text filter applied to file paths. */
|
|
16775
|
+
q: external_exports.string().optional(),
|
|
16776
|
+
/**
|
|
16777
|
+
* Special listing mode. `blocked` returns every effectively-blocked, auto-blocked
|
|
16778
|
+
* file across the whole repo (folders omitted, most-recent first), ignoring
|
|
16779
|
+
* `path`/`q` — powers the project-wide "recently blocked" strip.
|
|
16780
|
+
*/
|
|
16781
|
+
filter: external_exports.enum(["blocked"]).optional()
|
|
16782
|
+
});
|
|
16783
|
+
var GetProjectFileQuery = external_exports.object({
|
|
16784
|
+
/** Repository-relative file path; absent or empty → 400. */
|
|
16785
|
+
path: external_exports.string()
|
|
16786
|
+
});
|
|
16787
|
+
var GetHarnessEventsQuery = external_exports.object({
|
|
16788
|
+
/** Maximum number of events to return. Range: 1–50; default: 7. */
|
|
16789
|
+
limit: external_exports.coerce.number().int().min(1).max(50).default(7)
|
|
16790
|
+
});
|
|
16791
|
+
|
|
17035
16792
|
// ../../packages/schema/src/zod/shares.ts
|
|
17036
16793
|
var DestinationKind = external_exports.enum(["provider", "internal", "external", "ip"]).meta({ id: "DestinationKind" });
|
|
17037
16794
|
var Transport = external_exports.enum(["https", "http", "sftp", "grpc", "smtp", "ws", "wss"]).meta({ id: "Transport" });
|
|
@@ -17238,6 +16995,127 @@ var EgressWriteSummary = external_exports.object({
|
|
|
17238
16995
|
droppedFiles: external_exports.array(external_exports.string()).default([])
|
|
17239
16996
|
}).meta({ id: "EgressWriteSummary" });
|
|
17240
16997
|
|
|
16998
|
+
// ../../packages/schema/src/zod/event.ts
|
|
16999
|
+
var EventKind = external_exports.enum(["prompt", "response", "code_change", "tool_use"]).meta({ id: "EventKind" });
|
|
17000
|
+
var CAPTURE_EVENT_TYPES_SQL = EventKind.options.map((k) => `'${k}'`).join(",");
|
|
17001
|
+
var EventMetadata = external_exports.object({
|
|
17002
|
+
sessionId: external_exports.string().optional(),
|
|
17003
|
+
repo: external_exports.string().optional(),
|
|
17004
|
+
filePath: external_exports.string().optional(),
|
|
17005
|
+
// The host tool whose input/output was scanned (e.g. 'Bash', 'WebFetch'),
|
|
17006
|
+
// set by the tool-scanning hooks. The tool NAME only — never the tool's
|
|
17007
|
+
// arguments or output, which can carry the very value a finding masked
|
|
17008
|
+
// (metadata is stored unredacted). Gives findings on non-file captures a
|
|
17009
|
+
// display location ("via Bash") when no filePath exists.
|
|
17010
|
+
toolName: external_exports.string().optional(),
|
|
17011
|
+
// Set (true) by the worktree scanner when the file is excluded by the
|
|
17012
|
+
// repo's .gitignore. Gitignored files ARE still scanned — local scratch and
|
|
17013
|
+
// generated code can leak real secrets — but the provenance is recorded so
|
|
17014
|
+
// policy/dashboards can treat those findings as informational rather than
|
|
17015
|
+
// blocking. Omitted (not false) for tracked files and non-scan events.
|
|
17016
|
+
gitignored: external_exports.boolean().optional(),
|
|
17017
|
+
// Set (true) ONLY when the event's `content` is the COMPLETE file at
|
|
17018
|
+
// capture time (a worktree scan reading from disk). Hook-captured edits
|
|
17019
|
+
// (e.g. an Edit tool's new_string) are partial fragments and MUST NOT set
|
|
17020
|
+
// this. The resolver-on-ingest keys its fixed-at-source dropout
|
|
17021
|
+
// diff on this marker: only a whole-file snapshot can prove a previously
|
|
17022
|
+
// open finding is gone; a fragment's absence proves nothing (the secret
|
|
17023
|
+
// may live outside the hunk). Omitted (not false) for fragments and
|
|
17024
|
+
// non-scan events, so pre-marker clients safely default to the
|
|
17025
|
+
// non-authoritative path.
|
|
17026
|
+
wholeFile: external_exports.boolean().optional(),
|
|
17027
|
+
model: external_exports.string().optional(),
|
|
17028
|
+
turnIndex: external_exports.number().int().nonnegative().optional(),
|
|
17029
|
+
// Distributed-tracing correlation. `correlationId` ties a recorded event back
|
|
17030
|
+
// to the request that captured/ingested it (a UUID, generated independently of
|
|
17031
|
+
// the trace id); `traceId` is the W3C trace id (32 lowercase hex chars) of the
|
|
17032
|
+
// originating span when telemetry is enabled. Both optional + backward
|
|
17033
|
+
// compatible — populated by the plugin (see @akasecurity/plugin-sdk).
|
|
17034
|
+
correlationId: external_exports.uuid().optional(),
|
|
17035
|
+
traceId: external_exports.string().regex(/^[0-9a-f]{32}$/).optional(),
|
|
17036
|
+
// Ids of the detection exceptions that downgraded findings in this capture
|
|
17037
|
+
// to 'allow' — the enforcement audit trail's link back to the grant that
|
|
17038
|
+
// authorized the bypass. Absent on captures where no exception applied.
|
|
17039
|
+
exceptionIds: external_exports.array(external_exports.guid()).optional()
|
|
17040
|
+
}).meta({ id: "EventMetadata" });
|
|
17041
|
+
var Event = external_exports.object({
|
|
17042
|
+
id: external_exports.guid(),
|
|
17043
|
+
sourceTool: SourceTool,
|
|
17044
|
+
kind: EventKind,
|
|
17045
|
+
occurredAt: external_exports.iso.datetime(),
|
|
17046
|
+
contentHash: external_exports.string(),
|
|
17047
|
+
content: external_exports.string(),
|
|
17048
|
+
metadata: EventMetadata.optional()
|
|
17049
|
+
}).meta({ id: "Event" });
|
|
17050
|
+
var IngestEvent = Event.meta({ id: "IngestEvent" });
|
|
17051
|
+
var IngestBatch = external_exports.object({
|
|
17052
|
+
events: external_exports.array(IngestEvent).min(1).max(100),
|
|
17053
|
+
// Dedup policy for this batch. Id-dedup ALWAYS applies. 'content-hash'
|
|
17054
|
+
// additionally rejects any event whose contentHash the store has already
|
|
17055
|
+
// recorded — for re-runnable bulk ingest (worktree scan, transcript
|
|
17056
|
+
// backfill), where a re-run mints fresh event ids for identical content and
|
|
17057
|
+
// would otherwise accumulate duplicates. Live hook traffic must NOT set it:
|
|
17058
|
+
// two genuinely separate prompts can be byte-identical and both belong on
|
|
17059
|
+
// the timeline.
|
|
17060
|
+
dedupe: external_exports.literal("content-hash").optional()
|
|
17061
|
+
}).meta({ id: "IngestBatch" });
|
|
17062
|
+
|
|
17063
|
+
// ../../packages/schema/src/zod/exception.ts
|
|
17064
|
+
var ExceptionScope = external_exports.enum(["once", "temporary", "permanent"]);
|
|
17065
|
+
var ExceptionConditions = external_exports.object({
|
|
17066
|
+
repo: external_exports.string().optional(),
|
|
17067
|
+
sourceTool: external_exports.string().optional(),
|
|
17068
|
+
provider: external_exports.string().optional()
|
|
17069
|
+
}).strict();
|
|
17070
|
+
var ExceptionCapability = external_exports.enum(["suppress", "reveal_to_model"]);
|
|
17071
|
+
var DetectionException = external_exports.object({
|
|
17072
|
+
id: external_exports.guid(),
|
|
17073
|
+
ruleId: external_exports.string(),
|
|
17074
|
+
// Denormalized from the rule, for reporting — never matched on.
|
|
17075
|
+
category: DetectionCategory,
|
|
17076
|
+
// HMAC-SHA256 hex of the raw match under a machine-local key: a KEYED
|
|
17077
|
+
// fingerprint, never the raw value, and never reversible. Matching recomputes
|
|
17078
|
+
// the fingerprint from a fresh capture; the value itself is never stored.
|
|
17079
|
+
// Shape-constrained so a malformed — or accidentally raw — value is rejected
|
|
17080
|
+
// at the boundary rather than persisted.
|
|
17081
|
+
valueFingerprint: external_exports.string().regex(/^[0-9a-f]{64}$/),
|
|
17082
|
+
// Version of the fingerprint key the grant was written under; a rotated key
|
|
17083
|
+
// invalidates old grants rather than silently mismatching them.
|
|
17084
|
+
keyVersion: external_exports.number().int().positive(),
|
|
17085
|
+
// maskMatch() preview of the approved value — never the raw value.
|
|
17086
|
+
maskedValue: external_exports.string(),
|
|
17087
|
+
capability: ExceptionCapability.default("suppress"),
|
|
17088
|
+
scope: ExceptionScope,
|
|
17089
|
+
expiresAt: external_exports.iso.datetime().nullable(),
|
|
17090
|
+
maxUses: external_exports.number().int().positive().nullable(),
|
|
17091
|
+
useCount: external_exports.number().int().nonnegative(),
|
|
17092
|
+
lastUsedAt: external_exports.iso.datetime().nullable(),
|
|
17093
|
+
// Mandatory: every grant carries the human reason it exists.
|
|
17094
|
+
justification: external_exports.string().min(1),
|
|
17095
|
+
conditions: ExceptionConditions.nullable(),
|
|
17096
|
+
createdBy: external_exports.string(),
|
|
17097
|
+
createdVia: external_exports.enum(["cli-approve", "cli-add", "web-approve", "web-add", "api", "setup-triage"]),
|
|
17098
|
+
createdAt: external_exports.iso.datetime(),
|
|
17099
|
+
updatedAt: external_exports.iso.datetime(),
|
|
17100
|
+
// Revocation is terminal and retained — consumed/expired/revoked rows are
|
|
17101
|
+
// audit evidence; nothing in the exception lifecycle hard-deletes.
|
|
17102
|
+
revokedAt: external_exports.iso.datetime().nullable(),
|
|
17103
|
+
revokedBy: external_exports.string().nullable(),
|
|
17104
|
+
revokeReason: external_exports.string().nullable()
|
|
17105
|
+
});
|
|
17106
|
+
var ExceptionBundleEntry = DetectionException.pick({
|
|
17107
|
+
id: true,
|
|
17108
|
+
ruleId: true,
|
|
17109
|
+
valueFingerprint: true,
|
|
17110
|
+
keyVersion: true,
|
|
17111
|
+
capability: true,
|
|
17112
|
+
expiresAt: true,
|
|
17113
|
+
maxUses: true,
|
|
17114
|
+
useCount: true,
|
|
17115
|
+
conditions: true
|
|
17116
|
+
});
|
|
17117
|
+
var ExceptionDescriptor = DetectionException.omit({ valueFingerprint: true });
|
|
17118
|
+
|
|
17241
17119
|
// ../../packages/schema/src/zod/exception-action.ts
|
|
17242
17120
|
var confirmation = external_exports.string().optional();
|
|
17243
17121
|
var ApproveBlockedInput = external_exports.object({
|
|
@@ -17280,10 +17158,11 @@ function toApiAction(dbVal) {
|
|
|
17280
17158
|
}
|
|
17281
17159
|
function toApiCategory(dbVal) {
|
|
17282
17160
|
if (dbVal === "code_context") return "source_code";
|
|
17283
|
-
|
|
17161
|
+
const parsed = FindingCategory.safeParse(dbVal);
|
|
17162
|
+
return parsed.success ? parsed.data : "custom";
|
|
17284
17163
|
}
|
|
17285
17164
|
function toApiProvider(sourceTool) {
|
|
17286
|
-
return TOOL_TO_HARNESS[sourceTool] ??
|
|
17165
|
+
return TOOL_TO_HARNESS[sourceTool] ?? HARNESS.Api;
|
|
17287
17166
|
}
|
|
17288
17167
|
var STATUS_PRECEDENCE = ["open", "handled", "dismissed", "resolved"];
|
|
17289
17168
|
function foldGroupStatus(instanceStatuses) {
|
|
@@ -17871,7 +17750,14 @@ function isVaultConsentValid(consent) {
|
|
|
17871
17750
|
|
|
17872
17751
|
// ../../packages/schema/src/zod/local.ts
|
|
17873
17752
|
var WORKSPACE_SETTINGS_SPEC_VERSION = 5;
|
|
17874
|
-
var
|
|
17753
|
+
var MODEL_JUDGE_PAYLOAD_VERSION = 1;
|
|
17754
|
+
var RunMode = external_exports.enum(["standalone", "attached"]);
|
|
17755
|
+
var ControlPlaneConnection = external_exports.object({
|
|
17756
|
+
endpoint: external_exports.string().min(1),
|
|
17757
|
+
// Display name for the deployment, shown instead of the raw endpoint.
|
|
17758
|
+
label: external_exports.string().min(1).optional(),
|
|
17759
|
+
attachedAt: external_exports.iso.datetime()
|
|
17760
|
+
}).meta({ id: "ControlPlaneConnection" });
|
|
17875
17761
|
var SimpleDetectionPolicy = external_exports.enum(["redact", "warn"]);
|
|
17876
17762
|
var HistoricalAccess = external_exports.enum(["full", "session-only"]);
|
|
17877
17763
|
var ModelJudgeConsent = external_exports.object({
|
|
@@ -17880,12 +17766,10 @@ var ModelJudgeConsent = external_exports.object({
|
|
|
17880
17766
|
});
|
|
17881
17767
|
var WorkspaceSettings = external_exports.object({
|
|
17882
17768
|
specVersion: external_exports.number().int().positive().default(WORKSPACE_SETTINGS_SPEC_VERSION),
|
|
17883
|
-
|
|
17884
|
-
//
|
|
17885
|
-
runMode:
|
|
17886
|
-
|
|
17887
|
-
RunMode.default("standalone")
|
|
17888
|
-
),
|
|
17769
|
+
runMode: RunMode.default("standalone"),
|
|
17770
|
+
// Present only while attached; a detach clears it. Its presence is what makes
|
|
17771
|
+
// `runMode: 'attached'` mean anything — see isAttached.
|
|
17772
|
+
controlPlane: ControlPlaneConnection.optional(),
|
|
17889
17773
|
policy: SimpleDetectionPolicy.default("redact"),
|
|
17890
17774
|
// Consent for scanning pre-install surfaces; opt-in (see HistoricalAccess).
|
|
17891
17775
|
historicalAccess: HistoricalAccess.default("session-only"),
|
|
@@ -17987,39 +17871,244 @@ function toInspectionFindingRow(input) {
|
|
|
17987
17871
|
firstDetectedAt: input.firstDetectedAt ? isoToEpochMillis(input.firstDetectedAt) : null
|
|
17988
17872
|
};
|
|
17989
17873
|
}
|
|
17990
|
-
function toCaptureAttributes(event) {
|
|
17991
|
-
const metadata = event.metadata;
|
|
17992
|
-
return {
|
|
17993
|
-
source_tool: event.sourceTool,
|
|
17994
|
-
...metadata?.repo !== void 0 ? { repo: metadata.repo } : {},
|
|
17995
|
-
...metadata?.filePath !== void 0 ? { file_path: metadata.filePath } : {},
|
|
17996
|
-
...metadata?.toolName !== void 0 ? { tool_name: metadata.toolName } : {},
|
|
17997
|
-
...metadata?.gitignored !== void 0 ? { gitignored: metadata.gitignored } : {},
|
|
17998
|
-
...metadata?.wholeFile !== void 0 ? { whole_file: metadata.wholeFile } : {},
|
|
17999
|
-
...metadata?.correlationId !== void 0 ? { correlation_id: metadata.correlationId } : {},
|
|
18000
|
-
...metadata?.traceId !== void 0 ? { trace_id: metadata.traceId } : {},
|
|
18001
|
-
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
18002
|
-
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
18003
|
-
// has ever populated either), but every legacy metadata key still rides
|
|
18004
|
-
// the bag rather than being silently dropped — CaptureAttributes'
|
|
18005
|
-
// `.catchall(z.unknown())` carries the long tail.
|
|
18006
|
-
...metadata?.model !== void 0 ? { model: metadata.model } : {},
|
|
18007
|
-
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {}
|
|
18008
|
-
};
|
|
17874
|
+
function toCaptureAttributes(event) {
|
|
17875
|
+
const metadata = event.metadata;
|
|
17876
|
+
return {
|
|
17877
|
+
source_tool: event.sourceTool,
|
|
17878
|
+
...metadata?.repo !== void 0 ? { repo: metadata.repo } : {},
|
|
17879
|
+
...metadata?.filePath !== void 0 ? { file_path: metadata.filePath } : {},
|
|
17880
|
+
...metadata?.toolName !== void 0 ? { tool_name: metadata.toolName } : {},
|
|
17881
|
+
...metadata?.gitignored !== void 0 ? { gitignored: metadata.gitignored } : {},
|
|
17882
|
+
...metadata?.wholeFile !== void 0 ? { whole_file: metadata.wholeFile } : {},
|
|
17883
|
+
...metadata?.correlationId !== void 0 ? { correlation_id: metadata.correlationId } : {},
|
|
17884
|
+
...metadata?.traceId !== void 0 ? { trace_id: metadata.traceId } : {},
|
|
17885
|
+
...metadata?.exceptionIds !== void 0 ? { exception_ids: metadata.exceptionIds } : {},
|
|
17886
|
+
// `model`/`turnIndex` have no dedicated CaptureAttributes field (no writer
|
|
17887
|
+
// has ever populated either), but every legacy metadata key still rides
|
|
17888
|
+
// the bag rather than being silently dropped — CaptureAttributes'
|
|
17889
|
+
// `.catchall(z.unknown())` carries the long tail.
|
|
17890
|
+
...metadata?.model !== void 0 ? { model: metadata.model } : {},
|
|
17891
|
+
...metadata?.turnIndex !== void 0 ? { turn_index: metadata.turnIndex } : {}
|
|
17892
|
+
};
|
|
17893
|
+
}
|
|
17894
|
+
function captureDefinitionVersion(finding) {
|
|
17895
|
+
return `capture/${finding.category}/${finding.severity}`;
|
|
17896
|
+
}
|
|
17897
|
+
function toCaptureDefinitionInput(finding) {
|
|
17898
|
+
return {
|
|
17899
|
+
ruleId: finding.ruleId,
|
|
17900
|
+
version: captureDefinitionVersion(finding),
|
|
17901
|
+
name: finding.ruleId,
|
|
17902
|
+
category: finding.category,
|
|
17903
|
+
severity: finding.severity,
|
|
17904
|
+
definition: JSON.stringify({ ruleId: finding.ruleId })
|
|
17905
|
+
};
|
|
17906
|
+
}
|
|
17907
|
+
|
|
17908
|
+
// ../../packages/schema/src/zod/managed.ts
|
|
17909
|
+
var MANAGED_SETTINGS_FILENAME = "managed-settings.json";
|
|
17910
|
+
var MANAGED_SETTINGS_SPEC_VERSION = 1;
|
|
17911
|
+
var ManagedSettingKey = external_exports.enum([
|
|
17912
|
+
"runMode",
|
|
17913
|
+
"historicalAccess",
|
|
17914
|
+
"vaultConsent",
|
|
17915
|
+
"vaultKeyCustody",
|
|
17916
|
+
"vaultInlineReveal",
|
|
17917
|
+
"modelJudgeConsent",
|
|
17918
|
+
"dataSharesInPlace"
|
|
17919
|
+
]).meta({ id: "ManagedSettingKey" });
|
|
17920
|
+
var ManagedSettingsValues = external_exports.object({
|
|
17921
|
+
runMode: external_exports.enum(["standalone", "attached"]).optional(),
|
|
17922
|
+
controlPlane: external_exports.object({
|
|
17923
|
+
endpoint: external_exports.string().min(1),
|
|
17924
|
+
label: external_exports.string().min(1).optional()
|
|
17925
|
+
}).optional(),
|
|
17926
|
+
historicalAccess: external_exports.enum(["full", "session-only"]).optional(),
|
|
17927
|
+
vaultConsent: external_exports.boolean().optional(),
|
|
17928
|
+
vaultKeyCustody: external_exports.enum(["file", "keychain"]).optional(),
|
|
17929
|
+
vaultInlineReveal: external_exports.enum(["masked", "full", "off"]).optional(),
|
|
17930
|
+
modelJudgeConsent: external_exports.boolean().optional(),
|
|
17931
|
+
dataSharesInPlace: external_exports.boolean().optional()
|
|
17932
|
+
}).meta({ id: "ManagedSettingsValues" });
|
|
17933
|
+
var ManagedSettings = external_exports.object({
|
|
17934
|
+
specVersion: external_exports.number().int().positive().default(MANAGED_SETTINGS_SPEC_VERSION),
|
|
17935
|
+
// Shown on every locked control, so the user can tell an administrative
|
|
17936
|
+
// decision from a bug. Absent renders as a generic "your organization".
|
|
17937
|
+
organization: external_exports.string().min(1).optional(),
|
|
17938
|
+
// What the administrator pinned.
|
|
17939
|
+
values: ManagedSettingsValues.default({}),
|
|
17940
|
+
// Which of those the user may not change. A key here with no matching value
|
|
17941
|
+
// freezes whatever the user last chose; a value with no lock is a DEFAULT
|
|
17942
|
+
// the user may still override. The two are separable on purpose.
|
|
17943
|
+
lockedFields: external_exports.array(ManagedSettingKey).default([])
|
|
17944
|
+
}).meta({ id: "ManagedSettings" });
|
|
17945
|
+
|
|
17946
|
+
// ../../packages/schema/src/zod/policy.ts
|
|
17947
|
+
var PolicyScope = external_exports.enum(["global", "repo", "user"]).meta({ id: "PolicyScope" });
|
|
17948
|
+
var PolicyTarget = external_exports.union([external_exports.object({ ruleId: external_exports.string() }), external_exports.object({ category: DetectionCategory })]).meta({ id: "PolicyTarget" });
|
|
17949
|
+
var Policy = external_exports.object({
|
|
17950
|
+
id: external_exports.guid(),
|
|
17951
|
+
scope: PolicyScope,
|
|
17952
|
+
target: PolicyTarget,
|
|
17953
|
+
action: ActionTaken,
|
|
17954
|
+
enabled: external_exports.boolean().default(true),
|
|
17955
|
+
customKeywords: external_exports.array(external_exports.string()).optional(),
|
|
17956
|
+
// Display name — optional so older policy rows without name still parse.
|
|
17957
|
+
// Added for the findings API (policy.name column migration).
|
|
17958
|
+
name: external_exports.string().optional()
|
|
17959
|
+
}).meta({ id: "Policy" });
|
|
17960
|
+
var PolicyBundle = external_exports.object({
|
|
17961
|
+
version: external_exports.string(),
|
|
17962
|
+
policies: external_exports.array(Policy),
|
|
17963
|
+
// Rules from the installed marketplace packs (snapshotted by the
|
|
17964
|
+
// control plane). The plugin registers these in addition to its bundled
|
|
17965
|
+
// packs. Optional so older backends — and older on-disk caches — that omit
|
|
17966
|
+
// the field still parse; consumers read `bundle.rules ?? []`.
|
|
17967
|
+
rules: external_exports.array(Rule).optional(),
|
|
17968
|
+
// When true, `rules` IS the complete effective ruleset and the runtime must
|
|
17969
|
+
// NOT merge its compiled-in bundled packs — the standalone gateway sets this
|
|
17970
|
+
// after reading the user's installed snapshot (installed_packs, enabled
|
|
17971
|
+
// packs only), which is how detection updates stay manual: new bundled
|
|
17972
|
+
// rules run only after the user applies the pack update. Absent/false keeps
|
|
17973
|
+
// the historical composition (bundled packs + rules) — older caches.
|
|
17974
|
+
rulesComplete: external_exports.boolean().optional(),
|
|
17975
|
+
// Active detection exceptions, evaluation subset only (see
|
|
17976
|
+
// ExceptionBundleEntry). Optional so older bundle producers — and older
|
|
17977
|
+
// on-disk caches — that omit the field still parse; consumers read
|
|
17978
|
+
// `bundle.exceptions ?? []`.
|
|
17979
|
+
exceptions: external_exports.array(ExceptionBundleEntry).optional(),
|
|
17980
|
+
// Rule ids whose pack is assigned a REVERSIBLE archetype (Redact & Vault).
|
|
17981
|
+
// A second axis over the same `redact` action, carried beside the policies
|
|
17982
|
+
// rather than on them: nothing writes ruleId-targeted policies to disk, so
|
|
17983
|
+
// widening Policy itself would change a persisted shape to express something
|
|
17984
|
+
// only the in-memory bundle needs. Optional so an older producer — or an
|
|
17985
|
+
// older on-disk cache — still parses; consumers read `?? []` and get the
|
|
17986
|
+
// pre-existing one-way behaviour, which is the safe direction to default.
|
|
17987
|
+
reversibleRuleIds: external_exports.array(external_exports.string()).optional(),
|
|
17988
|
+
// Installed pack version, keyed by ruleId, for rules in `rules` that came
|
|
17989
|
+
// from a versioned installed pack. Optional so older backends — and older
|
|
17990
|
+
// on-disk caches — that omit the field still parse; consumers fall back to
|
|
17991
|
+
// the rule's own spec version. NOT the bundle version above — see
|
|
17992
|
+
// installedRuleset's ruleVersions for the source of truth.
|
|
17993
|
+
ruleVersions: external_exports.record(external_exports.string(), external_exports.string()).optional(),
|
|
17994
|
+
customKeywords: external_exports.array(external_exports.string()),
|
|
17995
|
+
fetchedAt: external_exports.iso.datetime()
|
|
17996
|
+
}).meta({ id: "PolicyBundle" });
|
|
17997
|
+
var OBSERVE_ONLY_CATEGORIES = ["config"];
|
|
17998
|
+
var ENFORCEABLE_CATEGORIES = DetectionCategory.options.filter((c) => !OBSERVE_ONLY_CATEGORIES.includes(c));
|
|
17999
|
+
var CATEGORY_PEAK_SEVERITY = {
|
|
18000
|
+
secret: "critical",
|
|
18001
|
+
financial: "critical",
|
|
18002
|
+
// core-financial/credit-card
|
|
18003
|
+
code_flaw: "critical",
|
|
18004
|
+
pii: "high",
|
|
18005
|
+
phi: "high",
|
|
18006
|
+
custom: "high",
|
|
18007
|
+
// user-defined; conservative
|
|
18008
|
+
code_context: "low",
|
|
18009
|
+
config: "low"
|
|
18010
|
+
// observe-only; floors to monitor regardless
|
|
18011
|
+
};
|
|
18012
|
+
function severityFloorPolicy(category) {
|
|
18013
|
+
if (OBSERVE_ONLY_CATEGORIES.includes(category)) return "monitor";
|
|
18014
|
+
const peak = CATEGORY_PEAK_SEVERITY[category];
|
|
18015
|
+
return peak === "critical" || peak === "high" ? "warn" : "monitor";
|
|
18016
|
+
}
|
|
18017
|
+
var PolicyKind = external_exports.enum(["builtin", "custom"]).meta({ id: "PolicyKind" });
|
|
18018
|
+
var KNOWN_BUILTIN_IDS = ["monitor", "warn", "redact", "vault", "block"];
|
|
18019
|
+
var BuiltinPolicyId = external_exports.enum(KNOWN_BUILTIN_IDS).meta({ id: "BuiltinPolicyId" });
|
|
18020
|
+
var BUILTIN_ORDER = KNOWN_BUILTIN_IDS;
|
|
18021
|
+
var BUILTIN_POLICY_SPECS = {
|
|
18022
|
+
monitor: {
|
|
18023
|
+
name: "Monitor",
|
|
18024
|
+
action: "log",
|
|
18025
|
+
reversible: false,
|
|
18026
|
+
description: "Log every match for audit. The request is allowed through untouched."
|
|
18027
|
+
},
|
|
18028
|
+
warn: {
|
|
18029
|
+
name: "Warn",
|
|
18030
|
+
action: "warn",
|
|
18031
|
+
reversible: false,
|
|
18032
|
+
description: "Allow the request, but warn the user inline before it is sent."
|
|
18033
|
+
},
|
|
18034
|
+
redact: {
|
|
18035
|
+
name: "Redact",
|
|
18036
|
+
action: "redact",
|
|
18037
|
+
reversible: false,
|
|
18038
|
+
description: "Strip the matched value from the request and destroy it, then continue. What was removed cannot be recovered."
|
|
18039
|
+
},
|
|
18040
|
+
vault: {
|
|
18041
|
+
name: "Redact & Vault",
|
|
18042
|
+
action: "redact",
|
|
18043
|
+
reversible: true,
|
|
18044
|
+
description: "Strip the matched value from the request and keep an encrypted, recoverable copy in the local vault, leaving a pointer in its place. Needs the vault consent granted under Settings; without it this behaves as Redact."
|
|
18045
|
+
},
|
|
18046
|
+
block: {
|
|
18047
|
+
name: "Block",
|
|
18048
|
+
action: "block",
|
|
18049
|
+
reversible: false,
|
|
18050
|
+
description: "Refuse the request entirely whenever any rule in this detection matches."
|
|
18051
|
+
}
|
|
18052
|
+
};
|
|
18053
|
+
function builtinPolicyToAction(id) {
|
|
18054
|
+
return BUILTIN_POLICY_SPECS[id].action;
|
|
18055
|
+
}
|
|
18056
|
+
var CATEGORY_EXPRESSIBLE_IDS = KNOWN_BUILTIN_IDS.filter(
|
|
18057
|
+
(id) => !BUILTIN_POLICY_SPECS[id].reversible
|
|
18058
|
+
);
|
|
18059
|
+
var CATEGORY_INEXPRESSIBLE_IDS = KNOWN_BUILTIN_IDS.filter(
|
|
18060
|
+
(id) => BUILTIN_POLICY_SPECS[id].reversible
|
|
18061
|
+
);
|
|
18062
|
+
var CategoryPolicyId = external_exports.enum(CATEGORY_EXPRESSIBLE_IDS).meta({ id: "CategoryPolicyId" });
|
|
18063
|
+
function builtinPolicyIsReversible(id) {
|
|
18064
|
+
return BUILTIN_POLICY_SPECS[id].reversible;
|
|
18009
18065
|
}
|
|
18010
|
-
function
|
|
18011
|
-
|
|
18066
|
+
function policyIdIsReversible(policyId) {
|
|
18067
|
+
const parsed = BuiltinPolicyId.safeParse(policyId ?? DEFAULT_PACK_POLICY_ID);
|
|
18068
|
+
const id = parsed.success ? parsed.data : DEFAULT_PACK_POLICY_ID;
|
|
18069
|
+
return builtinPolicyIsReversible(id);
|
|
18012
18070
|
}
|
|
18013
|
-
|
|
18014
|
-
|
|
18015
|
-
|
|
18016
|
-
|
|
18017
|
-
|
|
18018
|
-
|
|
18019
|
-
|
|
18020
|
-
|
|
18021
|
-
|
|
18071
|
+
var DEFAULT_ACTIONS = Object.fromEntries(
|
|
18072
|
+
DetectionCategory.options.map((c) => [c, builtinPolicyToAction(severityFloorPolicy(c))])
|
|
18073
|
+
);
|
|
18074
|
+
var BUILTIN_POLICIES = Object.fromEntries(
|
|
18075
|
+
KNOWN_BUILTIN_IDS.map((id) => [id, { id, ...BUILTIN_POLICY_SPECS[id] }])
|
|
18076
|
+
);
|
|
18077
|
+
var DEFAULT_PACK_POLICY_ID = "monitor";
|
|
18078
|
+
function policyIdToAction(policyId) {
|
|
18079
|
+
const parsed = BuiltinPolicyId.safeParse(policyId ?? DEFAULT_PACK_POLICY_ID);
|
|
18080
|
+
const id = parsed.success ? parsed.data : DEFAULT_PACK_POLICY_ID;
|
|
18081
|
+
return BUILTIN_POLICIES[id].action;
|
|
18022
18082
|
}
|
|
18083
|
+
var UsedByItem = external_exports.object({
|
|
18084
|
+
id: external_exports.string(),
|
|
18085
|
+
name: external_exports.string(),
|
|
18086
|
+
ruleCount: external_exports.number().int().nonnegative(),
|
|
18087
|
+
enabled: external_exports.boolean()
|
|
18088
|
+
}).meta({ id: "UsedByItem" });
|
|
18089
|
+
var PolicyListItem = external_exports.object({
|
|
18090
|
+
id: external_exports.string(),
|
|
18091
|
+
kind: PolicyKind,
|
|
18092
|
+
name: external_exports.string(),
|
|
18093
|
+
enabled: external_exports.boolean(),
|
|
18094
|
+
usedByCount: external_exports.number().int().nonnegative()
|
|
18095
|
+
}).meta({ id: "PolicyListItem" });
|
|
18096
|
+
var ListPoliciesResponse = external_exports.object({ items: external_exports.array(PolicyListItem) }).meta({ id: "ListPoliciesResponse" });
|
|
18097
|
+
var PolicyDetail = external_exports.object({
|
|
18098
|
+
specVersion: external_exports.literal(1),
|
|
18099
|
+
id: external_exports.string(),
|
|
18100
|
+
kind: PolicyKind,
|
|
18101
|
+
name: external_exports.string(),
|
|
18102
|
+
enabled: external_exports.boolean(),
|
|
18103
|
+
description: external_exports.string(),
|
|
18104
|
+
usedBy: external_exports.array(UsedByItem)
|
|
18105
|
+
}).meta({ id: "PolicyDetail" });
|
|
18106
|
+
var PolicyStatsResponse = external_exports.object({
|
|
18107
|
+
policies: external_exports.number().int().nonnegative(),
|
|
18108
|
+
builtin: external_exports.number().int().nonnegative(),
|
|
18109
|
+
custom: external_exports.number().int().nonnegative(),
|
|
18110
|
+
detectionsGoverned: external_exports.number().int().nonnegative()
|
|
18111
|
+
}).meta({ id: "PolicyStatsResponse" });
|
|
18023
18112
|
|
|
18024
18113
|
// ../../packages/schema/src/zod/project-files.ts
|
|
18025
18114
|
var ProjectFileInput = external_exports.object({
|
|
@@ -18099,44 +18188,6 @@ var BatchedRemediation = external_exports.discriminatedUnion("kind", [
|
|
|
18099
18188
|
NoRemediationDecision
|
|
18100
18189
|
]);
|
|
18101
18190
|
|
|
18102
|
-
// ../../packages/schema/src/zod/rule-test.ts
|
|
18103
|
-
var TestRulesRequest = external_exports.object({
|
|
18104
|
-
rules: external_exports.array(Rule).min(1).max(100),
|
|
18105
|
-
text: external_exports.string().max(5e4).optional(),
|
|
18106
|
-
fixtures: external_exports.array(RuleFixture).max(200).optional()
|
|
18107
|
-
}).refine((v) => v.text !== void 0 || (v.fixtures?.length ?? 0) > 0, {
|
|
18108
|
-
message: "Provide `text`, `fixtures`, or both \u2014 there must be something to test"
|
|
18109
|
-
}).meta({ id: "TestRulesRequest" });
|
|
18110
|
-
var RuleTestMatch = external_exports.object({
|
|
18111
|
-
ruleId: external_exports.string(),
|
|
18112
|
-
category: DetectionCategory,
|
|
18113
|
-
severity: Severity,
|
|
18114
|
-
span: Span,
|
|
18115
|
-
confidence: external_exports.number().min(0).max(1),
|
|
18116
|
-
match: external_exports.string()
|
|
18117
|
-
}).meta({ id: "RuleTestMatch" });
|
|
18118
|
-
var FixtureResult = external_exports.object({
|
|
18119
|
-
label: external_exports.string(),
|
|
18120
|
-
shouldMatch: external_exports.boolean(),
|
|
18121
|
-
didMatch: external_exports.boolean(),
|
|
18122
|
-
passed: external_exports.boolean(),
|
|
18123
|
-
matches: external_exports.array(RuleTestMatch)
|
|
18124
|
-
}).meta({ id: "FixtureResult" });
|
|
18125
|
-
var TestRulesResponse = external_exports.object({
|
|
18126
|
-
// Present only when the request supplied `text`.
|
|
18127
|
-
adhoc: external_exports.object({ matches: external_exports.array(RuleTestMatch) }).optional(),
|
|
18128
|
-
fixtures: external_exports.array(FixtureResult),
|
|
18129
|
-
summary: external_exports.object({
|
|
18130
|
-
total: external_exports.number().int().nonnegative(),
|
|
18131
|
-
passed: external_exports.number().int().nonnegative(),
|
|
18132
|
-
failed: external_exports.number().int().nonnegative()
|
|
18133
|
-
}),
|
|
18134
|
-
// Ids of rules whose matcher type the engine cannot evaluate today (e.g.
|
|
18135
|
-
// `validator`), so they silently never match. Surfaced so an author is not
|
|
18136
|
-
// misled by a green run that actually skipped a rule.
|
|
18137
|
-
unsupportedRuleIds: external_exports.array(external_exports.string())
|
|
18138
|
-
}).meta({ id: "TestRulesResponse" });
|
|
18139
|
-
|
|
18140
18191
|
// ../../packages/schema/src/zod/security.ts
|
|
18141
18192
|
var SeveritySummaryItem = external_exports.object({
|
|
18142
18193
|
severity: Severity,
|
|
@@ -18234,10 +18285,22 @@ var TopSourcesQuery = external_exports.object({
|
|
|
18234
18285
|
// Omit for both kinds.
|
|
18235
18286
|
kind: external_exports.enum(SOURCE_KINDS).optional()
|
|
18236
18287
|
});
|
|
18237
|
-
var Provider =
|
|
18288
|
+
var Provider = Harness.extract([
|
|
18289
|
+
"ClaudeCode",
|
|
18290
|
+
"Cursor",
|
|
18291
|
+
"Codex",
|
|
18292
|
+
"Antigravity",
|
|
18293
|
+
"ClaudeAi",
|
|
18294
|
+
"ChatGpt",
|
|
18295
|
+
"Copilot",
|
|
18296
|
+
"Api"
|
|
18297
|
+
]).meta({ id: "Provider" });
|
|
18238
18298
|
var ScanCoverageProvider = external_exports.object({
|
|
18239
18299
|
provider: Provider,
|
|
18240
|
-
// Percent of that provider's traffic
|
|
18300
|
+
// Percent of that provider's traffic the shipped capture surface reaches.
|
|
18301
|
+
// A curated business fact, constant across every `range` — not a measured
|
|
18302
|
+
// per-window metric. 0 exactly when `supported` is false. See the comment
|
|
18303
|
+
// above the block for where these numbers are decided.
|
|
18241
18304
|
coverage: external_exports.number().int().min(0).max(100),
|
|
18242
18305
|
supported: external_exports.boolean()
|
|
18243
18306
|
}).meta({ id: "ScanCoverageProvider" });
|
|
@@ -18291,6 +18354,18 @@ var ApplyRecommendedActionResponse = external_exports.object({
|
|
|
18291
18354
|
var DismissRecommendedActionResponse = external_exports.object({ id: external_exports.string(), status: external_exports.literal("dismissed") }).meta({ id: "DismissRecommendedActionResponse" });
|
|
18292
18355
|
var RecommendedActionIdParam = external_exports.object({ id: external_exports.string() });
|
|
18293
18356
|
|
|
18357
|
+
// ../../packages/schema/src/zod/settings-action.ts
|
|
18358
|
+
var SaveSettingsInput = external_exports.object({
|
|
18359
|
+
historicalAccess: external_exports.string(),
|
|
18360
|
+
modelJudgeConsent: external_exports.boolean(),
|
|
18361
|
+
vaultConsent: external_exports.string(),
|
|
18362
|
+
vaultInlineReveal: external_exports.string()
|
|
18363
|
+
});
|
|
18364
|
+
var AttachInput = external_exports.object({
|
|
18365
|
+
endpoint: external_exports.string(),
|
|
18366
|
+
label: external_exports.string().optional()
|
|
18367
|
+
});
|
|
18368
|
+
|
|
18294
18369
|
// ../../packages/schema/src/zod/triage.ts
|
|
18295
18370
|
var TriageHit = external_exports.object({
|
|
18296
18371
|
ruleId: external_exports.string(),
|
|
@@ -18305,7 +18380,7 @@ var TriageHit = external_exports.object({
|
|
|
18305
18380
|
valueFingerprint: external_exports.string().optional(),
|
|
18306
18381
|
keyVersion: external_exports.number().int().nonnegative().optional()
|
|
18307
18382
|
});
|
|
18308
|
-
var TriagePolicy =
|
|
18383
|
+
var TriagePolicy = CategoryPolicyId;
|
|
18309
18384
|
var TriageCategoryRec = external_exports.object({
|
|
18310
18385
|
category: DetectionCategory,
|
|
18311
18386
|
action: TriagePolicy,
|
|
@@ -18523,8 +18598,11 @@ function chmodBestEffort(path, mode) {
|
|
|
18523
18598
|
function tightenDir(dir) {
|
|
18524
18599
|
chmodBestEffort(dir, DATA_DIR_MODE);
|
|
18525
18600
|
}
|
|
18601
|
+
function mkdirOwnerOnlySync(dir, recursive = false) {
|
|
18602
|
+
mkdirSync(dir, { recursive, mode: DATA_DIR_MODE });
|
|
18603
|
+
}
|
|
18526
18604
|
function ensureDataDirSync(dir) {
|
|
18527
|
-
|
|
18605
|
+
mkdirOwnerOnlySync(dir, true);
|
|
18528
18606
|
tightenDir(dir);
|
|
18529
18607
|
}
|
|
18530
18608
|
function dbSidecars(file2) {
|
|
@@ -18536,6 +18614,26 @@ function tightenFile(file2) {
|
|
|
18536
18614
|
function tightenPerms(file2) {
|
|
18537
18615
|
for (const path of [file2, ...dbSidecars(file2)]) chmodBestEffort(path, DATA_FILE_MODE);
|
|
18538
18616
|
}
|
|
18617
|
+
function writeExclusiveOwnerOnlySync(file2, data) {
|
|
18618
|
+
writeFileSync(file2, data, { mode: DATA_FILE_MODE, flag: "wx" });
|
|
18619
|
+
}
|
|
18620
|
+
function writeOwnerOnlyFileSync(file2, data) {
|
|
18621
|
+
const tmp = `${file2}.${String(process.pid)}.tmp`;
|
|
18622
|
+
try {
|
|
18623
|
+
rmSync(tmp, { force: true });
|
|
18624
|
+
} catch {
|
|
18625
|
+
}
|
|
18626
|
+
try {
|
|
18627
|
+
writeExclusiveOwnerOnlySync(tmp, data);
|
|
18628
|
+
renameSync(tmp, file2);
|
|
18629
|
+
} finally {
|
|
18630
|
+
try {
|
|
18631
|
+
rmSync(tmp, { force: true });
|
|
18632
|
+
} catch {
|
|
18633
|
+
}
|
|
18634
|
+
}
|
|
18635
|
+
tightenFile(file2);
|
|
18636
|
+
}
|
|
18539
18637
|
function classifyOccupant(file2) {
|
|
18540
18638
|
try {
|
|
18541
18639
|
if (lstatSync(file2).isSymbolicLink()) return { kind: "symlink" };
|
|
@@ -18564,7 +18662,7 @@ function createOwnerOnlyFileSync(file2, data) {
|
|
|
18564
18662
|
}
|
|
18565
18663
|
let created;
|
|
18566
18664
|
try {
|
|
18567
|
-
|
|
18665
|
+
writeExclusiveOwnerOnlySync(tmp, data);
|
|
18568
18666
|
created = publishByLink(tmp, file2, data);
|
|
18569
18667
|
} finally {
|
|
18570
18668
|
try {
|
|
@@ -18586,7 +18684,7 @@ function publishByLink(tmp, file2, data) {
|
|
|
18586
18684
|
if (!LINK_UNSUPPORTED.has(code ?? "")) throw err;
|
|
18587
18685
|
}
|
|
18588
18686
|
try {
|
|
18589
|
-
|
|
18687
|
+
writeExclusiveOwnerOnlySync(file2, data);
|
|
18590
18688
|
return true;
|
|
18591
18689
|
} catch (err) {
|
|
18592
18690
|
if (err.code === "EEXIST") return false;
|
|
@@ -18599,6 +18697,25 @@ function backupPath(file2, tag) {
|
|
|
18599
18697
|
return `${file2}.${tag}.${String(Date.now())}.${randomUUID().slice(0, 8)}.bak`;
|
|
18600
18698
|
}
|
|
18601
18699
|
var STALE_PARTIAL_MS = 5 * 6e4;
|
|
18700
|
+
var SNAPSHOT_STAGING_SUFFIX = ".partial";
|
|
18701
|
+
var STAGED_NAME_SUFFIX = `.bak${SNAPSHOT_STAGING_SUFFIX}`;
|
|
18702
|
+
var SNAPSHOT_STAGING_COPY = "copy";
|
|
18703
|
+
function createSnapshotStaging(backup) {
|
|
18704
|
+
const stage = `${backup}${SNAPSHOT_STAGING_SUFFIX}`;
|
|
18705
|
+
rmSync2(stage, { recursive: true, force: true });
|
|
18706
|
+
mkdirOwnerOnlySync(stage);
|
|
18707
|
+
tightenDir(stage);
|
|
18708
|
+
return { stage, copy: join(stage, SNAPSHOT_STAGING_COPY) };
|
|
18709
|
+
}
|
|
18710
|
+
function idleMs(entry) {
|
|
18711
|
+
for (const candidate of [join(entry, SNAPSHOT_STAGING_COPY), entry]) {
|
|
18712
|
+
try {
|
|
18713
|
+
return Date.now() - statSync(candidate).mtimeMs;
|
|
18714
|
+
} catch {
|
|
18715
|
+
}
|
|
18716
|
+
}
|
|
18717
|
+
return null;
|
|
18718
|
+
}
|
|
18602
18719
|
function reapStalePartials(file2) {
|
|
18603
18720
|
const dir = dirname(file2);
|
|
18604
18721
|
const prefix = `${basename(file2)}.`;
|
|
@@ -18609,30 +18726,34 @@ function reapStalePartials(file2) {
|
|
|
18609
18726
|
return;
|
|
18610
18727
|
}
|
|
18611
18728
|
for (const name of entries) {
|
|
18612
|
-
if (!name.startsWith(prefix) || !name.endsWith(
|
|
18613
|
-
const
|
|
18729
|
+
if (!name.startsWith(prefix) || !name.endsWith(STAGED_NAME_SUFFIX)) continue;
|
|
18730
|
+
const staging = join(dir, name);
|
|
18614
18731
|
try {
|
|
18615
|
-
|
|
18616
|
-
|
|
18732
|
+
const idle = idleMs(staging);
|
|
18733
|
+
if (idle !== null && idle > STALE_PARTIAL_MS) {
|
|
18734
|
+
rmSync2(staging, { recursive: true, force: true });
|
|
18617
18735
|
}
|
|
18618
18736
|
} catch {
|
|
18619
18737
|
}
|
|
18620
18738
|
}
|
|
18621
18739
|
}
|
|
18622
18740
|
function snapshotStore(db, backup) {
|
|
18623
|
-
const
|
|
18741
|
+
const { stage, copy } = createSnapshotStaging(backup);
|
|
18624
18742
|
try {
|
|
18625
|
-
|
|
18626
|
-
|
|
18627
|
-
|
|
18628
|
-
renameSync2(partial2, backup);
|
|
18743
|
+
db.prepare("VACUUM INTO ?").run(copy);
|
|
18744
|
+
tightenFile(copy);
|
|
18745
|
+
renameSync2(copy, backup);
|
|
18629
18746
|
} catch (error51) {
|
|
18630
18747
|
try {
|
|
18631
|
-
rmSync2(
|
|
18748
|
+
rmSync2(stage, { recursive: true, force: true });
|
|
18632
18749
|
} catch {
|
|
18633
18750
|
}
|
|
18634
18751
|
throw error51;
|
|
18635
18752
|
}
|
|
18753
|
+
try {
|
|
18754
|
+
rmSync2(stage, { recursive: true, force: true });
|
|
18755
|
+
} catch {
|
|
18756
|
+
}
|
|
18636
18757
|
}
|
|
18637
18758
|
function moveStoreAside(file2, backup) {
|
|
18638
18759
|
const undo = [];
|
|
@@ -19360,9 +19481,10 @@ function safeParseStringArray(raw) {
|
|
|
19360
19481
|
const parsed = safeJson(raw, null);
|
|
19361
19482
|
return Array.isArray(parsed) ? parsed : [];
|
|
19362
19483
|
}
|
|
19484
|
+
var DEFAULT_HARNESS = HARNESS.ClaudeCode;
|
|
19363
19485
|
function toHarness(raw) {
|
|
19364
19486
|
const parsed = Harness.safeParse(raw);
|
|
19365
|
-
return parsed.success ? parsed.data :
|
|
19487
|
+
return parsed.success ? parsed.data : DEFAULT_HARNESS;
|
|
19366
19488
|
}
|
|
19367
19489
|
function resolveLifecycle(row, lastActivityMs, nowMs) {
|
|
19368
19490
|
if (row.status) {
|
|
@@ -19493,7 +19615,7 @@ var SqliteActivityRepository = class {
|
|
|
19493
19615
|
const params = [];
|
|
19494
19616
|
if (query.harness && query.harness.length > 0) {
|
|
19495
19617
|
conditions.push(
|
|
19496
|
-
`coalesce(json_extract(attributes, '$.harness'), '
|
|
19618
|
+
`coalesce(json_extract(attributes, '$.harness'), '${DEFAULT_HARNESS}') IN (${placeholders(query.harness.length)})`
|
|
19497
19619
|
);
|
|
19498
19620
|
params.push(...query.harness);
|
|
19499
19621
|
}
|
|
@@ -19700,13 +19822,13 @@ var SqliteActivityRepository = class {
|
|
|
19700
19822
|
* The DISTINCT harnesses that actually have sessions (optionally within a
|
|
19701
19823
|
* `started_at >= fromMs` window), so the filter can offer only the harnesses
|
|
19702
19824
|
* present rather than the full enum. Each stored value is normalized through
|
|
19703
|
-
* the SAME `toHarness` default the list uses (missing →
|
|
19704
|
-
* store of bare (harness-less) roots surfaces exactly
|
|
19825
|
+
* the SAME `toHarness` default the list uses (missing → DEFAULT_HARNESS), so
|
|
19826
|
+
* a store of bare (harness-less) roots surfaces exactly that one harness.
|
|
19705
19827
|
*/
|
|
19706
19828
|
harnessFacets(fromMs) {
|
|
19707
19829
|
const where = fromMs === void 0 ? "" : " AND started_at >= ?";
|
|
19708
19830
|
const stmt = this.db.prepare(
|
|
19709
|
-
`SELECT DISTINCT coalesce(json_extract(attributes, '$.harness'), '
|
|
19831
|
+
`SELECT DISTINCT coalesce(json_extract(attributes, '$.harness'), '${DEFAULT_HARNESS}') AS harness
|
|
19710
19832
|
FROM audit_events WHERE ${SESSION_ROOT}${where}`
|
|
19711
19833
|
);
|
|
19712
19834
|
const rows = allRows(
|
|
@@ -19920,8 +20042,8 @@ var SqliteAuditEventsRepository = class {
|
|
|
19920
20042
|
}
|
|
19921
20043
|
// Insert one transcript-derived `llm_call` leaf. Unlike `insertAuditEvent`
|
|
19922
20044
|
// (which takes a caller-supplied random id), the id here is MINTED internally
|
|
19923
|
-
// from the natural key — `llmCallId(sessionId, messageId)` —
|
|
19924
|
-
//
|
|
20045
|
+
// from the natural key — `llmCallId(sessionId, messageId)` — derived from the
|
|
20046
|
+
// session and message alone, like the sibling local-store ids. The deterministic
|
|
19925
20047
|
// id + the UPSERT-take-MAX(output_tokens) statement make every re-read idempotent
|
|
19926
20048
|
// AND converge a streaming partial/final split across two incremental passes:
|
|
19927
20049
|
// a whole-file re-read no-ops (equal output), a lagging final replaces a
|
|
@@ -20886,6 +21008,42 @@ var SqliteFindingsRepository = class {
|
|
|
20886
21008
|
this.db = db;
|
|
20887
21009
|
}
|
|
20888
21010
|
db;
|
|
21011
|
+
/**
|
|
21012
|
+
* The newest `limit` findings, newest first.
|
|
21013
|
+
*
|
|
21014
|
+
* THE PLAN IS THE POINT HERE, and two things in the SQL below exist only to
|
|
21015
|
+
* pin it. The natural spelling — drive from `inspection_findings`, order by the
|
|
21016
|
+
* JOINED `e.started_at` — cannot push the LIMIT down, because the sort key is
|
|
21017
|
+
* not on the driving table: SQLite sorts every finding in the store through a
|
|
21018
|
+
* temp B-tree to return 500 rows. Measured at 35.0 ms on a 40,000-event corpus
|
|
21019
|
+
* against 0.9 ms for the form below, and the gap is a ratio of the store size
|
|
21020
|
+
* rather than a constant.
|
|
21021
|
+
*
|
|
21022
|
+
* What it takes to make `started_at` order come out of an index instead:
|
|
21023
|
+
*
|
|
21024
|
+
* - **`+e.event_type`** — the unary plus makes that term non-indexable, so the
|
|
21025
|
+
* planner stops choosing `idx_audit_type_t` (`event_type, started_at`). That
|
|
21026
|
+
* index cannot serve the ORDER BY: the predicate spans four event types, so
|
|
21027
|
+
* satisfying a global `started_at` order across them needs a range merge
|
|
21028
|
+
* SQLite will not do, and it sorts instead. Freed of it, the planner scans
|
|
21029
|
+
* `idx_audit_started_at` — a bare `started_at` index — in DESC order and
|
|
21030
|
+
* filters the type per row, which lets the LIMIT stop the scan early.
|
|
21031
|
+
* - **`CROSS JOIN`** — semantically identical to JOIN in SQLite, and there
|
|
21032
|
+
* purely to stop the tables being reordered. With plain JOINs the planner
|
|
21033
|
+
* drives from `f` and sorts everything again: measured at 23.6 ms, i.e. the
|
|
21034
|
+
* unary plus ALONE recovers almost none of the win. Both are needed.
|
|
21035
|
+
*
|
|
21036
|
+
* Neither is a micro-optimisation that a later reader should tidy away, and
|
|
21037
|
+
* `packages/persistence/test/performance/hot-read-query-plans.test.ts` fails if
|
|
21038
|
+
* the temp B-tree comes back.
|
|
21039
|
+
*
|
|
21040
|
+
* Degrading gracefully was the reason for `+` over `INDEXED BY`, which measured
|
|
21041
|
+
* identically (0.9 ms): `INDEXED BY` is a hard requirement, so dropping or
|
|
21042
|
+
* renaming the index turns this read into an ERROR, where `+` turns it into a
|
|
21043
|
+
* scan-and-sort — slower, still correct. The worst case for the chosen form is
|
|
21044
|
+
* a store whose recent captures carry no findings at all, where the scan walks
|
|
21045
|
+
* the whole index; that is still no worse than the full sort it replaced.
|
|
21046
|
+
*/
|
|
20889
21047
|
recentFindings(opts) {
|
|
20890
21048
|
const limit = opts?.limit ?? 50;
|
|
20891
21049
|
const rows = allRows(
|
|
@@ -20894,10 +21052,10 @@ var SqliteFindingsRepository = class {
|
|
|
20894
21052
|
f.masked_match, f.action_taken, f.confidence, e.started_at AS occurred_at,
|
|
20895
21053
|
json_extract(e.attributes, '$.source_tool') AS source_tool,
|
|
20896
21054
|
e.event_type AS kind
|
|
20897
|
-
FROM
|
|
20898
|
-
JOIN
|
|
20899
|
-
JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
20900
|
-
WHERE e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
21055
|
+
FROM audit_events e
|
|
21056
|
+
CROSS JOIN inspection_findings f ON f.audit_event_id = e.id
|
|
21057
|
+
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
21058
|
+
WHERE +e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
20901
21059
|
ORDER BY e.started_at DESC, f.rowid DESC
|
|
20902
21060
|
LIMIT :limit`
|
|
20903
21061
|
),
|
|
@@ -21541,7 +21699,8 @@ var SqliteInspectionDefinitionsRepository = class {
|
|
|
21541
21699
|
}
|
|
21542
21700
|
db;
|
|
21543
21701
|
insertStmt;
|
|
21544
|
-
//
|
|
21702
|
+
// Insert-if-absent; returns the content-addressed definition id. An id already
|
|
21703
|
+
// present keeps the stored row untouched — see the class doc.
|
|
21545
21704
|
upsert(input) {
|
|
21546
21705
|
const id = inspectionDefinitionId(input.ruleId, input.version);
|
|
21547
21706
|
const row = toInspectionDefinitionRow(input, id);
|
|
@@ -21685,11 +21844,23 @@ function isParseableBinaryVersion(version2) {
|
|
|
21685
21844
|
|
|
21686
21845
|
// ../../packages/persistence/src/repositories/installed-packs.ts
|
|
21687
21846
|
var DEFAULT_POLICY_ID = DEFAULT_PACK_POLICY_ID;
|
|
21847
|
+
function printableRuleId(entry) {
|
|
21848
|
+
if (typeof entry !== "object" || entry === null) return null;
|
|
21849
|
+
const candidate = entry.id;
|
|
21850
|
+
return Rule.shape.id.safeParse(candidate).success ? candidate : null;
|
|
21851
|
+
}
|
|
21852
|
+
function firstIssueReason(error51) {
|
|
21853
|
+
const issue2 = error51.issues[0];
|
|
21854
|
+
if (!issue2) return "unknown";
|
|
21855
|
+
const path = issue2.path.map((segment) => String(segment)).join(".");
|
|
21856
|
+
return path ? `${path}: ${issue2.code}` : issue2.code;
|
|
21857
|
+
}
|
|
21858
|
+
var REJECTED_RULE_DETAIL_CAP = 10;
|
|
21688
21859
|
function inventorySignature(packs2) {
|
|
21689
21860
|
return packs2.map((p) => `${p.namespace}/${p.packId}@${p.version}#${hashRules(p.rulesJson)}`).sort().join(",");
|
|
21690
21861
|
}
|
|
21691
21862
|
function hashRules(rulesJson) {
|
|
21692
|
-
return createHash2("
|
|
21863
|
+
return createHash2("sha256").update(rulesJson).digest("hex");
|
|
21693
21864
|
}
|
|
21694
21865
|
function parseVersion(v) {
|
|
21695
21866
|
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(v);
|
|
@@ -21901,10 +22072,21 @@ var SqliteInstalledPacksRepository = class {
|
|
|
21901
22072
|
* (all detection off) instead of falling back to the bundled packs. Every
|
|
21902
22073
|
* JSON-level failure therefore counts as invalid.
|
|
21903
22074
|
*/
|
|
22075
|
+
/**
|
|
22076
|
+
* ORDERED, because a rule id is unique only WITHIN a pack — the sole unique
|
|
22077
|
+
* index is (namespace, pack_id) — so two enabled packs may contribute the same
|
|
22078
|
+
* id, and the per-rule maps below are last-write-wins. Without an ORDER BY the
|
|
22079
|
+
* winner is whatever order SQLite happens to return, which makes a collision
|
|
22080
|
+
* resolve differently on two machines holding identical stores. Ordering by
|
|
22081
|
+
* (namespace, pack_id) makes the loser deterministic and therefore testable.
|
|
22082
|
+
*/
|
|
21904
22083
|
installedRuleset() {
|
|
21905
22084
|
const rows = allRows(
|
|
21906
22085
|
this.db.prepare(
|
|
21907
|
-
`SELECT enabled, policy_id AS policyId, rules_json AS rulesJson, version
|
|
22086
|
+
`SELECT enabled, policy_id AS policyId, rules_json AS rulesJson, version,
|
|
22087
|
+
namespace, pack_id AS packId
|
|
22088
|
+
FROM installed_packs
|
|
22089
|
+
ORDER BY namespace, pack_id`
|
|
21908
22090
|
)
|
|
21909
22091
|
);
|
|
21910
22092
|
const out = {
|
|
@@ -21912,22 +22094,32 @@ var SqliteInstalledPacksRepository = class {
|
|
|
21912
22094
|
enabledPacks: 0,
|
|
21913
22095
|
rules: [],
|
|
21914
22096
|
invalidRules: 0,
|
|
22097
|
+
rejectedRules: [],
|
|
21915
22098
|
ruleActions: /* @__PURE__ */ new Map(),
|
|
21916
|
-
ruleVersions: /* @__PURE__ */ new Map()
|
|
22099
|
+
ruleVersions: /* @__PURE__ */ new Map(),
|
|
22100
|
+
reversibleRules: /* @__PURE__ */ new Set()
|
|
22101
|
+
};
|
|
22102
|
+
const reject = (pack, ruleId, reason) => {
|
|
22103
|
+
if (out.rejectedRules.length >= REJECTED_RULE_DETAIL_CAP) return;
|
|
22104
|
+
out.rejectedRules.push({ pack, ruleId, reason });
|
|
21917
22105
|
};
|
|
21918
22106
|
for (const row of rows) {
|
|
21919
22107
|
if (!intToBool(row.enabled)) continue;
|
|
21920
22108
|
out.enabledPacks += 1;
|
|
21921
22109
|
const action = policyIdToAction(row.policyId);
|
|
22110
|
+
const reversible = policyIdIsReversible(row.policyId);
|
|
22111
|
+
const pack = `${row.namespace}/${row.packId}`;
|
|
21922
22112
|
let raw;
|
|
21923
22113
|
try {
|
|
21924
22114
|
raw = JSON.parse(row.rulesJson);
|
|
21925
22115
|
} catch {
|
|
21926
22116
|
out.invalidRules += 1;
|
|
22117
|
+
reject(pack, null, "rules_json: malformed JSON");
|
|
21927
22118
|
continue;
|
|
21928
22119
|
}
|
|
21929
22120
|
if (!Array.isArray(raw)) {
|
|
21930
22121
|
out.invalidRules += 1;
|
|
22122
|
+
reject(pack, null, "rules_json: not an array");
|
|
21931
22123
|
continue;
|
|
21932
22124
|
}
|
|
21933
22125
|
for (const entry of raw) {
|
|
@@ -21936,7 +22128,12 @@ var SqliteInstalledPacksRepository = class {
|
|
|
21936
22128
|
out.rules.push(parsed.data);
|
|
21937
22129
|
out.ruleActions.set(parsed.data.id, action);
|
|
21938
22130
|
out.ruleVersions.set(parsed.data.id, row.version);
|
|
21939
|
-
|
|
22131
|
+
if (reversible) out.reversibleRules.add(parsed.data.id);
|
|
22132
|
+
else out.reversibleRules.delete(parsed.data.id);
|
|
22133
|
+
} else {
|
|
22134
|
+
out.invalidRules += 1;
|
|
22135
|
+
reject(pack, printableRuleId(entry), firstIssueReason(parsed.error));
|
|
22136
|
+
}
|
|
21940
22137
|
}
|
|
21941
22138
|
}
|
|
21942
22139
|
return out;
|
|
@@ -22130,31 +22327,38 @@ var CATEGORY_ORDER = ["config", "skill", "mcp", "hook"];
|
|
|
22130
22327
|
var VALID_HARNESS_IDS = new Set(HarnessId.options);
|
|
22131
22328
|
var WORKTREE_CHECKOUT_FILTER = "(url IS NULL OR (url NOT LIKE '%/.claude/worktrees/%' AND url NOT LIKE '%\\.claude\\worktrees\\%'))";
|
|
22132
22329
|
var HARNESS_LABELS = {
|
|
22133
|
-
|
|
22134
|
-
|
|
22135
|
-
|
|
22136
|
-
|
|
22330
|
+
[HARNESS.ClaudeCode]: "Claude Code",
|
|
22331
|
+
[HARNESS.Cursor]: "Cursor",
|
|
22332
|
+
[HARNESS.Codex]: "Codex",
|
|
22333
|
+
[HARNESS.Antigravity]: "Antigravity"
|
|
22137
22334
|
};
|
|
22138
22335
|
var HARNESS_LIVENESS_WINDOW_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
22139
22336
|
var EMPTY_PROJECT_AGG = {
|
|
22140
22337
|
accessCounts: { open: 0, approved: 0, blocked: 0, total: 0 },
|
|
22141
22338
|
findingsCount: 0
|
|
22142
22339
|
};
|
|
22340
|
+
var stripSeparators = (value) => value.toLowerCase().replace(/[\s-]/g, "");
|
|
22341
|
+
var TITLE_NEEDLES = {
|
|
22342
|
+
ClaudeCode: stripSeparators(SOURCE_TOOL.ClaudeCode),
|
|
22343
|
+
Cursor: stripSeparators(SOURCE_TOOL.Cursor),
|
|
22344
|
+
Codex: stripSeparators(SOURCE_TOOL.Codex),
|
|
22345
|
+
Antigravity: stripSeparators(SOURCE_TOOL.Antigravity)
|
|
22346
|
+
};
|
|
22143
22347
|
function resolveHarnessId(attrs, row) {
|
|
22144
22348
|
if (attrs.provider && VALID_HARNESS_IDS.has(attrs.provider)) {
|
|
22145
22349
|
return attrs.provider;
|
|
22146
22350
|
}
|
|
22147
|
-
const t = (row.title ?? "")
|
|
22148
|
-
if (t.includes(
|
|
22149
|
-
if (t.includes(
|
|
22150
|
-
if (t.includes(
|
|
22151
|
-
if (t.includes(
|
|
22351
|
+
const t = stripSeparators(row.title ?? "");
|
|
22352
|
+
if (t.includes(TITLE_NEEDLES.ClaudeCode) || t === "claude") return HARNESS.ClaudeCode;
|
|
22353
|
+
if (t.includes(TITLE_NEEDLES.Cursor)) return HARNESS.Cursor;
|
|
22354
|
+
if (t.includes(TITLE_NEEDLES.Codex)) return HARNESS.Codex;
|
|
22355
|
+
if (t.includes(TITLE_NEEDLES.Antigravity)) return HARNESS.Antigravity;
|
|
22152
22356
|
return null;
|
|
22153
22357
|
}
|
|
22154
22358
|
function isLiveRealClaudeCode(rows) {
|
|
22155
22359
|
return rows.some((r) => {
|
|
22156
22360
|
const attrs = safeJson(r.attributes, {});
|
|
22157
|
-
return attrs.provenance !== "sample" && resolveHarnessId(attrs, r) ===
|
|
22361
|
+
return attrs.provenance !== "sample" && resolveHarnessId(attrs, r) === HARNESS.ClaudeCode;
|
|
22158
22362
|
});
|
|
22159
22363
|
}
|
|
22160
22364
|
function toAssetSummary(row) {
|
|
@@ -22422,7 +22626,7 @@ var SqliteInventoryAssetsRepository = class {
|
|
|
22422
22626
|
const isRealHarness = rows.some(
|
|
22423
22627
|
(r) => safeJson(r.attributes, {}).provenance !== "sample"
|
|
22424
22628
|
);
|
|
22425
|
-
const attachConfig = isRealHarness && harnessId ===
|
|
22629
|
+
const attachConfig = isRealHarness && harnessId === HARNESS.ClaudeCode && configAssets.length > 0;
|
|
22426
22630
|
const assets = attachConfig ? [...harnessAssets, ...configAssets].sort((a, b) => a.name.localeCompare(b.name)) : harnessAssets;
|
|
22427
22631
|
if (q && assets.length === 0) continue;
|
|
22428
22632
|
const firstRow = rows[0];
|
|
@@ -23096,9 +23300,10 @@ var SqliteProjectFilesRepository = class {
|
|
|
23096
23300
|
// ../../packages/persistence/src/repositories/resolutions.ts
|
|
23097
23301
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
23098
23302
|
var SqliteResolutionsRepository = class {
|
|
23099
|
-
constructor(db, now = () => Date.now()) {
|
|
23303
|
+
constructor(db, now = () => Date.now(), newId = () => randomUUID7()) {
|
|
23100
23304
|
this.db = db;
|
|
23101
23305
|
this.now = now;
|
|
23306
|
+
this.newId = newId;
|
|
23102
23307
|
this.insertStmt = db.prepare(
|
|
23103
23308
|
`INSERT INTO finding_resolution (id, finding_key, status, method, resolved_at, evidence, created_at)
|
|
23104
23309
|
VALUES (:id, :findingKey, :status, :method, :resolvedAt, :evidence, :createdAt)`
|
|
@@ -23131,12 +23336,14 @@ var SqliteResolutionsRepository = class {
|
|
|
23131
23336
|
}
|
|
23132
23337
|
db;
|
|
23133
23338
|
now;
|
|
23339
|
+
newId;
|
|
23134
23340
|
insertStmt;
|
|
23135
23341
|
latestStmt;
|
|
23136
23342
|
openAtRestStmt;
|
|
23137
23343
|
resolvedAtRestStmt;
|
|
23138
23344
|
/**
|
|
23139
|
-
* Insert one disposition row. The repo mints the id and stamps created_at
|
|
23345
|
+
* Insert one disposition row. The repo mints the id and stamps created_at,
|
|
23346
|
+
* both through the constructor's injectable seams.
|
|
23140
23347
|
* `status`/`method` are typed AND re-parsed here against @akasecurity/schema's
|
|
23141
23348
|
* FindingStatus/ResolutionMethod, so the persisted vocabulary can never drift
|
|
23142
23349
|
* from the schema enums. NOTE for future manual-resolution writers: this is
|
|
@@ -23148,7 +23355,7 @@ var SqliteResolutionsRepository = class {
|
|
|
23148
23355
|
*/
|
|
23149
23356
|
insertResolution(r) {
|
|
23150
23357
|
this.insertStmt.run({
|
|
23151
|
-
id:
|
|
23358
|
+
id: this.newId(),
|
|
23152
23359
|
findingKey: r.findingKey,
|
|
23153
23360
|
status: FindingStatus.parse(r.status),
|
|
23154
23361
|
method: ResolutionMethod.parse(r.method),
|
|
@@ -23727,16 +23934,16 @@ var ACTION_TO_KIND = {
|
|
|
23727
23934
|
warn: "warned"
|
|
23728
23935
|
};
|
|
23729
23936
|
var ENFORCEMENT_KINDS = ["blocked", "redacted", "warned"];
|
|
23730
|
-
var SCAN_COVERAGE =
|
|
23731
|
-
|
|
23732
|
-
|
|
23733
|
-
|
|
23734
|
-
|
|
23735
|
-
|
|
23736
|
-
|
|
23737
|
-
|
|
23738
|
-
|
|
23739
|
-
|
|
23937
|
+
var SCAN_COVERAGE = {
|
|
23938
|
+
[HARNESS.Antigravity]: { coverage: 60, supported: true },
|
|
23939
|
+
[HARNESS.Api]: { coverage: 0, supported: false },
|
|
23940
|
+
[HARNESS.ChatGpt]: { coverage: 40, supported: true },
|
|
23941
|
+
[HARNESS.ClaudeAi]: { coverage: 40, supported: true },
|
|
23942
|
+
[HARNESS.ClaudeCode]: { coverage: 100, supported: true },
|
|
23943
|
+
[HARNESS.Codex]: { coverage: 80, supported: true },
|
|
23944
|
+
[HARNESS.Copilot]: { coverage: 0, supported: false },
|
|
23945
|
+
[HARNESS.Cursor]: { coverage: 0, supported: false }
|
|
23946
|
+
};
|
|
23740
23947
|
var GRANULARITY = {
|
|
23741
23948
|
"7d": "day",
|
|
23742
23949
|
"30d": "day",
|
|
@@ -23835,9 +24042,22 @@ var SqliteSecurityRepository = class {
|
|
|
23835
24042
|
return Promise.resolve({ total, needsRemediation, bySeverity });
|
|
23836
24043
|
}
|
|
23837
24044
|
// Range is echoed but does not change the result today — coverage is a constant
|
|
23838
|
-
// business fact (see SCAN_COVERAGE), not a measured per-window metric.
|
|
24045
|
+
// business fact (see SCAN_COVERAGE), not a measured per-window metric. Order
|
|
24046
|
+
// comes from Provider.options (the enum's declaration order), not from
|
|
24047
|
+
// SCAN_COVERAGE's own key order — deliberately, not because object literals
|
|
24048
|
+
// leave key order unspecified (ES2015 guarantees insertion order for these
|
|
24049
|
+
// non-integer string keys, so iterating SCAN_COVERAGE directly would be
|
|
24050
|
+
// reliable too). The reason is the schema comment's promise: the returned
|
|
24051
|
+
// order must mirror the generated OpenAPI enum list, which is Provider's
|
|
24052
|
+
// contract, not this table's.
|
|
23839
24053
|
scanCoverage(range) {
|
|
23840
|
-
return Promise.resolve({
|
|
24054
|
+
return Promise.resolve({
|
|
24055
|
+
range,
|
|
24056
|
+
providers: Provider.options.map((provider) => ({
|
|
24057
|
+
provider,
|
|
24058
|
+
...SCAN_COVERAGE[provider]
|
|
24059
|
+
}))
|
|
24060
|
+
});
|
|
23841
24061
|
}
|
|
23842
24062
|
enforcementActions(range) {
|
|
23843
24063
|
const lenMs = RANGE_DAYS[range] * DAY_MS4;
|
|
@@ -23895,10 +24115,10 @@ var SqliteSecurityRepository = class {
|
|
|
23895
24115
|
// count; a superseding open/redetected row means the finding is not
|
|
23896
24116
|
// remediated and is excluded, same invariant as severitySummary. Legacy
|
|
23897
24117
|
// at-rest findings with finding_key IS NULL can never have a resolution row
|
|
23898
|
-
// (the lifecycle is keyed by finding_key), so
|
|
23899
|
-
//
|
|
23900
|
-
//
|
|
23901
|
-
// mirroring this file's other methods.
|
|
24118
|
+
// (the lifecycle is keyed by finding_key), so they cannot reach the driving
|
|
24119
|
+
// set below. One raw-row query (fetch the findings with resolution activity in
|
|
24120
|
+
// the window + each one's latest resolution status/method/resolved_at) +
|
|
24121
|
+
// pure-JS filter/bucket/mean, mirroring this file's other methods.
|
|
23902
24122
|
mttrTrend(range) {
|
|
23903
24123
|
const granularity = granularityFor(range);
|
|
23904
24124
|
const bucketMs = (granularity === "day" ? 1 : 7) * DAY_MS4;
|
|
@@ -23914,29 +24134,80 @@ var SqliteSecurityRepository = class {
|
|
|
23914
24134
|
// started_at the upsert overwrites onto inspection_findings.audit_event_id.
|
|
23915
24135
|
// COALESCE onto the parent event's started_at defends against any
|
|
23916
24136
|
// legacy/edge row the backfill left null.
|
|
23917
|
-
`SELECT
|
|
24137
|
+
`SELECT DISTINCT f.finding_key AS finding_key,
|
|
24138
|
+
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at, d.severity AS severity,
|
|
23918
24139
|
latest.status AS latest_status,
|
|
23919
24140
|
latest.method AS latest_method,
|
|
23920
24141
|
latest.resolved_at AS latest_resolved_at
|
|
23921
|
-
FROM
|
|
23922
|
-
JOIN
|
|
23923
|
-
JOIN
|
|
24142
|
+
FROM finding_resolution fr
|
|
24143
|
+
CROSS JOIN inspection_findings f ON f.finding_key = fr.finding_key
|
|
24144
|
+
CROSS JOIN audit_events e ON e.id = f.audit_event_id
|
|
24145
|
+
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
23924
24146
|
LEFT JOIN ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
23925
24147
|
ON latest.finding_key = f.finding_key
|
|
23926
|
-
WHERE
|
|
23927
|
-
AND e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})
|
|
23928
|
-
|
|
23929
|
-
SELECT 1 FROM finding_resolution fr
|
|
23930
|
-
WHERE fr.finding_key = f.finding_key
|
|
23931
|
-
AND fr.resolved_at >= :windowStart
|
|
23932
|
-
)`
|
|
23933
|
-
// The EXISTS is a SUPERSET prefilter that bounds the scan to keys with
|
|
23934
|
-
// any resolution activity at/after the window start — a row this method
|
|
24148
|
+
WHERE fr.resolved_at >= :windowStart
|
|
24149
|
+
AND e.event_type IN (${CAPTURE_EVENT_TYPES_SQL})`
|
|
24150
|
+
// `fr` is a SUPERSET prefilter, not the answer: a finding this method
|
|
23935
24151
|
// ultimately counts has its LATEST resolution inside the window, which
|
|
23936
|
-
// implies
|
|
23937
|
-
// latest-wins + status/method + window gate
|
|
23938
|
-
// dialect-agnostic.
|
|
23939
|
-
//
|
|
24152
|
+
// implies a resolution row at/after the window start exists, so nothing
|
|
24153
|
+
// wanted is dropped. The exact latest-wins + status/method + window gate
|
|
24154
|
+
// stays in JS below, dialect-agnostic. `f.finding_key IS NOT NULL` is
|
|
24155
|
+
// implied rather than dropped — the join key comes from
|
|
24156
|
+
// finding_resolution, whose finding_key is NOT NULL.
|
|
24157
|
+
//
|
|
24158
|
+
// IT IS THE DRIVING TABLE THAT MAKES THAT PREFILTER A BOUND, which is
|
|
24159
|
+
// the correction this replaced. Spelled as an `EXISTS` in the WHERE it
|
|
24160
|
+
// READ as a bound and was not one: SQLite drove from `audit_events` on
|
|
24161
|
+
// event_type, joined every capture event to its findings, and evaluated
|
|
24162
|
+
// the EXISTS last — bounding the RESULT and not the scan, so a 7d request
|
|
24163
|
+
// still cost the store's whole trackable history. Measured at 44.6 ms on
|
|
24164
|
+
// 50,000 events and 171.3 ms on 150,000 — linear in the STORE, and in
|
|
24165
|
+
// both cases returning rows for a window holding a fraction of it.
|
|
24166
|
+
//
|
|
24167
|
+
// Two things carry it, and they answer DIFFERENT halves — which is worth
|
|
24168
|
+
// stating precisely, because the obvious reading (both are needed for the
|
|
24169
|
+
// speed) is wrong and was measured to be wrong:
|
|
24170
|
+
//
|
|
24171
|
+
// - **`CROSS JOIN`** is the whole of the store-size fix. In SQLite the
|
|
24172
|
+
// keyword is semantically identical to JOIN and exists only to stop the
|
|
24173
|
+
// tables being reordered; with plain JOINs the planner puts `e` back on
|
|
24174
|
+
// the outside, because with no ANALYZE statistics it prices
|
|
24175
|
+
// `event_type IN (...)` as a selective probe. Reverting it alone takes
|
|
24176
|
+
// the 2k->20k flatness ratio from 1.32 to 16.87.
|
|
24177
|
+
// - **`idx_finding_resolution_resolved_at`** (migration 0021) makes
|
|
24178
|
+
// `resolved_at >= :windowStart` a range SEARCH instead of a bare
|
|
24179
|
+
// `SCAN fr` — finding_key was this table's only index before it, so the
|
|
24180
|
+
// range had none. It buys NO flatness in store size: remove it and the
|
|
24181
|
+
// ratio above does not move, because the latest-resolution derived
|
|
24182
|
+
// table already passes over the whole of finding_resolution, so this
|
|
24183
|
+
// read is O(resolutions) either way and resolutions are not the store.
|
|
24184
|
+
// What it buys is the criterion `hot-read-query-plans.test.ts` enforces
|
|
24185
|
+
// — no hot read may pass over a table with no index — and that is the
|
|
24186
|
+
// guard that goes red when it is dropped. Neither test catches the
|
|
24187
|
+
// other's defect.
|
|
24188
|
+
//
|
|
24189
|
+
// SELECT DISTINCT is a CORRECTNESS requirement of driving from `fr`, not a
|
|
24190
|
+
// tidy-up. finding_resolution is append-only, so a key that was fixed,
|
|
24191
|
+
// redetected and fixed again carries several rows inside one window and
|
|
24192
|
+
// matches once per row — and the value below is a MEAN, so a key matched
|
|
24193
|
+
// three times is a key weighted three times.
|
|
24194
|
+
//
|
|
24195
|
+
// The skew is easy to argue away and the argument is wrong, so it is worth
|
|
24196
|
+
// recording. Duplicate rows for ONE key are identical (every projected
|
|
24197
|
+
// column is per-key: `latest.*` is latest-wins, `first_detected_at` is
|
|
24198
|
+
// preserved), so sums and counts scale together and that key's own mean
|
|
24199
|
+
// does not move. What moves is a bucket holding TWO findings that duplicate
|
|
24200
|
+
// UNEQUALLY: three rows for a 5.9-day fix and one for a 1.9-day fix average
|
|
24201
|
+
// 4.9 days weighted against 3.9 unweighted. Measured, and pinned by
|
|
24202
|
+
// `security.test.ts`'s "weights a finding ONCE however many resolution rows
|
|
24203
|
+
// it has inside the window" — which needed a fixture built for it, since no
|
|
24204
|
+
// single-key case can show it.
|
|
24205
|
+
//
|
|
24206
|
+
// `finding_key` is selected to make the DISTINCT dedup by KEY rather than
|
|
24207
|
+
// by value tuple. On the other columns alone, two genuinely different
|
|
24208
|
+
// findings sharing a severity, a first-detection event and a resolution
|
|
24209
|
+
// instant — one commit fixing two secrets in one file — are one tuple, and
|
|
24210
|
+
// collapsing them would under-count in the other direction.
|
|
23940
24211
|
),
|
|
23941
24212
|
{ windowStart }
|
|
23942
24213
|
);
|
|
@@ -23994,16 +24265,47 @@ var SqliteSecurityRepository = class {
|
|
|
23994
24265
|
}
|
|
23995
24266
|
// Recently-resolved activity feed: findings whose finding_key's LATEST
|
|
23996
24267
|
// finding_resolution row is status:'resolved'/method:'fixed-at-source' —
|
|
23997
|
-
// same latest-resolution-wins
|
|
23998
|
-
//
|
|
23999
|
-
//
|
|
24000
|
-
//
|
|
24001
|
-
//
|
|
24002
|
-
//
|
|
24003
|
-
//
|
|
24004
|
-
//
|
|
24005
|
-
//
|
|
24006
|
-
//
|
|
24268
|
+
// same latest-resolution-wins derived table as severitySummary / mttrTrend
|
|
24269
|
+
// (NOT a plain JOIN, which would surface every historical resolution row for
|
|
24270
|
+
// a key rather than just its current disposition). A key whose latest row is
|
|
24271
|
+
// a superseding 'open'/'redetected' row (the same secret came back) is
|
|
24272
|
+
// excluded — it is not currently resolved. Legacy at-rest findings with
|
|
24273
|
+
// finding_key IS NULL are excluded outright (the resolution lifecycle can
|
|
24274
|
+
// never attach to them). Path comes from the finding's parent event
|
|
24275
|
+
// (event_type 'code_change', attributes.file_path) — mirrors resolutions.ts's
|
|
24276
|
+
// openAtRestStmt accessor. Ordered by resolved_at DESC, capped at `limit`.
|
|
24277
|
+
//
|
|
24278
|
+
// THE RESOLUTION SET DRIVES THIS QUERY, and that is a correctness property of
|
|
24279
|
+
// the plan rather than a preference. Written the other way round — driving
|
|
24280
|
+
// from inspection_findings/audit_events with `latest` LEFT JOINed on — SQLite
|
|
24281
|
+
// cannot use the join key: `f` is reached FROM `latest` by finding_key, so
|
|
24282
|
+
// `latest` gets probed on (rn, status, method) instead and the plan enumerates
|
|
24283
|
+
// every (code_change event x resolved key) pair before `f` can reject it. That
|
|
24284
|
+
// is a cross product, and it is quadratic in the store: measured at 10,966 ms
|
|
24285
|
+
// on a corpus of 50,000 events carrying 2,051 resolutions, against 20 rows
|
|
24286
|
+
// returned. It was invisible for as long as it was, and reported at 8 ms,
|
|
24287
|
+
// because an empty finding_resolution table makes the inner side empty and the
|
|
24288
|
+
// cross product collapses to nothing — so the shape is only observable on a
|
|
24289
|
+
// corpus that seeds resolutions.
|
|
24290
|
+
//
|
|
24291
|
+
// Driving from `latest` instead makes every step below it a unique-index or
|
|
24292
|
+
// primary-key lookup (uq_inspection_findings_key, then audit_events' own PK),
|
|
24293
|
+
// so the cost is the derived table's own — linear in resolutions, which is
|
|
24294
|
+
// what this feed is legitimately about.
|
|
24295
|
+
//
|
|
24296
|
+
// CROSS JOIN is what actually pins that, and it is load-bearing rather than
|
|
24297
|
+
// decorative: in SQLite the keyword is semantically identical to JOIN and
|
|
24298
|
+
// exists only to stop the optimizer reordering the tables. Written as plain
|
|
24299
|
+
// JOINs in this order the planner puts `e` back on the outside — it has no
|
|
24300
|
+
// ANALYZE statistics to price the alternatives with, so it takes
|
|
24301
|
+
// `event_type = 'code_change'` for a selective index probe and rebuilds the
|
|
24302
|
+
// cross product. The FROM order alone was measured to change the plan not at
|
|
24303
|
+
// all.
|
|
24304
|
+
//
|
|
24305
|
+
// The LEFT JOIN it replaced was already an inner join in effect: three
|
|
24306
|
+
// `latest.*` predicates sit in the WHERE, and each of them is false for a
|
|
24307
|
+
// null-extended row. Spelling it JOIN changes no row and stops the plan
|
|
24308
|
+
// reading as though the findings side could drive.
|
|
24007
24309
|
recentlyResolved(limit = 20) {
|
|
24008
24310
|
const rows = allRows(
|
|
24009
24311
|
this.db.prepare(
|
|
@@ -24013,17 +24315,15 @@ var SqliteSecurityRepository = class {
|
|
|
24013
24315
|
json_extract(e.attributes, '$.file_path') AS path,
|
|
24014
24316
|
COALESCE(f.first_detected_at, e.started_at) AS first_detected_at,
|
|
24015
24317
|
latest.resolved_at AS latest_resolved_at
|
|
24016
|
-
FROM
|
|
24017
|
-
JOIN
|
|
24018
|
-
JOIN
|
|
24019
|
-
|
|
24020
|
-
|
|
24021
|
-
WHERE e.event_type = 'code_change'
|
|
24022
|
-
AND f.finding_key IS NOT NULL
|
|
24023
|
-
AND latest.status = 'resolved'
|
|
24318
|
+
FROM ${LATEST_RESOLUTION_BY_KEY_SQL} latest
|
|
24319
|
+
CROSS JOIN inspection_findings f ON f.finding_key = latest.finding_key
|
|
24320
|
+
CROSS JOIN audit_events e ON e.id = f.audit_event_id
|
|
24321
|
+
CROSS JOIN inspection_definitions d ON d.id = f.inspection_definition_id
|
|
24322
|
+
WHERE latest.status = 'resolved'
|
|
24024
24323
|
AND latest.method = 'fixed-at-source'
|
|
24025
24324
|
AND latest.resolved_at IS NOT NULL
|
|
24026
|
-
|
|
24325
|
+
AND e.event_type = 'code_change'
|
|
24326
|
+
ORDER BY latest.resolved_at DESC
|
|
24027
24327
|
LIMIT :limit`
|
|
24028
24328
|
),
|
|
24029
24329
|
{ limit }
|
|
@@ -24960,6 +25260,7 @@ function openAndInitialize(file2) {
|
|
|
24960
25260
|
function openLocalDatabase(dir) {
|
|
24961
25261
|
ensureDataDirSync(dir);
|
|
24962
25262
|
const file2 = join2(dir, DB_FILENAME);
|
|
25263
|
+
reapStalePartials(file2);
|
|
24963
25264
|
const {
|
|
24964
25265
|
db,
|
|
24965
25266
|
events,
|
|
@@ -25394,11 +25695,79 @@ function migrateLegacyLayout(base = defaultDataDir()) {
|
|
|
25394
25695
|
}
|
|
25395
25696
|
}
|
|
25396
25697
|
|
|
25397
|
-
// ../../packages/persistence/src/settings.ts
|
|
25698
|
+
// ../../packages/persistence/src/managed-settings.ts
|
|
25398
25699
|
import { readFileSync as readFileSync3 } from "fs";
|
|
25700
|
+
import { posix, win32 } from "path";
|
|
25701
|
+
function managedSettingsPaths(platform2 = process.platform) {
|
|
25702
|
+
if (platform2 === "darwin") {
|
|
25703
|
+
return [
|
|
25704
|
+
posix.join("/Library", "Application Support", "AKASecurity", MANAGED_SETTINGS_FILENAME),
|
|
25705
|
+
posix.join("/Library", "Managed Preferences", MANAGED_SETTINGS_FILENAME)
|
|
25706
|
+
];
|
|
25707
|
+
}
|
|
25708
|
+
if (platform2 === "win32") {
|
|
25709
|
+
return [win32.join("C:\\", "ProgramData", "AKASecurity", MANAGED_SETTINGS_FILENAME)];
|
|
25710
|
+
}
|
|
25711
|
+
return [posix.join("/etc", "aka", MANAGED_SETTINGS_FILENAME)];
|
|
25712
|
+
}
|
|
25713
|
+
function readManagedSettings(paths = managedSettingsPaths()) {
|
|
25714
|
+
for (const path of paths) {
|
|
25715
|
+
let text;
|
|
25716
|
+
try {
|
|
25717
|
+
text = readFileSync3(path, "utf8");
|
|
25718
|
+
} catch {
|
|
25719
|
+
continue;
|
|
25720
|
+
}
|
|
25721
|
+
const record2 = parseJsonObject(text);
|
|
25722
|
+
if (!record2) continue;
|
|
25723
|
+
const parsed = ManagedSettings.safeParse(record2);
|
|
25724
|
+
if (parsed.success) return parsed.data;
|
|
25725
|
+
}
|
|
25726
|
+
return null;
|
|
25727
|
+
}
|
|
25728
|
+
function overlayManagedSettings(settings, managed, now = () => /* @__PURE__ */ new Date()) {
|
|
25729
|
+
if (!managed) return settings;
|
|
25730
|
+
const { values } = managed;
|
|
25731
|
+
const merged = { ...settings };
|
|
25732
|
+
if (values.runMode !== void 0) merged.runMode = values.runMode;
|
|
25733
|
+
if (values.controlPlane !== void 0) {
|
|
25734
|
+
merged.controlPlane = {
|
|
25735
|
+
...values.controlPlane,
|
|
25736
|
+
// The administrator pinned WHICH deployment, not WHEN this machine
|
|
25737
|
+
// joined it. Keep the user's own attach time when the endpoint is
|
|
25738
|
+
// unchanged, so a managed machine does not appear to re-attach on every
|
|
25739
|
+
// read; stamp a fresh one when the administrator moved it.
|
|
25740
|
+
attachedAt: settings.controlPlane?.endpoint === values.controlPlane.endpoint ? settings.controlPlane.attachedAt : now().toISOString()
|
|
25741
|
+
};
|
|
25742
|
+
}
|
|
25743
|
+
if (values.historicalAccess !== void 0) merged.historicalAccess = values.historicalAccess;
|
|
25744
|
+
if (values.vaultKeyCustody !== void 0) merged.vaultKeyCustody = values.vaultKeyCustody;
|
|
25745
|
+
if (values.vaultInlineReveal !== void 0) merged.vaultInlineReveal = values.vaultInlineReveal;
|
|
25746
|
+
if (values.dataSharesInPlace !== void 0) merged.dataSharesInPlace = values.dataSharesInPlace;
|
|
25747
|
+
if (values.vaultConsent !== void 0) {
|
|
25748
|
+
merged.vaultConsent = values.vaultConsent ? (
|
|
25749
|
+
// Keep an existing valid grant so its acknowledgedAt survives; mint one
|
|
25750
|
+
// at the current version otherwise.
|
|
25751
|
+
settings.vaultConsent?.version === VAULT_CONSENT_VERSION ? settings.vaultConsent : { acknowledgedAt: now().toISOString(), version: VAULT_CONSENT_VERSION }
|
|
25752
|
+
) : void 0;
|
|
25753
|
+
}
|
|
25754
|
+
if (values.modelJudgeConsent !== void 0) {
|
|
25755
|
+
merged.modelJudgeConsent = values.modelJudgeConsent ? settings.modelJudgeConsent?.payloadVersion === MODEL_JUDGE_PAYLOAD_VERSION ? settings.modelJudgeConsent : {
|
|
25756
|
+
acknowledgedAt: now().toISOString(),
|
|
25757
|
+
payloadVersion: MODEL_JUDGE_PAYLOAD_VERSION
|
|
25758
|
+
} : void 0;
|
|
25759
|
+
}
|
|
25760
|
+
return merged;
|
|
25761
|
+
}
|
|
25762
|
+
|
|
25763
|
+
// ../../packages/persistence/src/settings.ts
|
|
25764
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
25399
25765
|
import { join as join5 } from "path";
|
|
25400
25766
|
var SETTINGS_FILENAME = "settings.json";
|
|
25401
25767
|
function readWorkspaceSettings(base = defaultDataDir()) {
|
|
25768
|
+
return overlayManagedSettings(readUserSettings(base), readManagedSettings());
|
|
25769
|
+
}
|
|
25770
|
+
function readUserSettings(base) {
|
|
25402
25771
|
const record2 = readJson(join5(settingsDir(base), SETTINGS_FILENAME));
|
|
25403
25772
|
if (!record2) return defaultWorkspaceSettings();
|
|
25404
25773
|
try {
|
|
@@ -25410,7 +25779,7 @@ function readWorkspaceSettings(base = defaultDataDir()) {
|
|
|
25410
25779
|
function readJson(file2) {
|
|
25411
25780
|
let text;
|
|
25412
25781
|
try {
|
|
25413
|
-
text =
|
|
25782
|
+
text = readFileSync4(file2, "utf8");
|
|
25414
25783
|
} catch {
|
|
25415
25784
|
return null;
|
|
25416
25785
|
}
|
|
@@ -25528,15 +25897,7 @@ function formatPointer(category, keyVersion, pointerId, tag) {
|
|
|
25528
25897
|
// ../../packages/persistence/src/vault/key-provider.ts
|
|
25529
25898
|
import { execFileSync } from "child_process";
|
|
25530
25899
|
import { randomBytes as randomBytes2 } from "crypto";
|
|
25531
|
-
import {
|
|
25532
|
-
chmodSync as chmodSync2,
|
|
25533
|
-
mkdirSync as mkdirSync2,
|
|
25534
|
-
readFileSync as readFileSync4,
|
|
25535
|
-
renameSync as renameSync4,
|
|
25536
|
-
rmSync as rmSync4,
|
|
25537
|
-
statSync as statSync3,
|
|
25538
|
-
writeFileSync as writeFileSync3
|
|
25539
|
-
} from "fs";
|
|
25900
|
+
import { chmodSync as chmodSync2, readFileSync as readFileSync5, renameSync as renameSync4, rmSync as rmSync4, statSync as statSync3, writeFileSync as writeFileSync3 } from "fs";
|
|
25540
25901
|
import { join as join6 } from "path";
|
|
25541
25902
|
var VAULT_OCCUPANT_REASON = {
|
|
25542
25903
|
symlink: "the path is a symlink; remove it so a keyring can be created",
|
|
@@ -25629,7 +25990,8 @@ var LOCK_OWNER_FILE = "owner";
|
|
|
25629
25990
|
var ROTATION_IN_PROGRESS = "vault: a key rotation is already in progress";
|
|
25630
25991
|
function claimRotationLock(lock, owner) {
|
|
25631
25992
|
try {
|
|
25632
|
-
|
|
25993
|
+
mkdirOwnerOnlySync(lock);
|
|
25994
|
+
tightenDir(lock);
|
|
25633
25995
|
} catch (err) {
|
|
25634
25996
|
if (err.code === "EEXIST") return false;
|
|
25635
25997
|
throw asError(err);
|
|
@@ -25671,7 +26033,7 @@ function acquireRotationLock(keysDir2) {
|
|
|
25671
26033
|
}
|
|
25672
26034
|
function releaseRotationLock(lease) {
|
|
25673
26035
|
try {
|
|
25674
|
-
if (
|
|
26036
|
+
if (readFileSync5(join6(lease.lock, LOCK_OWNER_FILE), "utf8").trim() !== lease.owner) return;
|
|
25675
26037
|
} catch {
|
|
25676
26038
|
return;
|
|
25677
26039
|
}
|
|
@@ -25722,7 +26084,7 @@ var FileKeyProvider = class {
|
|
|
25722
26084
|
#read() {
|
|
25723
26085
|
let raw;
|
|
25724
26086
|
try {
|
|
25725
|
-
raw =
|
|
26087
|
+
raw = readFileSync5(this.filePath, "utf8");
|
|
25726
26088
|
} catch (err) {
|
|
25727
26089
|
if (err.code === "ENOENT") return null;
|
|
25728
26090
|
throw err instanceof Error ? err : new Error(String(err));
|
|
@@ -25761,15 +26123,19 @@ var FileKeyProvider = class {
|
|
|
25761
26123
|
* Atomic tmp + rename so a crash mid-write cannot truncate the keyring.
|
|
25762
26124
|
* Used only for rotation, under the rotation lock — first creation goes
|
|
25763
26125
|
* through the creation-exclusive path instead.
|
|
26126
|
+
*
|
|
26127
|
+
* Delegated to the shared owner-only write rather than spelled here, so the
|
|
26128
|
+
* create mode this file is published at is the one paths.ts owns and tests
|
|
26129
|
+
* directly. A local copy of the pair was a second place the mode could be
|
|
26130
|
+
* dropped with the trailing tighten still repairing the end state, which is
|
|
26131
|
+
* the shape no assertion on a published file can see. It also picks up that
|
|
26132
|
+
* primitive's per-process tmp name, its stale-tmp sweep, and an exclusive
|
|
26133
|
+
* create that refuses to follow a symlink planted at the tmp path.
|
|
25764
26134
|
*/
|
|
25765
26135
|
#write(keyring) {
|
|
25766
26136
|
ensureDataDirSync(this.#keysDir);
|
|
25767
|
-
|
|
25768
|
-
|
|
25769
|
-
writeFileSync3(tmp, `${serializeKeyring(keyring)}
|
|
25770
|
-
`, { mode: DATA_FILE_MODE });
|
|
25771
|
-
renameSync4(tmp, file2);
|
|
25772
|
-
tightenFileMode(file2);
|
|
26137
|
+
writeOwnerOnlyFileSync(this.filePath, `${serializeKeyring(keyring)}
|
|
26138
|
+
`);
|
|
25773
26139
|
return keyring;
|
|
25774
26140
|
}
|
|
25775
26141
|
};
|
|
@@ -25779,15 +26145,73 @@ function tightenFileMode(file2) {
|
|
|
25779
26145
|
} catch {
|
|
25780
26146
|
}
|
|
25781
26147
|
}
|
|
25782
|
-
var
|
|
26148
|
+
var SECURITY_TIMEOUT_MS = 5e3;
|
|
26149
|
+
var runSecurity = (args, stdin) => execFileSync("/usr/bin/security", args, {
|
|
25783
26150
|
encoding: "utf8",
|
|
25784
|
-
|
|
26151
|
+
input: stdin,
|
|
26152
|
+
timeout: SECURITY_TIMEOUT_MS,
|
|
26153
|
+
// stderr is discarded rather than captured, and that is deliberate: a
|
|
26154
|
+
// captured stream rides out on an execFileSync error's `.stderr`, and the
|
|
26155
|
+
// write paths here carry the keyring. Exit status is the only thing any
|
|
26156
|
+
// branch below reads.
|
|
26157
|
+
stdio: [stdin === void 0 ? "ignore" : "pipe", "pipe", "ignore"]
|
|
25785
26158
|
});
|
|
25786
26159
|
var SECURITY_ITEM_NOT_FOUND = 44;
|
|
26160
|
+
function corruptReason(err) {
|
|
26161
|
+
if (err instanceof SyntaxError) return "malformed JSON";
|
|
26162
|
+
return err instanceof Error ? err.message : "unknown";
|
|
26163
|
+
}
|
|
26164
|
+
function securityFailureMeta(err) {
|
|
26165
|
+
const e = err;
|
|
26166
|
+
const parts = [];
|
|
26167
|
+
if (typeof e.status === "number") parts.push(`exit ${String(e.status)}`);
|
|
26168
|
+
if (typeof e.signal === "string" && e.signal) parts.push(`signal ${e.signal}`);
|
|
26169
|
+
if (typeof e.code === "string" && e.code) parts.push(e.code);
|
|
26170
|
+
return parts.length > 0 ? parts.join(", ") : "unknown error";
|
|
26171
|
+
}
|
|
26172
|
+
function writeCommand(keyring, update, keychain) {
|
|
26173
|
+
const hex3 = Buffer.from(serializeKeyring(keyring), "utf8").toString("hex");
|
|
26174
|
+
const parts = [
|
|
26175
|
+
"add-generic-password",
|
|
26176
|
+
...update ? ["-U"] : [],
|
|
26177
|
+
"-s",
|
|
26178
|
+
KEYCHAIN_SERVICE,
|
|
26179
|
+
"-a",
|
|
26180
|
+
KEYCHAIN_ACCOUNT,
|
|
26181
|
+
"-X",
|
|
26182
|
+
hex3
|
|
26183
|
+
];
|
|
26184
|
+
if (keychain !== void 0) {
|
|
26185
|
+
if (/['\\\n\r\0]/.test(keychain)) {
|
|
26186
|
+
throw new Error(
|
|
26187
|
+
"vault: keychain path contains a quote, backslash, line break or NUL, which security -i cannot carry intact"
|
|
26188
|
+
);
|
|
26189
|
+
}
|
|
26190
|
+
parts.push(`'${keychain}'`);
|
|
26191
|
+
}
|
|
26192
|
+
return `${parts.join(" ")}
|
|
26193
|
+
`;
|
|
26194
|
+
}
|
|
25787
26195
|
var KeychainKeyProvider = class {
|
|
25788
26196
|
#keysDir;
|
|
25789
26197
|
#exec;
|
|
25790
|
-
|
|
26198
|
+
#keychain;
|
|
26199
|
+
/**
|
|
26200
|
+
* The trailing keychain argument, or nothing. Every subcommand used here
|
|
26201
|
+
* takes it last (`add-generic-password [keychain]`,
|
|
26202
|
+
* `find-generic-password [keychain...]`), and omitting it means the default
|
|
26203
|
+
* search list. Fixed at construction, so it is built once rather than per
|
|
26204
|
+
* call on the capture path.
|
|
26205
|
+
*/
|
|
26206
|
+
#target;
|
|
26207
|
+
/**
|
|
26208
|
+
* `keychain` names the keychain to operate on, as `security`'s trailing
|
|
26209
|
+
* argument. Production passes nothing and gets the user's default keychain,
|
|
26210
|
+
* which is the whole point of the backend. A test driving the REAL binary
|
|
26211
|
+
* passes a throwaway one, because the alternative is writing vault key
|
|
26212
|
+
* material into the developer's own login keychain and leaving it there.
|
|
26213
|
+
*/
|
|
26214
|
+
constructor(keysDir2, exec = runSecurity, keychain) {
|
|
25791
26215
|
if (exec === runSecurity && process.platform !== "darwin") {
|
|
25792
26216
|
throw new Error(
|
|
25793
26217
|
`keychain custody is not available on this platform (${process.platform}); use file custody`
|
|
@@ -25795,6 +26219,8 @@ var KeychainKeyProvider = class {
|
|
|
25795
26219
|
}
|
|
25796
26220
|
this.#keysDir = keysDir2;
|
|
25797
26221
|
this.#exec = exec;
|
|
26222
|
+
this.#keychain = keychain;
|
|
26223
|
+
this.#target = keychain === void 0 ? [] : [keychain];
|
|
25798
26224
|
}
|
|
25799
26225
|
/** Where a fallback file provider for the same vault would keep its keyring. */
|
|
25800
26226
|
get keysDir() {
|
|
@@ -25833,18 +26259,22 @@ var KeychainKeyProvider = class {
|
|
|
25833
26259
|
KEYCHAIN_SERVICE,
|
|
25834
26260
|
"-a",
|
|
25835
26261
|
KEYCHAIN_ACCOUNT,
|
|
25836
|
-
"-w"
|
|
26262
|
+
"-w",
|
|
26263
|
+
...this.#target
|
|
25837
26264
|
]);
|
|
25838
26265
|
} catch (err) {
|
|
25839
26266
|
if (err.status === SECURITY_ITEM_NOT_FOUND) return null;
|
|
25840
26267
|
throw new Error(
|
|
25841
|
-
`vault: keychain read failed (${
|
|
25842
|
-
{ cause: err }
|
|
26268
|
+
`vault: keychain read failed (${securityFailureMeta(err)}); refusing to treat the failure as an absent keyring`
|
|
25843
26269
|
);
|
|
25844
26270
|
}
|
|
25845
26271
|
const body = raw.trim();
|
|
25846
26272
|
if (body.length === 0) return null;
|
|
25847
|
-
|
|
26273
|
+
try {
|
|
26274
|
+
return parseKeyring(body);
|
|
26275
|
+
} catch (err) {
|
|
26276
|
+
throw new Error(`vault: keychain item is not a usable keyring (${corruptReason(err)})`);
|
|
26277
|
+
}
|
|
25848
26278
|
}
|
|
25849
26279
|
/**
|
|
25850
26280
|
* First mint: a plain `add-generic-password` (no `-U`) fails when an item
|
|
@@ -25852,37 +26282,25 @@ var KeychainKeyProvider = class {
|
|
|
25852
26282
|
* keyring — the loser re-reads and adopts it instead.
|
|
25853
26283
|
*/
|
|
25854
26284
|
#create(keyring) {
|
|
25855
|
-
const
|
|
25856
|
-
"add-generic-password",
|
|
25857
|
-
"-s",
|
|
25858
|
-
KEYCHAIN_SERVICE,
|
|
25859
|
-
"-a",
|
|
25860
|
-
KEYCHAIN_ACCOUNT,
|
|
25861
|
-
"-w",
|
|
25862
|
-
serializeKeyring(keyring)
|
|
25863
|
-
];
|
|
26285
|
+
const line = writeCommand(keyring, false, this.#keychain);
|
|
25864
26286
|
try {
|
|
25865
|
-
this.#exec(
|
|
26287
|
+
this.#exec(["-i"], line);
|
|
25866
26288
|
} catch (err) {
|
|
25867
26289
|
const winner = this.#read();
|
|
25868
26290
|
if (winner) return winner;
|
|
25869
|
-
throw
|
|
26291
|
+
throw new Error(`vault: keychain write failed (${securityFailureMeta(err)})`);
|
|
25870
26292
|
}
|
|
25871
26293
|
return keyring;
|
|
25872
26294
|
}
|
|
25873
26295
|
// `-U` updates the item in place, deliberately replacing the stored map with
|
|
25874
26296
|
// one that contains it — used only for rotation, under the rotation lock.
|
|
25875
26297
|
#replace(keyring) {
|
|
25876
|
-
this.#
|
|
25877
|
-
|
|
25878
|
-
"-
|
|
25879
|
-
|
|
25880
|
-
|
|
25881
|
-
|
|
25882
|
-
KEYCHAIN_ACCOUNT,
|
|
25883
|
-
"-w",
|
|
25884
|
-
serializeKeyring(keyring)
|
|
25885
|
-
]);
|
|
26298
|
+
const line = writeCommand(keyring, true, this.#keychain);
|
|
26299
|
+
try {
|
|
26300
|
+
this.#exec(["-i"], line);
|
|
26301
|
+
} catch (err) {
|
|
26302
|
+
throw new Error(`vault: keychain write failed (${securityFailureMeta(err)})`);
|
|
26303
|
+
}
|
|
25886
26304
|
return keyring;
|
|
25887
26305
|
}
|
|
25888
26306
|
};
|
|
@@ -26382,7 +26800,7 @@ function resolveProviderSafe(resolveProviderFn) {
|
|
|
26382
26800
|
}
|
|
26383
26801
|
|
|
26384
26802
|
// ../../packages/plugin-sdk/src/config-inventory.ts
|
|
26385
|
-
import { readdirSync as readdirSync2, readFileSync as
|
|
26803
|
+
import { readdirSync as readdirSync2, readFileSync as readFileSync7, realpathSync, statSync as statSync5 } from "fs";
|
|
26386
26804
|
import { homedir as homedir2 } from "os";
|
|
26387
26805
|
import { basename as basename3, join as join10 } from "path";
|
|
26388
26806
|
|
|
@@ -26958,6 +27376,40 @@ function escapeRegExp2(value) {
|
|
|
26958
27376
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
26959
27377
|
}
|
|
26960
27378
|
|
|
27379
|
+
// ../../packages/detections/src/regex-cache.ts
|
|
27380
|
+
var singles = /* @__PURE__ */ new WeakMap();
|
|
27381
|
+
var keywordLists = /* @__PURE__ */ new WeakMap();
|
|
27382
|
+
var labelLists = /* @__PURE__ */ new WeakMap();
|
|
27383
|
+
function listCache(kind) {
|
|
27384
|
+
return kind === "keyword" ? keywordLists : labelLists;
|
|
27385
|
+
}
|
|
27386
|
+
function memoizedRegExp(owner, build) {
|
|
27387
|
+
const cached2 = singles.get(owner);
|
|
27388
|
+
if (cached2 !== void 0) {
|
|
27389
|
+
cached2.lastIndex = 0;
|
|
27390
|
+
return cached2;
|
|
27391
|
+
}
|
|
27392
|
+
const compiled = build();
|
|
27393
|
+
singles.set(owner, compiled);
|
|
27394
|
+
return compiled;
|
|
27395
|
+
}
|
|
27396
|
+
function memoizedRegExpList(kind, owner, build) {
|
|
27397
|
+
const cache = listCache(kind);
|
|
27398
|
+
const cached2 = cache.get(owner);
|
|
27399
|
+
if (cached2 !== void 0) {
|
|
27400
|
+
if (cached2.stateful) {
|
|
27401
|
+
for (const re of cached2.entries) if (re !== void 0) re.lastIndex = 0;
|
|
27402
|
+
}
|
|
27403
|
+
return cached2.entries;
|
|
27404
|
+
}
|
|
27405
|
+
const entries = build();
|
|
27406
|
+
cache.set(owner, {
|
|
27407
|
+
entries,
|
|
27408
|
+
stateful: entries.some((re) => re !== void 0 && (re.global || re.sticky))
|
|
27409
|
+
});
|
|
27410
|
+
return entries;
|
|
27411
|
+
}
|
|
27412
|
+
|
|
26961
27413
|
// ../../packages/detections/src/matchers/limits.ts
|
|
26962
27414
|
var MAX_MATCHES_PER_RULE = 1e4;
|
|
26963
27415
|
var MAX_REGEX_INPUT_LENGTH = 2e5;
|
|
@@ -26968,10 +27420,17 @@ var KeywordMatcher2 = class {
|
|
|
26968
27420
|
if (rule.matcher.type !== "keyword") return [];
|
|
26969
27421
|
const { keywords, caseSensitive } = rule.matcher;
|
|
26970
27422
|
const spans = [];
|
|
26971
|
-
|
|
26972
|
-
|
|
27423
|
+
const compiled = memoizedRegExpList(
|
|
27424
|
+
"keyword",
|
|
27425
|
+
rule.matcher,
|
|
27426
|
+
() => keywords.map((kw) => {
|
|
27427
|
+
if (kw.length === 0) return void 0;
|
|
27428
|
+
return new RegExp(escapeRegExp2(kw), caseSensitive ? "gu" : "giu");
|
|
27429
|
+
})
|
|
27430
|
+
);
|
|
27431
|
+
for (const re of compiled) {
|
|
27432
|
+
if (re === void 0) continue;
|
|
26973
27433
|
if (spans.length >= MAX_MATCHES_PER_RULE) break;
|
|
26974
|
-
const re = new RegExp(escapeRegExp2(kw), caseSensitive ? "gu" : "giu");
|
|
26975
27434
|
let m;
|
|
26976
27435
|
while ((m = re.exec(text)) !== null) {
|
|
26977
27436
|
spans.push({ start: m.index, end: m.index + m[0].length });
|
|
@@ -26987,7 +27446,10 @@ var RegexMatcher2 = class {
|
|
|
26987
27446
|
match(text, rule) {
|
|
26988
27447
|
if (rule.matcher.type !== "regex") return [];
|
|
26989
27448
|
const { pattern, flags, captureGroup } = rule.matcher;
|
|
26990
|
-
const re =
|
|
27449
|
+
const re = memoizedRegExp(
|
|
27450
|
+
rule.matcher,
|
|
27451
|
+
() => new RegExp(pattern, flags.includes("d") ? flags : `${flags}d`)
|
|
27452
|
+
);
|
|
26991
27453
|
const scanText2 = text.length > MAX_REGEX_INPUT_LENGTH ? text.slice(0, MAX_REGEX_INPUT_LENGTH) : text;
|
|
26992
27454
|
const spans = [];
|
|
26993
27455
|
let m;
|
|
@@ -27046,6 +27508,10 @@ function luhnCheck(digits) {
|
|
|
27046
27508
|
// ../../packages/detections/src/engine.ts
|
|
27047
27509
|
var keywordMatcher = new KeywordMatcher2();
|
|
27048
27510
|
var regexMatcher = new RegexMatcher2();
|
|
27511
|
+
var MATCHERS = {
|
|
27512
|
+
keyword: (text, rule) => keywordMatcher.match(text, rule),
|
|
27513
|
+
regex: (text, rule) => regexMatcher.match(text, rule)
|
|
27514
|
+
};
|
|
27049
27515
|
var packs = /* @__PURE__ */ new Map();
|
|
27050
27516
|
var POST_VALIDATORS = {
|
|
27051
27517
|
entropy: (value, config2) => isHighEntropy(value, numberOption(config2, "threshold"), numberOption(config2, "minLength")),
|
|
@@ -27061,8 +27527,7 @@ function passesPostValidators(rule, value) {
|
|
|
27061
27527
|
for (const ref of validators) {
|
|
27062
27528
|
const name = typeof ref === "string" ? ref : ref.name;
|
|
27063
27529
|
const config2 = typeof ref === "string" ? void 0 : ref.config;
|
|
27064
|
-
|
|
27065
|
-
if (validate && !validate(value, config2)) return false;
|
|
27530
|
+
if (!POST_VALIDATORS[name](value, config2)) return false;
|
|
27066
27531
|
}
|
|
27067
27532
|
return true;
|
|
27068
27533
|
}
|
|
@@ -27095,11 +27560,15 @@ function isCorroborated(candidate, candidates, text) {
|
|
|
27095
27560
|
const labels = req.labels;
|
|
27096
27561
|
if (labels && labels.length > 0) {
|
|
27097
27562
|
const haystack = text.slice(Math.max(0, winStart), winEnd);
|
|
27098
|
-
for (const
|
|
27099
|
-
|
|
27100
|
-
|
|
27101
|
-
|
|
27102
|
-
|
|
27563
|
+
for (const re of memoizedRegExpList(
|
|
27564
|
+
"label",
|
|
27565
|
+
req,
|
|
27566
|
+
() => labels.map((label) => {
|
|
27567
|
+
const trimmed = label.trim();
|
|
27568
|
+
return trimmed.length === 0 ? void 0 : new RegExp(`(?<![A-Za-z0-9])${escapeRegExp2(trimmed)}(?![A-Za-z0-9])`, "i");
|
|
27569
|
+
})
|
|
27570
|
+
)) {
|
|
27571
|
+
if (re?.test(haystack)) return true;
|
|
27103
27572
|
}
|
|
27104
27573
|
}
|
|
27105
27574
|
return false;
|
|
@@ -27119,14 +27588,7 @@ function scan(text, rules, context) {
|
|
|
27119
27588
|
const candidates = [];
|
|
27120
27589
|
for (const rule of ruleset) {
|
|
27121
27590
|
if (!ruleApplies(rule, extension)) continue;
|
|
27122
|
-
|
|
27123
|
-
if (rule.matcher.type === "keyword") {
|
|
27124
|
-
spans = keywordMatcher.match(text, rule);
|
|
27125
|
-
} else if (rule.matcher.type === "regex") {
|
|
27126
|
-
spans = regexMatcher.match(text, rule);
|
|
27127
|
-
} else {
|
|
27128
|
-
continue;
|
|
27129
|
-
}
|
|
27591
|
+
const spans = MATCHERS[rule.matcher.type](text, rule);
|
|
27130
27592
|
for (const span of spans) {
|
|
27131
27593
|
const rawMatch = text.slice(span.start, span.end);
|
|
27132
27594
|
if (!passesPostValidators(rule, rawMatch)) continue;
|
|
@@ -27367,24 +27829,33 @@ function probesFor(rule) {
|
|
|
27367
27829
|
const derived = rule.matcher.type === "regex" ? derivedProbes(rule.matcher.pattern) : [];
|
|
27368
27830
|
return [...derived, ...EXPONENTIAL_PROBES, ...POLYNOMIAL_PROBES];
|
|
27369
27831
|
}
|
|
27370
|
-
|
|
27832
|
+
var wallClock = () => performance.now();
|
|
27833
|
+
function worstProbeMs(rule, now = wallClock, corroborate) {
|
|
27371
27834
|
let ms = 0;
|
|
27372
27835
|
let probe = "";
|
|
27836
|
+
let corroboratedMs;
|
|
27373
27837
|
for (const text of probesFor(rule)) {
|
|
27374
|
-
const start =
|
|
27838
|
+
const start = now();
|
|
27839
|
+
const corroborateStart = corroborate?.();
|
|
27375
27840
|
scan(text, [rule]);
|
|
27376
|
-
const elapsed =
|
|
27841
|
+
const elapsed = now() - start;
|
|
27842
|
+
const corroborateEnd = corroborate?.();
|
|
27377
27843
|
if (elapsed > ms) {
|
|
27378
27844
|
ms = elapsed;
|
|
27379
27845
|
probe = text;
|
|
27846
|
+
corroboratedMs = corroborateStart === void 0 || corroborateEnd === void 0 ? void 0 : corroborateEnd - corroborateStart;
|
|
27380
27847
|
}
|
|
27381
27848
|
if (ms >= BUDGET_MS) break;
|
|
27382
27849
|
}
|
|
27383
|
-
return { ms, probe };
|
|
27850
|
+
return { ms, probe, corroboratedMs };
|
|
27384
27851
|
}
|
|
27385
|
-
|
|
27386
|
-
|
|
27387
|
-
|
|
27852
|
+
var CPU_CORROBORATION_SHARE = 0.2;
|
|
27853
|
+
var CORROBORATION_FLOOR_MS = BUDGET_MS * CPU_CORROBORATION_SHARE;
|
|
27854
|
+
function checkRuleTiming(rule, corroborate) {
|
|
27855
|
+
const { ms, probe, corroboratedMs } = worstProbeMs(rule, wallClock, corroborate);
|
|
27856
|
+
const work = corroboratedMs ?? 0;
|
|
27857
|
+
const verdict = ms < BUDGET_MS ? "safe" : work >= CORROBORATION_FLOOR_MS ? "over-budget" : "uncorroborated";
|
|
27858
|
+
return { verdict, worstMs: ms, corroboratedMs: work, probe };
|
|
27388
27859
|
}
|
|
27389
27860
|
|
|
27390
27861
|
// ../../rules/code-flaws/auth-jwt-no-verify.json
|
|
@@ -29420,7 +29891,7 @@ function bundledDetections() {
|
|
|
29420
29891
|
}
|
|
29421
29892
|
|
|
29422
29893
|
// ../../packages/plugin-sdk/src/repo.ts
|
|
29423
|
-
import { existsSync as existsSync6, readFileSync as
|
|
29894
|
+
import { existsSync as existsSync6, readFileSync as readFileSync6, statSync as statSync4 } from "fs";
|
|
29424
29895
|
import { basename as basename2, dirname as dirname2, isAbsolute, join as join9, sep as sep2 } from "path";
|
|
29425
29896
|
function resolveRepo(cwd) {
|
|
29426
29897
|
try {
|
|
@@ -29465,7 +29936,7 @@ function resolveGitContext(root) {
|
|
|
29465
29936
|
}
|
|
29466
29937
|
function safeRead(path) {
|
|
29467
29938
|
try {
|
|
29468
|
-
return
|
|
29939
|
+
return readFileSync6(path, "utf8");
|
|
29469
29940
|
} catch {
|
|
29470
29941
|
return void 0;
|
|
29471
29942
|
}
|
|
@@ -29766,7 +30237,12 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
29766
30237
|
build: (id) => ({ kind: "probe", id, rule }),
|
|
29767
30238
|
reply: (message) => {
|
|
29768
30239
|
if (message.kind !== "probed") return false;
|
|
29769
|
-
resolve({
|
|
30240
|
+
resolve({
|
|
30241
|
+
status: "ok",
|
|
30242
|
+
verdict: message.verdict,
|
|
30243
|
+
worstMs: message.worstMs,
|
|
30244
|
+
corroboratedMs: message.corroboratedMs
|
|
30245
|
+
});
|
|
29770
30246
|
return true;
|
|
29771
30247
|
}
|
|
29772
30248
|
},
|
|
@@ -29786,6 +30262,12 @@ function createIsolatedScanner(data, opts = {}) {
|
|
|
29786
30262
|
};
|
|
29787
30263
|
}
|
|
29788
30264
|
|
|
30265
|
+
// ../../packages/plugin-sdk/src/work-clock.ts
|
|
30266
|
+
function workClockMs() {
|
|
30267
|
+
const usage = typeof process.threadCpuUsage === "function" ? process.threadCpuUsage() : process.cpuUsage();
|
|
30268
|
+
return (usage.user + usage.system) / 1e3;
|
|
30269
|
+
}
|
|
30270
|
+
|
|
29789
30271
|
// ../../packages/plugin-sdk/src/rule-quarantine.ts
|
|
29790
30272
|
var PASS_BUDGET_MS = 2e3;
|
|
29791
30273
|
var UNQUARANTINE_HINT = "clear it with `aka detections unquarantine`";
|
|
@@ -29814,6 +30296,14 @@ function warnUnmeasured(rule) {
|
|
|
29814
30296
|
false
|
|
29815
30297
|
);
|
|
29816
30298
|
}
|
|
30299
|
+
function warnUncorroborated(rule, worstMs, corroboratedMs) {
|
|
30300
|
+
warn(
|
|
30301
|
+
rule,
|
|
30302
|
+
"deferred",
|
|
30303
|
+
`its regex matcher ran past the ReDoS timing budget (${worstMs.toFixed(1)}ms) but spent only ${corroboratedMs.toFixed(1)}ms of CPU doing it, which is a busy machine rather than a slow pattern; excluded from this run and measured again next time, with nothing recorded against it.`,
|
|
30304
|
+
false
|
|
30305
|
+
);
|
|
30306
|
+
}
|
|
29817
30307
|
function warnUnmeasurable(reason, count) {
|
|
29818
30308
|
process.stderr.write(
|
|
29819
30309
|
`[aka] ${String(count)} pulled/custom-pack rule(s) could not be time-checked: ${reason}. That is a problem with this install, not with the rules \u2014 until it is fixed they are excluded from every scan on this machine. Nothing was quarantined, so reinstalling AKA brings them straight back.
|
|
@@ -29860,24 +30350,31 @@ async function filterUnsafeRules(rules, gateway, opts) {
|
|
|
29860
30350
|
warnUnmeasured(rule);
|
|
29861
30351
|
continue;
|
|
29862
30352
|
}
|
|
29863
|
-
let
|
|
30353
|
+
let verdict;
|
|
29864
30354
|
let worstMs;
|
|
30355
|
+
let corroboratedMs = 0;
|
|
29865
30356
|
if (prober) {
|
|
29866
30357
|
const outcome = await prober.probe(rule);
|
|
29867
30358
|
if (outcome.status === "unavailable") {
|
|
29868
30359
|
unmeasurable.set(outcome.reason, (unmeasurable.get(outcome.reason) ?? 0) + 1);
|
|
29869
30360
|
continue;
|
|
29870
30361
|
}
|
|
29871
|
-
|
|
30362
|
+
verdict = outcome.status === "ok" ? outcome.verdict : "over-budget";
|
|
29872
30363
|
worstMs = outcome.status === "ok" ? outcome.worstMs : outcome.elapsedMs;
|
|
30364
|
+
if (outcome.status === "ok") corroboratedMs = outcome.corroboratedMs;
|
|
29873
30365
|
} else {
|
|
29874
30366
|
try {
|
|
29875
|
-
({
|
|
30367
|
+
({ verdict, worstMs, corroboratedMs } = checkRuleTiming(rule, workClockMs));
|
|
29876
30368
|
} catch {
|
|
29877
|
-
|
|
30369
|
+
verdict = "over-budget";
|
|
29878
30370
|
worstMs = Number.POSITIVE_INFINITY;
|
|
29879
30371
|
}
|
|
29880
30372
|
}
|
|
30373
|
+
if (verdict === "uncorroborated") {
|
|
30374
|
+
warnUncorroborated(rule, worstMs, corroboratedMs);
|
|
30375
|
+
continue;
|
|
30376
|
+
}
|
|
30377
|
+
const isSafe = verdict === "safe";
|
|
29881
30378
|
let persisted = false;
|
|
29882
30379
|
try {
|
|
29883
30380
|
await gateway.setRuleProbeVerdict(key, isSafe ? "safe" : "quarantined", worstMs);
|
|
@@ -29977,21 +30474,25 @@ function createGuardedScanner(partition, gateway, opts) {
|
|
|
29977
30474
|
};
|
|
29978
30475
|
}
|
|
29979
30476
|
|
|
30477
|
+
// ../../packages/plugin-sdk/src/ignore-layers.ts
|
|
30478
|
+
var import_ignore = __toESM(require_ignore(), 1);
|
|
30479
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
30480
|
+
import { join as join11 } from "path";
|
|
30481
|
+
|
|
29980
30482
|
// ../../packages/plugin-sdk/src/inventory-resolver.ts
|
|
29981
30483
|
import { arch, hostname as hostname4, platform, release } from "os";
|
|
29982
30484
|
|
|
29983
30485
|
// ../../packages/plugin-sdk/src/nudge.ts
|
|
29984
|
-
import { mkdirSync as
|
|
29985
|
-
import { join as
|
|
30486
|
+
import { mkdirSync as mkdirSync2, readFileSync as readFileSync9, writeFileSync as writeFileSync5 } from "fs";
|
|
30487
|
+
import { join as join12 } from "path";
|
|
29986
30488
|
|
|
29987
30489
|
// ../../packages/plugin-sdk/src/paths.ts
|
|
29988
30490
|
import { readdirSync as readdirSync3, realpathSync as realpathSync2 } from "fs";
|
|
29989
30491
|
import { basename as basename4, dirname as dirname3, sep as sep3 } from "path";
|
|
29990
30492
|
|
|
29991
30493
|
// ../../packages/plugin-sdk/src/project-files.ts
|
|
29992
|
-
|
|
29993
|
-
import {
|
|
29994
|
-
import { basename as basename5, join as join12, relative, sep as sep4 } from "path";
|
|
30494
|
+
import { existsSync as existsSync8, readdirSync as readdirSync4 } from "fs";
|
|
30495
|
+
import { basename as basename5, join as join13 } from "path";
|
|
29995
30496
|
|
|
29996
30497
|
// ../../packages/plugin-sdk/src/provider-env-antigravity.ts
|
|
29997
30498
|
var optionalBaseUrl2 = external_exports.preprocess((v) => {
|
|
@@ -30050,6 +30551,7 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
30050
30551
|
let initialized = false;
|
|
30051
30552
|
const ruleActionIndex = /* @__PURE__ */ new Map();
|
|
30052
30553
|
const categoryActionIndex = /* @__PURE__ */ new Map();
|
|
30554
|
+
let reversibleRuleIndex = /* @__PURE__ */ new Set();
|
|
30053
30555
|
async function ensureInitialized() {
|
|
30054
30556
|
if (initialized) return;
|
|
30055
30557
|
const bundle = await gateway.getPolicyBundle();
|
|
@@ -30062,6 +30564,7 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
30062
30564
|
categoryActionIndex.set(p.target.category, p.action);
|
|
30063
30565
|
}
|
|
30064
30566
|
}
|
|
30567
|
+
reversibleRuleIndex = new Set(bundle.reversibleRuleIds ?? []);
|
|
30065
30568
|
const bundledProbeKeys = new Set(
|
|
30066
30569
|
getLoadedRules().map(ruleProbeKey).filter((key) => key !== void 0)
|
|
30067
30570
|
);
|
|
@@ -30140,11 +30643,13 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
30140
30643
|
if (worst === "block") return { action: "block", text: null, findings };
|
|
30141
30644
|
if (worst === "redact") {
|
|
30142
30645
|
const redactFindings = findings.filter((f) => actionFor(f) === "redact");
|
|
30646
|
+
const reversibleFindings = redactFindings.filter((f) => reversibleRuleIndex.has(f.ruleId));
|
|
30143
30647
|
return {
|
|
30144
30648
|
action: "redact",
|
|
30145
30649
|
text: redact(text, redactFindings),
|
|
30146
30650
|
findings,
|
|
30147
|
-
enforcedFindings: redactFindings
|
|
30651
|
+
enforcedFindings: redactFindings,
|
|
30652
|
+
reversibleFindings
|
|
30148
30653
|
};
|
|
30149
30654
|
}
|
|
30150
30655
|
return { action: worst, text, findings };
|
|
@@ -30358,8 +30863,8 @@ function createPluginRuntime(gateway, settings, opts) {
|
|
|
30358
30863
|
var THIRTY_DAYS_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
30359
30864
|
|
|
30360
30865
|
// ../../packages/plugin-sdk/src/throttle.ts
|
|
30361
|
-
import { mkdirSync as
|
|
30362
|
-
import { join as
|
|
30866
|
+
import { mkdirSync as mkdirSync3, statSync as statSync6, writeFileSync as writeFileSync6 } from "fs";
|
|
30867
|
+
import { join as join14 } from "path";
|
|
30363
30868
|
|
|
30364
30869
|
// ../../packages/plugin-sdk/src/tokenize.ts
|
|
30365
30870
|
function redactedPlaceholder(category) {
|
|
@@ -30422,6 +30927,8 @@ var SecretVaultGlue = class {
|
|
|
30422
30927
|
async tokenizeText(text, opts) {
|
|
30423
30928
|
try {
|
|
30424
30929
|
const findings = opts?.findings ?? this.#selfScan(text);
|
|
30930
|
+
const reversible = opts?.reversible;
|
|
30931
|
+
const keeps = (finding) => reversible === void 0 || reversible.has(finding);
|
|
30425
30932
|
if (findings === null) return { text: "[REDACTED]", pointers: [], degraded: [] };
|
|
30426
30933
|
if (findings.length === 0) return { text, pointers: [], degraded: [] };
|
|
30427
30934
|
const groups = groupSpans(text, findings);
|
|
@@ -30438,6 +30945,8 @@ var SecretVaultGlue = class {
|
|
|
30438
30945
|
} else if (original !== finding.rawMatch) {
|
|
30439
30946
|
replacement = redactedPlaceholder(group.category);
|
|
30440
30947
|
degraded.unshift({ category: group.category });
|
|
30948
|
+
} else if (!keeps(finding)) {
|
|
30949
|
+
replacement = redactedPlaceholder(finding.category);
|
|
30441
30950
|
} else {
|
|
30442
30951
|
replacement = await this.tokenizeValue(finding.rawMatch, {
|
|
30443
30952
|
ruleId: finding.ruleId,
|
|
@@ -30662,17 +31171,17 @@ var UNOPENABLE_VAULT = {
|
|
|
30662
31171
|
|
|
30663
31172
|
// src/protocol/marker.ts
|
|
30664
31173
|
import { randomBytes as randomBytes4 } from "crypto";
|
|
30665
|
-
import { mkdirSync as
|
|
30666
|
-
import { join as
|
|
31174
|
+
import { mkdirSync as mkdirSync4, readFileSync as readFileSync10, renameSync as renameSync5, writeFileSync as writeFileSync7 } from "fs";
|
|
31175
|
+
import { join as join15 } from "path";
|
|
30667
31176
|
var MARKER_FILE = "protocol-marker";
|
|
30668
31177
|
function mintMarker() {
|
|
30669
31178
|
return randomBytes4(8).toString("hex");
|
|
30670
31179
|
}
|
|
30671
31180
|
function sessionProtocolMarker(dataDir2, sessionId) {
|
|
30672
31181
|
if (!sessionId) return mintMarker();
|
|
30673
|
-
const path =
|
|
31182
|
+
const path = join15(dataDir2, MARKER_FILE);
|
|
30674
31183
|
try {
|
|
30675
|
-
const stored = JSON.parse(
|
|
31184
|
+
const stored = JSON.parse(readFileSync10(path, "utf8"));
|
|
30676
31185
|
if (stored.sessionId === sessionId && typeof stored.marker === "string" && /^[0-9a-f]{16}$/.test(stored.marker)) {
|
|
30677
31186
|
return stored.marker;
|
|
30678
31187
|
}
|
|
@@ -30680,8 +31189,8 @@ function sessionProtocolMarker(dataDir2, sessionId) {
|
|
|
30680
31189
|
}
|
|
30681
31190
|
const marker = mintMarker();
|
|
30682
31191
|
try {
|
|
30683
|
-
|
|
30684
|
-
const tmp =
|
|
31192
|
+
mkdirSync4(dataDir2, { recursive: true, mode: DATA_DIR_MODE });
|
|
31193
|
+
const tmp = join15(dataDir2, `${MARKER_FILE}.tmp`);
|
|
30685
31194
|
writeFileSync7(tmp, JSON.stringify({ sessionId, marker }), { mode: DATA_FILE_MODE });
|
|
30686
31195
|
renameSync5(tmp, path);
|
|
30687
31196
|
} catch {
|
|
@@ -30876,9 +31385,10 @@ async function decidePreToolUse(toolName, toolInput, scanned, tokenizeField) {
|
|
|
30876
31385
|
} else if (action === "redact") {
|
|
30877
31386
|
let rewritten = result.text;
|
|
30878
31387
|
const enforced = result.enforcedFindings ?? [];
|
|
31388
|
+
const reversible = new Set(result.reversibleFindings ?? []);
|
|
30879
31389
|
if (tokenizeField && enforced.length > 0) {
|
|
30880
31390
|
try {
|
|
30881
|
-
const tokenized = await tokenizeField(text, enforced);
|
|
31391
|
+
const tokenized = await tokenizeField(text, enforced, reversible);
|
|
30882
31392
|
rewritten = tokenized.text;
|
|
30883
31393
|
for (const token of tokenized.pointers) {
|
|
30884
31394
|
realized.pointers.push({ token, category: pointerCategory(token) });
|
|
@@ -31076,8 +31586,8 @@ function baseMetadata(input) {
|
|
|
31076
31586
|
}
|
|
31077
31587
|
|
|
31078
31588
|
// src/hooks/store-health.ts
|
|
31079
|
-
import { mkdirSync as
|
|
31080
|
-
import { join as
|
|
31589
|
+
import { mkdirSync as mkdirSync5, readFileSync as readFileSync11, writeFileSync as writeFileSync8 } from "fs";
|
|
31590
|
+
import { join as join16 } from "path";
|
|
31081
31591
|
|
|
31082
31592
|
// ../../packages/plugin-runtime/src/standalone-gateway.ts
|
|
31083
31593
|
import { randomUUID as randomUUID15 } from "crypto";
|
|
@@ -31090,6 +31600,8 @@ var StandaloneDataGateway = class {
|
|
|
31090
31600
|
db;
|
|
31091
31601
|
// Kept for the fingerprint key lookup (exception.key lives beside the store).
|
|
31092
31602
|
dataDir;
|
|
31603
|
+
// One notice per gateway — see warnRulesetDiscarded.
|
|
31604
|
+
warnedRulesetDiscarded = false;
|
|
31093
31605
|
constructor(dataDir2, detections = [], meta3) {
|
|
31094
31606
|
this.db = openLocalDatabase(dataDir2);
|
|
31095
31607
|
this.dataDir = dataDir2;
|
|
@@ -31209,28 +31721,69 @@ var StandaloneDataGateway = class {
|
|
|
31209
31721
|
// - ANY invalid rule among enabled packs (all-invalid, partial corruption,
|
|
31210
31722
|
// or a single malformed entry) → undefined → bundled fallback. Serving a
|
|
31211
31723
|
// reduced "complete" set would silently drop exactly the corrupted rules
|
|
31212
|
-
// with no fallback
|
|
31213
|
-
// never loses coverage
|
|
31214
|
-
//
|
|
31215
|
-
//
|
|
31724
|
+
// with no fallback. The bundled packs are a superset of AKA's OWN packs,
|
|
31725
|
+
// so falling back never loses coverage there — but they contain no
|
|
31726
|
+
// pulled or custom pack, so for those this trades a partial ruleset for
|
|
31727
|
+
// none of them plus the loss of every pack's per-detection enforcement
|
|
31728
|
+
// action. That is deliberate (a store this machine cannot fully validate
|
|
31729
|
+
// is not authoritative), and it is why the cost of REJECTING a rule
|
|
31730
|
+
// matters: `Rule` is strict, so one unrecognized key in one custom rule
|
|
31731
|
+
// reaches this branch, not just a genuinely malformed or foreign store.
|
|
31732
|
+
// `installed-packs.test.ts` pins that per-rule counting;
|
|
31216
31733
|
// - enabled packs that produce ZERO rules with no invalids (e.g. every
|
|
31217
31734
|
// enabled pack's rules_json is `[]`) → undefined → bundled fallback: an
|
|
31218
31735
|
// enabled pack contributing nothing is untrustworthy, not a real
|
|
31219
31736
|
// "detect nothing" (that is expressed by disabling packs, handled above);
|
|
31220
31737
|
// - otherwise → the enabled packs' validated rules, marked complete.
|
|
31738
|
+
/**
|
|
31739
|
+
* The discard above is the one ruleset decision this gateway reaches on its
|
|
31740
|
+
* own, and it is the most expensive one here: ONE rejected entry costs the
|
|
31741
|
+
* user every custom rule and every per-detection enforcement action, replaced
|
|
31742
|
+
* by bundled packs that contain neither. Nothing else reports it — a hook is a
|
|
31743
|
+
* short-lived process whose stderr is the only channel it has — so name what
|
|
31744
|
+
* was rejected and where the rest of the list lives.
|
|
31745
|
+
*
|
|
31746
|
+
* Unlike a quarantine verdict this caches nothing: the rejection is re-derived
|
|
31747
|
+
* from the store on every run, so the recovery is to fix or reinstall the pack,
|
|
31748
|
+
* and no line here may offer a command that clears a stored verdict.
|
|
31749
|
+
*
|
|
31750
|
+
* Written at most once per gateway — a second getPolicyBundle() in the same
|
|
31751
|
+
* process would re-report the same finding.
|
|
31752
|
+
*/
|
|
31753
|
+
warnRulesetDiscarded(snapshot) {
|
|
31754
|
+
if (this.warnedRulesetDiscarded) return;
|
|
31755
|
+
this.warnedRulesetDiscarded = true;
|
|
31756
|
+
const listed = snapshot.rejectedRules.map((r) => `${r.pack}${r.ruleId === null ? "" : ` "${r.ruleId}"`} (${r.reason})`).join(", ");
|
|
31757
|
+
const undisclosed = snapshot.invalidRules - snapshot.rejectedRules.length;
|
|
31758
|
+
const more = undisclosed > 0 ? `, and ${String(undisclosed)} more` : "";
|
|
31759
|
+
process.stderr.write(
|
|
31760
|
+
`[aka] installed ruleset not used: ${String(snapshot.invalidRules)} rule(s) under enabled packs failed validation, so scanning fell back to the bundled packs and no custom rule or per-detection action is enforced \u2014 rejected: ${listed}${more}; review them with \`aka detections\`
|
|
31761
|
+
`
|
|
31762
|
+
);
|
|
31763
|
+
}
|
|
31221
31764
|
installedScanRules() {
|
|
31222
31765
|
try {
|
|
31223
31766
|
const snapshot = this.db.installedPacks.installedRuleset();
|
|
31224
31767
|
if (snapshot.installedPacks === 0) return void 0;
|
|
31225
31768
|
if (snapshot.enabledPacks === 0) {
|
|
31226
|
-
return {
|
|
31769
|
+
return {
|
|
31770
|
+
rules: [],
|
|
31771
|
+
ruleActions: /* @__PURE__ */ new Map(),
|
|
31772
|
+
ruleVersions: /* @__PURE__ */ new Map(),
|
|
31773
|
+
reversibleRules: /* @__PURE__ */ new Set(),
|
|
31774
|
+
complete: true
|
|
31775
|
+
};
|
|
31776
|
+
}
|
|
31777
|
+
if (snapshot.invalidRules > 0) {
|
|
31778
|
+
this.warnRulesetDiscarded(snapshot);
|
|
31779
|
+
return void 0;
|
|
31227
31780
|
}
|
|
31228
|
-
if (snapshot.invalidRules > 0) return void 0;
|
|
31229
31781
|
if (snapshot.rules.length === 0) return void 0;
|
|
31230
31782
|
return {
|
|
31231
31783
|
rules: snapshot.rules,
|
|
31232
31784
|
ruleActions: snapshot.ruleActions,
|
|
31233
31785
|
ruleVersions: snapshot.ruleVersions,
|
|
31786
|
+
reversibleRules: snapshot.reversibleRules,
|
|
31234
31787
|
complete: true
|
|
31235
31788
|
};
|
|
31236
31789
|
} catch {
|
|
@@ -31258,6 +31811,11 @@ var StandaloneDataGateway = class {
|
|
|
31258
31811
|
return {
|
|
31259
31812
|
version: "local",
|
|
31260
31813
|
policies: [...policies, ...rulePolicies],
|
|
31814
|
+
// The reversibility half of each pack's assignment. Emitted only under the
|
|
31815
|
+
// authoritative installed snapshot, exactly like rulePolicies above: the
|
|
31816
|
+
// bundled-packs fallback carries no per-pack assignment, so it carries no
|
|
31817
|
+
// reversibility either and every redaction there stays one-way.
|
|
31818
|
+
reversibleRuleIds: installed ? [...installed.reversibleRules] : [],
|
|
31261
31819
|
rules: installed ? installed.rules : [],
|
|
31262
31820
|
...installed ? { rulesComplete: true } : {},
|
|
31263
31821
|
...installed ? { ruleVersions: Object.fromEntries(installed.ruleVersions) } : {},
|
|
@@ -31276,29 +31834,32 @@ var StandaloneDataGateway = class {
|
|
|
31276
31834
|
return this.db.exceptions.recordBlocked(entry);
|
|
31277
31835
|
}
|
|
31278
31836
|
// Retention sweep over TERMINAL exception rows (revoked / expired / budget
|
|
31279
|
-
// exhausted) —
|
|
31280
|
-
//
|
|
31837
|
+
// exhausted) — local-store maintenance, invoked from SessionStart through the
|
|
31838
|
+
// LocalStoreMaintenance capability rather than the DataGateway port. Active
|
|
31839
|
+
// grants are never touched.
|
|
31281
31840
|
sweepTerminalExceptions(retentionMs) {
|
|
31282
31841
|
return this.db.exceptions.sweepTerminal(retentionMs);
|
|
31283
31842
|
}
|
|
31284
|
-
// The warn-era enforcement cap
|
|
31285
|
-
//
|
|
31286
|
-
// of block/redact rows capped to
|
|
31287
|
-
// already-capped one).
|
|
31843
|
+
// The warn-era enforcement cap — local-store maintenance, invoked from
|
|
31844
|
+
// SessionStart through the LocalStoreMaintenance capability rather than
|
|
31845
|
+
// the DataGateway port. Returns the number of block/redact rows capped to
|
|
31846
|
+
// warn (0 for a redact-policy store or an already-capped one).
|
|
31288
31847
|
capWarnEraEnforcement(policyMode) {
|
|
31289
31848
|
const { capped } = capWarnEraEnforcementOnce(this.db, policyMode, this.dataDir);
|
|
31290
31849
|
return { capped };
|
|
31291
31850
|
}
|
|
31292
31851
|
// One project-file scan → the local project_file tree (one transaction inside
|
|
31293
|
-
// the LocalDatabase, fail-open there). Like the sweep above, this is
|
|
31294
|
-
//
|
|
31852
|
+
// the LocalDatabase, fail-open there). Like the sweep above, this is reached
|
|
31853
|
+
// through the LocalStoreMaintenance capability rather than the DataGateway
|
|
31854
|
+
// port: the file tree is a local-store read model.
|
|
31295
31855
|
recordProjectFiles(projectId, scan2) {
|
|
31296
31856
|
this.db.recordProjectFiles(projectId, scan2);
|
|
31297
31857
|
return Promise.resolve();
|
|
31298
31858
|
}
|
|
31299
31859
|
// Fold ghost source_project rows minted by the pre-worktree-fix resolver
|
|
31300
|
-
// (checkout-path identities) into the repo's canonical row.
|
|
31301
|
-
//
|
|
31860
|
+
// (checkout-path identities) into the repo's canonical row. Local-store
|
|
31861
|
+
// maintenance, invoked from SessionStart through the LocalStoreMaintenance
|
|
31862
|
+
// capability. Fail-open in the store.
|
|
31302
31863
|
reconcileWorktreeProjects(canonicalId, headRoot, worktreeRoot) {
|
|
31303
31864
|
this.db.reconcileWorktreeProjects(canonicalId, headRoot, worktreeRoot);
|
|
31304
31865
|
return Promise.resolve();
|
|
@@ -31309,10 +31870,10 @@ var StandaloneDataGateway = class {
|
|
|
31309
31870
|
* executing the plugin generation they started with (Claude Code caches
|
|
31310
31871
|
* plugin versions), and the write gate makes their installed-pack writes
|
|
31311
31872
|
* silent no-ops — this is the one-line nudge telling the user WHY, and that
|
|
31312
|
-
* a restart picks the newer plugin up.
|
|
31313
|
-
* SessionStart
|
|
31314
|
-
* null (no notice), and
|
|
31315
|
-
* never fire it.
|
|
31873
|
+
* a restart picks the newer plugin up. Local-store maintenance, invoked
|
|
31874
|
+
* from SessionStart through the LocalStoreMaintenance capability rather
|
|
31875
|
+
* than the DataGateway port. Fail-open: any error → null (no notice), and
|
|
31876
|
+
* unparseable versions compare equal so garbage can never fire it.
|
|
31316
31877
|
*/
|
|
31317
31878
|
staleBinaryNotice(currentVersion) {
|
|
31318
31879
|
try {
|
|
@@ -31390,7 +31951,8 @@ var StandaloneDataGateway = class {
|
|
|
31390
31951
|
|
|
31391
31952
|
// ../../packages/plugin-runtime/src/resolve.ts
|
|
31392
31953
|
var standaloneGatewayFactory = (config2, meta3) => new StandaloneDataGateway(config2.dataDir, bundledDetections(), meta3);
|
|
31393
|
-
|
|
31954
|
+
var defaultGatewayFactory = standaloneGatewayFactory;
|
|
31955
|
+
function resolveDataGateway(config2, meta3, gatewayFactory = defaultGatewayFactory) {
|
|
31394
31956
|
return gatewayFactory(config2, meta3);
|
|
31395
31957
|
}
|
|
31396
31958
|
|
|
@@ -31412,13 +31974,13 @@ function storeUnavailableMessage(dbPath2) {
|
|
|
31412
31974
|
}
|
|
31413
31975
|
function claimStoreUnavailableWarning(dataDir2, sessionId) {
|
|
31414
31976
|
if (!sessionId) return true;
|
|
31415
|
-
const path =
|
|
31977
|
+
const path = join16(dataDir2, STORE_WARNING_MARKER);
|
|
31416
31978
|
try {
|
|
31417
|
-
if (
|
|
31979
|
+
if (readFileSync11(path, "utf8") === sessionId) return false;
|
|
31418
31980
|
} catch {
|
|
31419
31981
|
}
|
|
31420
31982
|
try {
|
|
31421
|
-
|
|
31983
|
+
mkdirSync5(dataDir2, { recursive: true, mode: DATA_DIR_MODE });
|
|
31422
31984
|
writeFileSync8(path, sessionId, { mode: DATA_FILE_MODE });
|
|
31423
31985
|
} catch {
|
|
31424
31986
|
}
|
|
@@ -31510,7 +32072,7 @@ async function main() {
|
|
|
31510
32072
|
const text = stringAtPath(effectiveInput, spec.path);
|
|
31511
32073
|
if (text === void 0 || text === "") continue;
|
|
31512
32074
|
const result = await runtime.capture(
|
|
31513
|
-
{ kind, sourceTool:
|
|
32075
|
+
{ kind, sourceTool: SOURCE_TOOL.ClaudeCode, text, metadata },
|
|
31514
32076
|
// code_change keeps the default 'always': those events are the at-rest
|
|
31515
32077
|
// trail the re-scan resolver reconciles against, so a benign one still
|
|
31516
32078
|
// has to exist. tool_use records only what was flagged — this hook sees
|
|
@@ -31533,8 +32095,12 @@ async function main() {
|
|
|
31533
32095
|
toolName,
|
|
31534
32096
|
effectiveInput,
|
|
31535
32097
|
scanned,
|
|
31536
|
-
vaultGlue ? (text, findings) => vaultGlue.tokenizeText(text, {
|
|
32098
|
+
vaultGlue ? (text, findings, reversible) => vaultGlue.tokenizeText(text, {
|
|
31537
32099
|
findings,
|
|
32100
|
+
// Which of those the assigned archetype said to KEEP. The glue
|
|
32101
|
+
// rewrites every span either way; this decides only which survive
|
|
32102
|
+
// as recoverable pointers and which are destroyed.
|
|
32103
|
+
reversible,
|
|
31538
32104
|
sighting: filePath ? { location: filePath, kind: "file" } : { location: `${toolName} input`, kind: "tool-input" }
|
|
31539
32105
|
}) : void 0
|
|
31540
32106
|
);
|