avorelo 0.1.0 → 0.3.0
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/LICENSE +23 -16
- package/README.md +90 -51
- package/bin/avorelo.mjs +7 -0
- package/dist/avorelo.mjs +19741 -0
- package/package.json +135 -120
- package/bin/avorelo +0 -9
- package/scripts/README.md +0 -40
- package/scripts/cco-dashboard.js +0 -252
- package/scripts/cco-status.js +0 -430
- package/scripts/lib/activation/account-state.js +0 -37
- package/scripts/lib/activation/activation-runner.js +0 -546
- package/scripts/lib/activation/activation-self-healing.js +0 -480
- package/scripts/lib/activation/activation-state.js +0 -83
- package/scripts/lib/activation/activation-summary.js +0 -191
- package/scripts/lib/activation/adapters/claude-code.js +0 -77
- package/scripts/lib/activation/adapters/codex-cli.js +0 -52
- package/scripts/lib/activation/adapters/cursor.js +0 -37
- package/scripts/lib/activation/adapters/github-agent.js +0 -39
- package/scripts/lib/activation/adapters/terminal.js +0 -42
- package/scripts/lib/activation/adapters/vscode.js +0 -39
- package/scripts/lib/activation/adapters/windsurf.js +0 -37
- package/scripts/lib/activation/ai-surface-detector.js +0 -151
- package/scripts/lib/activation/connect-account.js +0 -145
- package/scripts/lib/activation/detect-environment.js +0 -75
- package/scripts/lib/activation/detect-hosts.js +0 -62
- package/scripts/lib/activation/format-activation-output.js +0 -109
- package/scripts/lib/activation/next-action.js +0 -43
- package/scripts/lib/activation/repair-engine.js +0 -219
- package/scripts/lib/activation-distribution-readiness.js +0 -507
- package/scripts/lib/adapter-conformance.js +0 -176
- package/scripts/lib/adapter-readiness.js +0 -417
- package/scripts/lib/adapter-safety-boundaries.js +0 -335
- package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
- package/scripts/lib/agent-access-governance.js +0 -455
- package/scripts/lib/agent-enforcement.js +0 -765
- package/scripts/lib/agent-policy-profile.js +0 -210
- package/scripts/lib/agent-security/action-evaluator.js +0 -507
- package/scripts/lib/agent-security/adapter-registry.js +0 -98
- package/scripts/lib/agent-security/auto-policy.js +0 -139
- package/scripts/lib/agent-security/bounded-scan.js +0 -93
- package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
- package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
- package/scripts/lib/agent-security/file-write-adapter.js +0 -183
- package/scripts/lib/agent-security/file-write-rules.js +0 -178
- package/scripts/lib/agent-security/index.js +0 -3342
- package/scripts/lib/agent-security/instruction-risk.js +0 -181
- package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
- package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
- package/scripts/lib/agent-security/package-action-adapter.js +0 -175
- package/scripts/lib/agent-security/package-action-rules.js +0 -233
- package/scripts/lib/agent-security/performance.js +0 -148
- package/scripts/lib/agent-security/permission-minimizer.js +0 -403
- package/scripts/lib/agent-security/scan-cache.js +0 -74
- package/scripts/lib/agent-security/source-trust.js +0 -146
- package/scripts/lib/ai-install-prompt.js +0 -288
- package/scripts/lib/ai-workspace-hygiene.js +0 -1499
- package/scripts/lib/alpha-activation.js +0 -520
- package/scripts/lib/alpha-feedback.js +0 -263
- package/scripts/lib/alpha-readiness-gate.js +0 -332
- package/scripts/lib/anti-gaming.js +0 -169
- package/scripts/lib/artifact-health.js +0 -431
- package/scripts/lib/attribution.js +0 -180
- package/scripts/lib/audit.js +0 -289
- package/scripts/lib/avorelo-skill-registry.js +0 -810
- package/scripts/lib/batch-jobs.js +0 -71
- package/scripts/lib/brain-pack.js +0 -578
- package/scripts/lib/brand-boundary.js +0 -424
- package/scripts/lib/brand.js +0 -74
- package/scripts/lib/browser-capability.js +0 -1048
- package/scripts/lib/browser-proof-preflight.js +0 -321
- package/scripts/lib/cache-readiness.js +0 -187
- package/scripts/lib/canonical-reentry.js +0 -162
- package/scripts/lib/capability-packs.js +0 -314
- package/scripts/lib/capability-recommender.js +0 -512
- package/scripts/lib/capability-registry.js +0 -1059
- package/scripts/lib/carry-forward-surfacing.js +0 -194
- package/scripts/lib/ccusage-adapter.js +0 -188
- package/scripts/lib/company-loop.js +0 -1149
- package/scripts/lib/config.js +0 -637
- package/scripts/lib/context-acquisition-plan.js +0 -287
- package/scripts/lib/context-budget-guard.js +0 -170
- package/scripts/lib/context-budget-scanner.js +0 -257
- package/scripts/lib/context-optimizer.js +0 -715
- package/scripts/lib/context-reduction-plan.js +0 -178
- package/scripts/lib/context-safety.js +0 -88
- package/scripts/lib/context-savings-engine.js +0 -158
- package/scripts/lib/cost-evidence.js +0 -254
- package/scripts/lib/cross-host-install-plan.js +0 -308
- package/scripts/lib/cross-host-install-readiness.js +0 -237
- package/scripts/lib/cross-host-value-flow.js +0 -268
- package/scripts/lib/dashboard.js +0 -900
- package/scripts/lib/design-partner-feedback.js +0 -346
- package/scripts/lib/entitlements.js +0 -100
- package/scripts/lib/execution-packet.js +0 -559
- package/scripts/lib/experimentation-events.js +0 -547
- package/scripts/lib/external-capability-compliance.js +0 -107
- package/scripts/lib/external-user-simulation.js +0 -166
- package/scripts/lib/failure-recovery-readiness.js +0 -81
- package/scripts/lib/failure-recovery.js +0 -419
- package/scripts/lib/feedback-intelligence.js +0 -537
- package/scripts/lib/feedback-signals.js +0 -205
- package/scripts/lib/file-integrity.js +0 -68
- package/scripts/lib/fsx.js +0 -127
- package/scripts/lib/full-readiness-gate.js +0 -451
- package/scripts/lib/guidance-builder.js +0 -174
- package/scripts/lib/hook-apply.js +0 -1019
- package/scripts/lib/hook-baseline.js +0 -310
- package/scripts/lib/hook-config-preview.js +0 -275
- package/scripts/lib/hook-contracts.js +0 -290
- package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
- package/scripts/lib/host-capability-matrix.js +0 -351
- package/scripts/lib/host-support-context.js +0 -254
- package/scripts/lib/http-hook-action.js +0 -538
- package/scripts/lib/install-ai-readiness.js +0 -84
- package/scripts/lib/install-intake-risk.js +0 -1037
- package/scripts/lib/install-journey-intelligence.js +0 -329
- package/scripts/lib/intervention-guidance.js +0 -57
- package/scripts/lib/known-limitations.js +0 -115
- package/scripts/lib/l8-path-truth.js +0 -146
- package/scripts/lib/launch-hardening-gate.js +0 -436
- package/scripts/lib/launch-readiness.js +0 -628
- package/scripts/lib/learning-memory.js +0 -686
- package/scripts/lib/lifecycle-hooks.js +0 -802
- package/scripts/lib/local-package-smoke.js +0 -423
- package/scripts/lib/local-pricing.js +0 -299
- package/scripts/lib/mcp-enforcement.js +0 -311
- package/scripts/lib/mcp-least-privilege-policy.js +0 -303
- package/scripts/lib/mcp-tool-inventory.js +0 -388
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +0 -335
- package/scripts/lib/metrics.js +0 -699
- package/scripts/lib/micro-proof.js +0 -133
- package/scripts/lib/next-run-context.js +0 -436
- package/scripts/lib/operating-value.js +0 -1648
- package/scripts/lib/optimization-v3.js +0 -122
- package/scripts/lib/orchestration/adapters/_shared.js +0 -49
- package/scripts/lib/orchestration/adapters/aider.js +0 -18
- package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
- package/scripts/lib/orchestration/adapters/codex.js +0 -35
- package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
- package/scripts/lib/orchestration/adapters/git.js +0 -25
- package/scripts/lib/orchestration/adapters/index.js +0 -31
- package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
- package/scripts/lib/orchestration/adapters/ollama.js +0 -18
- package/scripts/lib/orchestration/adapters/opencode.js +0 -18
- package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
- package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
- package/scripts/lib/orchestration/cli.js +0 -438
- package/scripts/lib/orchestration/execution-manager.js +0 -279
- package/scripts/lib/orchestration/handoff.js +0 -314
- package/scripts/lib/orchestration/index.js +0 -456
- package/scripts/lib/orchestration/inventory.js +0 -47
- package/scripts/lib/orchestration/model-discovery.js +0 -498
- package/scripts/lib/orchestration/model-profiler.js +0 -170
- package/scripts/lib/orchestration/model-profiles.js +0 -252
- package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
- package/scripts/lib/orchestration/proof-writer.js +0 -349
- package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
- package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
- package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
- package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
- package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
- package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
- package/scripts/lib/orchestration/risk-classifier.js +0 -130
- package/scripts/lib/orchestration/routing-policy.js +0 -486
- package/scripts/lib/orchestration/settings.js +0 -112
- package/scripts/lib/orchestration/state.js +0 -165
- package/scripts/lib/orchestration/verification-manager.js +0 -138
- package/scripts/lib/output-profiles.js +0 -146
- package/scripts/lib/package-content-audit.js +0 -368
- package/scripts/lib/package-runtime.js +0 -278
- package/scripts/lib/plan-surface.js +0 -53
- package/scripts/lib/plans.js +0 -2318
- package/scripts/lib/policy-provider.js +0 -27
- package/scripts/lib/prelaunch-activation-readiness.js +0 -409
- package/scripts/lib/prelaunch-evidence-store.js +0 -816
- package/scripts/lib/prelaunch-intelligence.js +0 -869
- package/scripts/lib/pricing-experiment.js +0 -118
- package/scripts/lib/pro-moment-events.js +0 -77
- package/scripts/lib/pro-moment-state.js +0 -227
- package/scripts/lib/pro-moments.js +0 -1216
- package/scripts/lib/product-learning-events.js +0 -629
- package/scripts/lib/project-profile.js +0 -555
- package/scripts/lib/prompt-compiler.js +0 -280
- package/scripts/lib/prompt-lint.js +0 -32
- package/scripts/lib/prompt-suggestions.js +0 -52
- package/scripts/lib/proof-canonical.js +0 -398
- package/scripts/lib/proof-drilldown.js +0 -383
- package/scripts/lib/proof-events.js +0 -342
- package/scripts/lib/proof-history.js +0 -243
- package/scripts/lib/proof-metrics.js +0 -296
- package/scripts/lib/proof-outcome-evidence.js +0 -134
- package/scripts/lib/proof-receipt.js +0 -335
- package/scripts/lib/proof-record.js +0 -461
- package/scripts/lib/public-activation-distribution-gate.js +0 -258
- package/scripts/lib/public-cli.js +0 -3891
- package/scripts/lib/public-distribution-truth.js +0 -211
- package/scripts/lib/public-install-claim-checker.js +0 -294
- package/scripts/lib/publish-provenance-readiness.js +0 -283
- package/scripts/lib/readiness-delta.js +0 -218
- package/scripts/lib/readiness-evidence-closure.js +0 -196
- package/scripts/lib/reentry-memory-capture.js +0 -241
- package/scripts/lib/reentry-memory-retrieval.js +0 -302
- package/scripts/lib/reentry-memory-status.js +0 -146
- package/scripts/lib/reentry-memory-store.js +0 -178
- package/scripts/lib/reentry-state.js +0 -66
- package/scripts/lib/release-candidate-bundle.js +0 -166
- package/scripts/lib/remediation.js +0 -81
- package/scripts/lib/repo-map.js +0 -391
- package/scripts/lib/run-improvements-lifecycle.js +0 -330
- package/scripts/lib/run-improvements.js +0 -789
- package/scripts/lib/runtime-decision-policy.js +0 -387
- package/scripts/lib/safe-path-engine.js +0 -705
- package/scripts/lib/safe-run-controller.js +0 -887
- package/scripts/lib/score.js +0 -262
- package/scripts/lib/seamless-enforcement.js +0 -329
- package/scripts/lib/seamless-outcome.js +0 -689
- package/scripts/lib/seamless-reality-gate.js +0 -5043
- package/scripts/lib/security-risk-classifier.js +0 -511
- package/scripts/lib/security-scan.js +0 -384
- package/scripts/lib/session-context-optimizer.js +0 -1211
- package/scripts/lib/session-timing.js +0 -315
- package/scripts/lib/skill-hygiene.js +0 -805
- package/scripts/lib/skill-packs.js +0 -161
- package/scripts/lib/skills-operating-layer.js +0 -580
- package/scripts/lib/smart-work-routing.js +0 -768
- package/scripts/lib/source-catalog.js +0 -700
- package/scripts/lib/status-value-summary.js +0 -32
- package/scripts/lib/support-bundle.js +0 -578
- package/scripts/lib/task-continuation.js +0 -440
- package/scripts/lib/test-helpers.js +0 -15
- package/scripts/lib/tier.js +0 -38
- package/scripts/lib/token-context-quality-gate.js +0 -370
- package/scripts/lib/token-cost-capture.js +0 -187
- package/scripts/lib/token-cost-intelligence.js +0 -358
- package/scripts/lib/token-efficiency-evidence.js +0 -213
- package/scripts/lib/token-evidence.js +0 -699
- package/scripts/lib/tokenish.js +0 -17
- package/scripts/lib/tool-output-sandbox.js +0 -304
- package/scripts/lib/trust-audit.js +0 -136
- package/scripts/lib/unified-events.js +0 -396
- package/scripts/lib/upgrade-interruption-recovery.js +0 -407
- package/scripts/lib/usage-ledger.js +0 -201
- package/scripts/lib/value-ledger.js +0 -130
- package/scripts/lib/value-proof-calibration.js +0 -531
- package/scripts/lib/visual-qa.js +0 -231
- package/scripts/lib/voice-alpha.js +0 -29
- package/scripts/lib/work-aware-orchestration.js +0 -976
- package/scripts/lib/work-control-receipts.js +0 -577
- package/scripts/lib/work-ledger.js +0 -1123
- package/scripts/lib/work-panel-preview.js +0 -352
- package/scripts/lib/workflow-discipline.js +0 -280
- package/scripts/lib/workflow-signals.js +0 -419
- package/scripts/lib/workspace-map.js +0 -281
- package/scripts/lib/workspace-registry.js +0 -1367
- package/scripts/lib/workspace-resolver.js +0 -480
|
@@ -1,507 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const crypto = require("crypto");
|
|
4
|
-
const {
|
|
5
|
-
contentHashFromAction,
|
|
6
|
-
normalizePath,
|
|
7
|
-
classifyFilesystemWriteTarget,
|
|
8
|
-
isSensitiveWriteTarget,
|
|
9
|
-
isWorkflowWriteTarget,
|
|
10
|
-
targetHashFromAction,
|
|
11
|
-
} = require("./file-write-rules");
|
|
12
|
-
const { classifyPackageAction } = require("./package-action-rules");
|
|
13
|
-
const { classifyMcpAction, argsHashFromAction, targetHashFromMcpAction } = require("./mcp-action-rules");
|
|
14
|
-
|
|
15
|
-
function stableStringify(value) {
|
|
16
|
-
if (Array.isArray(value)) {
|
|
17
|
-
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
18
|
-
}
|
|
19
|
-
if (value && typeof value === "object") {
|
|
20
|
-
return `{${Object.keys(value)
|
|
21
|
-
.sort((left, right) => left.localeCompare(right))
|
|
22
|
-
.map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`)
|
|
23
|
-
.join(",")}}`;
|
|
24
|
-
}
|
|
25
|
-
return JSON.stringify(value);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function sha256(value) {
|
|
29
|
-
return crypto.createHash("sha256").update(value).digest("hex");
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function buildScopeKey(normalized) {
|
|
33
|
-
return sha256(stableStringify({
|
|
34
|
-
componentId: normalized.componentId || "",
|
|
35
|
-
componentType: normalized.componentType || "",
|
|
36
|
-
actionType: normalized.actionType || "",
|
|
37
|
-
cwd: normalized.context?.cwd || "",
|
|
38
|
-
target: normalized.target || "",
|
|
39
|
-
commandHash: normalized.commandHash || "",
|
|
40
|
-
targetHash: normalized.targetHash || "",
|
|
41
|
-
contentHash: normalized.contentHash || "",
|
|
42
|
-
argsHash: normalized.argsHash || "",
|
|
43
|
-
packageManager: normalized.packageManager || "",
|
|
44
|
-
scriptName: normalized.scriptName || "",
|
|
45
|
-
packageName: normalized.packageName || "",
|
|
46
|
-
mcpServer: normalized.mcpServer || "",
|
|
47
|
-
toolName: normalized.toolName || "",
|
|
48
|
-
})).slice(0, 16);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function buildActionIdFromNormalized(normalized) {
|
|
52
|
-
return `action-${sha256(stableStringify({
|
|
53
|
-
componentId: normalized.componentId || "",
|
|
54
|
-
componentType: normalized.componentType || "",
|
|
55
|
-
actionType: normalized.actionType || "",
|
|
56
|
-
target: normalized.target || "",
|
|
57
|
-
commandHash: normalized.commandHash || "",
|
|
58
|
-
targetHash: normalized.targetHash || "",
|
|
59
|
-
contentHash: normalized.contentHash || "",
|
|
60
|
-
argsHash: normalized.argsHash || "",
|
|
61
|
-
scopeKey: normalized.scopeKey || "",
|
|
62
|
-
source: normalized.source || "",
|
|
63
|
-
})).slice(0, 12)}`;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function normalizeAgentSecurityAction(action) {
|
|
67
|
-
const actionType = String(action?.actionType || "filesystem.read");
|
|
68
|
-
const target = normalizePath(action?.target || "");
|
|
69
|
-
const command = String(action?.command || "");
|
|
70
|
-
const contentHash = contentHashFromAction(action);
|
|
71
|
-
const targetHash = actionType === "filesystem.write"
|
|
72
|
-
? targetHashFromAction(action)
|
|
73
|
-
: actionType.startsWith("mcp.")
|
|
74
|
-
? targetHashFromMcpAction(action)
|
|
75
|
-
: target
|
|
76
|
-
? sha256(target)
|
|
77
|
-
: null;
|
|
78
|
-
const argsHash = actionType.startsWith("mcp.") ? argsHashFromAction(action) : null;
|
|
79
|
-
const normalized = {
|
|
80
|
-
componentId: action?.componentId || null,
|
|
81
|
-
componentType: action?.componentType || "config",
|
|
82
|
-
actionType,
|
|
83
|
-
target,
|
|
84
|
-
command,
|
|
85
|
-
commandHash: command ? sha256(command) : null,
|
|
86
|
-
targetHash,
|
|
87
|
-
contentHash,
|
|
88
|
-
argsHash,
|
|
89
|
-
source: normalizePath(action?.source || ""),
|
|
90
|
-
context: {
|
|
91
|
-
cwd: normalizePath(action?.context?.cwd || process.cwd()),
|
|
92
|
-
task: String(action?.context?.task || ""),
|
|
93
|
-
sessionId: String(action?.context?.sessionId || ""),
|
|
94
|
-
},
|
|
95
|
-
relatedSourceIds: Array.isArray(action?.relatedSourceIds)
|
|
96
|
-
? action.relatedSourceIds.map((item) => String(item || "")).filter(Boolean)
|
|
97
|
-
: Array.isArray(action?.context?.relatedSourceIds)
|
|
98
|
-
? action.context.relatedSourceIds.map((item) => String(item || "")).filter(Boolean)
|
|
99
|
-
: [],
|
|
100
|
-
content: typeof action?.content === "string" ? action.content : null,
|
|
101
|
-
packageManager: String(action?.packageManager || ""),
|
|
102
|
-
scriptName: String(action?.scriptName || ""),
|
|
103
|
-
packageName: String(action?.packageName || ""),
|
|
104
|
-
mcpServer: String(action?.mcpServer || ""),
|
|
105
|
-
toolName: String(action?.toolName || ""),
|
|
106
|
-
resource: action?.resource && typeof action.resource === "object" ? action.resource : null,
|
|
107
|
-
args: action?.args && typeof action.args === "object" ? action.args : null,
|
|
108
|
-
};
|
|
109
|
-
normalized.scopeKey = buildScopeKey(normalized);
|
|
110
|
-
normalized.actionId = action?.actionId || buildActionIdFromNormalized(normalized);
|
|
111
|
-
return normalized;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function buildActionId(action) {
|
|
115
|
-
return normalizeAgentSecurityAction(action).actionId;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function hasPattern(text, pattern) {
|
|
119
|
-
return pattern.test(String(text || ""));
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function isSensitivePath(value) {
|
|
123
|
-
return isSensitiveWriteTarget(value);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
function isWorkflowPath(value) {
|
|
127
|
-
return isWorkflowWriteTarget(value);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function isSafeTestCommand(command) {
|
|
131
|
-
const normalized = String(command || "").trim().toLowerCase();
|
|
132
|
-
if (!normalized) return false;
|
|
133
|
-
if (/[|;&><]/.test(normalized)) return false;
|
|
134
|
-
return /^(npm test|npm run test\b|pnpm test\b|pnpm run test\b|yarn test\b|node tests[\\/]|node --test\b|pytest\b|vitest\b|cargo test\b|go test\b)/i.test(normalized);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function inferActionCapabilities(action, componentCard) {
|
|
138
|
-
const capabilities = new Set();
|
|
139
|
-
const actionType = String(action?.actionType || "");
|
|
140
|
-
const text = `${actionType}\n${action?.target || ""}\n${action?.command || ""}\n${action?.source || ""}`;
|
|
141
|
-
|
|
142
|
-
if (actionType.startsWith("filesystem.read")) capabilities.add("filesystemRead");
|
|
143
|
-
if (actionType.startsWith("filesystem.write")) capabilities.add("filesystemWrite");
|
|
144
|
-
if (actionType === "shell.run") capabilities.add("shell");
|
|
145
|
-
if (actionType === "package.run" || actionType === "package.script" || actionType === "package.install") capabilities.add("shell");
|
|
146
|
-
if (actionType === "network.call") capabilities.add("network");
|
|
147
|
-
if (actionType === "mcp.read") capabilities.add("mcpRead");
|
|
148
|
-
if (actionType === "mcp.write" || actionType === "mcp.delete" || actionType === "mcp.admin" || actionType === "mcp.externalMutation" || actionType === "mcp.unknown") {
|
|
149
|
-
capabilities.add("mcpWrite");
|
|
150
|
-
capabilities.add("externalMutation");
|
|
151
|
-
}
|
|
152
|
-
if (actionType === "mcp.read" || actionType === "mcp.unknown") capabilities.add("mcpRead");
|
|
153
|
-
if (
|
|
154
|
-
actionType === "workflow.modify" ||
|
|
155
|
-
actionType === "config.modify" ||
|
|
156
|
-
actionType === "package.install" ||
|
|
157
|
-
actionType === "package.script" ||
|
|
158
|
-
actionType === "package.lockfile.modify"
|
|
159
|
-
) {
|
|
160
|
-
capabilities.add("filesystemWrite");
|
|
161
|
-
}
|
|
162
|
-
if (actionType === "package.install") capabilities.add("network");
|
|
163
|
-
|
|
164
|
-
if (hasPattern(text, /\bhttps?:\/\/|curl|wget|invoke-webrequest|invoke-restmethod|downloadstring\b/i)) {
|
|
165
|
-
capabilities.add("network");
|
|
166
|
-
}
|
|
167
|
-
if (isSensitivePath(text)) capabilities.add("sensitiveAccess");
|
|
168
|
-
if (isWorkflowPath(text)) capabilities.add("externalMutation");
|
|
169
|
-
|
|
170
|
-
const componentCapabilities = componentCard?.capabilities || {};
|
|
171
|
-
Object.keys(componentCapabilities).forEach((key) => {
|
|
172
|
-
if (componentCapabilities[key]) capabilities.add(key);
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
return Array.from(capabilities);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
function collectSensitiveTargets(action) {
|
|
179
|
-
const sensitiveTargets = [];
|
|
180
|
-
[action?.target, action?.source, action?.command].forEach((value) => {
|
|
181
|
-
if (!value || !isSensitivePath(value)) return;
|
|
182
|
-
const nextValue = String(value);
|
|
183
|
-
if (!sensitiveTargets.includes(nextValue)) sensitiveTargets.push(nextValue);
|
|
184
|
-
});
|
|
185
|
-
return sensitiveTargets;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function buildIntentMismatchSignal(normalizedAction, relatedSources = []) {
|
|
189
|
-
const task = String(normalizedAction?.context?.task || "").toLowerCase();
|
|
190
|
-
const target = String(normalizedAction?.target || "").toLowerCase();
|
|
191
|
-
const command = String(normalizedAction?.command || "").toLowerCase();
|
|
192
|
-
const toolName = String(normalizedAction?.toolName || "").toLowerCase();
|
|
193
|
-
const actionType = String(normalizedAction?.actionType || "").toLowerCase();
|
|
194
|
-
const sourceRisky = relatedSources.some((source) => source && source.instructionRisk === "high");
|
|
195
|
-
|
|
196
|
-
if (!task) return null;
|
|
197
|
-
|
|
198
|
-
const stylingTask = /\b(style|styling|css|button|ui|frontend|layout|color|spacing|font)\b/.test(task);
|
|
199
|
-
const targetLooksSensitive = /\.env\b|id_rsa|private.?key|credential|secret/.test(target) || /\.env\b|id_rsa|private.?key|credential|secret/.test(command);
|
|
200
|
-
const workflowLike = /\.github\/workflows\//.test(target) || /\bworkflow|github actions|ci\b/.test(command);
|
|
201
|
-
const packageInstallLike = actionType === "package.install" || /\bnpm install|pnpm add|yarn add|bun add\b/.test(command);
|
|
202
|
-
const destructiveMcp = actionType === "mcp.delete" || actionType === "mcp.admin" || /\bdelete|admin\b/.test(toolName);
|
|
203
|
-
const remoteScript = /\bcurl\b[^\n]*\|\s*(bash|sh|pwsh|powershell)\b/.test(command);
|
|
204
|
-
|
|
205
|
-
if (stylingTask && (targetLooksSensitive || workflowLike || packageInstallLike || destructiveMcp || remoteScript || sourceRisky)) {
|
|
206
|
-
return {
|
|
207
|
-
signal: "intent_mismatch",
|
|
208
|
-
message: "The requested action does not match the stated task.",
|
|
209
|
-
};
|
|
210
|
-
}
|
|
211
|
-
if (!/\b(dependen|install|package|npm|pnpm|yarn)\b/.test(task) && packageInstallLike) {
|
|
212
|
-
return {
|
|
213
|
-
signal: "intent_mismatch",
|
|
214
|
-
message: "Package installation does not match the stated task.",
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
if (!/\b(workflow|ci|release|deploy|github actions)\b/.test(task) && workflowLike) {
|
|
218
|
-
return {
|
|
219
|
-
signal: "intent_mismatch",
|
|
220
|
-
message: "Workflow modification does not match the stated task.",
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
if (!/\b(secret|credential|env|config)\b/.test(task) && targetLooksSensitive) {
|
|
224
|
-
return {
|
|
225
|
-
signal: "intent_mismatch",
|
|
226
|
-
message: "Sensitive file access does not match the stated task.",
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function evaluateAgentSecurityAction(action, options = {}) {
|
|
233
|
-
const componentCard = options.componentCard || null;
|
|
234
|
-
const relatedSources = Array.isArray(options.relatedSources) ? options.relatedSources : [];
|
|
235
|
-
const normalizedAction = {
|
|
236
|
-
...normalizeAgentSecurityAction(action),
|
|
237
|
-
componentId: action?.componentId || componentCard?.id || null,
|
|
238
|
-
componentType: action?.componentType || componentCard?.type || "config",
|
|
239
|
-
source: normalizePath(action?.source || componentCard?.source || ""),
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
const reasons = [];
|
|
243
|
-
const capabilities = inferActionCapabilities(normalizedAction, componentCard);
|
|
244
|
-
const sensitiveTargets = collectSensitiveTargets(normalizedAction);
|
|
245
|
-
const explicitRelatedSourceIds = normalizedAction.relatedSourceIds.length > 0
|
|
246
|
-
? normalizedAction.relatedSourceIds
|
|
247
|
-
: componentCard?.id
|
|
248
|
-
? [componentCard.id]
|
|
249
|
-
: [];
|
|
250
|
-
const componentStatus = componentCard?.status || "known";
|
|
251
|
-
const componentTrust = componentCard
|
|
252
|
-
? (componentCard.trustLevel || "unknown")
|
|
253
|
-
: (normalizedAction.actionType.startsWith("package.") ? "local" : "unknown");
|
|
254
|
-
const permissionExpansion = capabilities.some((capability) => componentCard?.capabilities?.[capability] === false);
|
|
255
|
-
const targetAndCommand = `${normalizedAction.target}\n${normalizedAction.command}`.toLowerCase();
|
|
256
|
-
const highRiskRelatedSource = relatedSources.find((source) => source && source.instructionRisk === "high");
|
|
257
|
-
const suspiciousExternalSource = relatedSources.find((source) => source && ["external_untrusted", "tool_returned_untrusted", "unknown"].includes(source.trustLevel));
|
|
258
|
-
const quarantinedSource = relatedSources.find((source) => Array.isArray(source.remediationActions) && source.remediationActions.includes("quarantine_source"));
|
|
259
|
-
const dataOnlySource = relatedSources.find((source) => source && source.allowedToInfluenceTools === false);
|
|
260
|
-
const trustedOverrideSource = relatedSources.find((source) => Array.isArray(source.remediationActions) && source.remediationActions.includes("trust_source"));
|
|
261
|
-
const writeProfile = normalizedAction.actionType === "filesystem.write"
|
|
262
|
-
? classifyFilesystemWriteTarget(normalizedAction.context?.cwd || process.cwd(), normalizedAction.target)
|
|
263
|
-
: null;
|
|
264
|
-
const packageProfile = normalizedAction.actionType.startsWith("package.")
|
|
265
|
-
? classifyPackageAction(normalizedAction)
|
|
266
|
-
: null;
|
|
267
|
-
const mcpProfile = normalizedAction.actionType.startsWith("mcp.")
|
|
268
|
-
? classifyMcpAction({
|
|
269
|
-
...normalizedAction,
|
|
270
|
-
target: action?.target || normalizedAction.target,
|
|
271
|
-
resource: action?.resource,
|
|
272
|
-
args: action?.args,
|
|
273
|
-
mcpServer: action?.mcpServer || normalizedAction.mcpServer,
|
|
274
|
-
toolName: action?.toolName || normalizedAction.toolName,
|
|
275
|
-
})
|
|
276
|
-
: null;
|
|
277
|
-
|
|
278
|
-
let riskScore = 1;
|
|
279
|
-
let recommendedDecision = "approve";
|
|
280
|
-
|
|
281
|
-
if (normalizedAction.actionType === "filesystem.read" && sensitiveTargets.length === 0 && componentStatus === "known" && componentTrust !== "unknown") {
|
|
282
|
-
reasons.push("Local read-only action on non-sensitive files.");
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (isSafeTestCommand(normalizedAction.command) && componentStatus === "known" && componentTrust !== "unknown") {
|
|
286
|
-
reasons.push("Known local test command.");
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
if (sensitiveTargets.length > 0) {
|
|
290
|
-
reasons.push("Sensitive files or secret-like targets are involved.");
|
|
291
|
-
riskScore = Math.max(riskScore, 3);
|
|
292
|
-
recommendedDecision = normalizedAction.actionType === "filesystem.read" ? "limit" : "deny";
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (highRiskRelatedSource && !trustedOverrideSource) {
|
|
296
|
-
reasons.push("A related source contains high-risk instruction-like content.");
|
|
297
|
-
riskScore = Math.max(riskScore, 3);
|
|
298
|
-
if (
|
|
299
|
-
normalizedAction.actionType === "filesystem.write" ||
|
|
300
|
-
normalizedAction.actionType === "shell.run" ||
|
|
301
|
-
normalizedAction.actionType.startsWith("package.") ||
|
|
302
|
-
normalizedAction.actionType.startsWith("mcp.") ||
|
|
303
|
-
normalizedAction.actionType === "network.call"
|
|
304
|
-
) {
|
|
305
|
-
recommendedDecision = normalizedAction.actionType === "filesystem.read" ? "limit" : "deny";
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
if (quarantinedSource) {
|
|
310
|
-
reasons.push("A related source is quarantined.");
|
|
311
|
-
riskScore = Math.max(riskScore, 3);
|
|
312
|
-
recommendedDecision = normalizedAction.actionType === "filesystem.read" ? "limit" : "deny";
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (suspiciousExternalSource && dataOnlySource) {
|
|
316
|
-
reasons.push("A related untrusted source must be treated as data only.");
|
|
317
|
-
riskScore = Math.max(riskScore, 2);
|
|
318
|
-
if (recommendedDecision === "approve") recommendedDecision = "limit";
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
if (normalizedAction.actionType === "workflow.modify" || isWorkflowPath(normalizedAction.target)) {
|
|
322
|
-
reasons.push("Workflow modification can change automation or release behavior.");
|
|
323
|
-
riskScore = Math.max(riskScore, 3);
|
|
324
|
-
recommendedDecision = "limit";
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (normalizedAction.actionType === "filesystem.write") {
|
|
328
|
-
writeProfile.reasons.forEach((reason) => {
|
|
329
|
-
if (!reasons.includes(reason)) reasons.push(reason);
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
if (writeProfile.riskLevel === "high") {
|
|
333
|
-
riskScore = Math.max(riskScore, 3);
|
|
334
|
-
recommendedDecision = writeProfile.workflow ? "limit" : "deny";
|
|
335
|
-
} else if (writeProfile.riskLevel === "medium") {
|
|
336
|
-
riskScore = Math.max(riskScore, 2);
|
|
337
|
-
recommendedDecision = recommendedDecision === "approve" ? "limit" : recommendedDecision;
|
|
338
|
-
} else {
|
|
339
|
-
riskScore = Math.max(riskScore, 1);
|
|
340
|
-
recommendedDecision = recommendedDecision === "approve" ? "limit" : recommendedDecision;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
if (packageProfile) {
|
|
345
|
-
packageProfile.reasons.forEach((reason) => {
|
|
346
|
-
if (!reasons.includes(reason)) reasons.push(reason);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
if (packageProfile.riskLevel === "high") {
|
|
350
|
-
riskScore = Math.max(riskScore, 3);
|
|
351
|
-
recommendedDecision = packageProfile.recommendedDecision || "deny";
|
|
352
|
-
} else if (packageProfile.riskLevel === "medium") {
|
|
353
|
-
riskScore = Math.max(riskScore, 2);
|
|
354
|
-
recommendedDecision = recommendedDecision === "approve"
|
|
355
|
-
? (packageProfile.recommendedDecision || "limit")
|
|
356
|
-
: recommendedDecision;
|
|
357
|
-
} else {
|
|
358
|
-
riskScore = Math.max(riskScore, 1);
|
|
359
|
-
recommendedDecision = recommendedDecision === "approve"
|
|
360
|
-
? (packageProfile.recommendedDecision || "limit")
|
|
361
|
-
: recommendedDecision;
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (mcpProfile) {
|
|
366
|
-
mcpProfile.reasons.forEach((reason) => {
|
|
367
|
-
if (!reasons.includes(reason)) reasons.push(reason);
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
if (mcpProfile.riskLevel === "high") {
|
|
371
|
-
riskScore = Math.max(riskScore, 3);
|
|
372
|
-
recommendedDecision = mcpProfile.recommendedDecision || "deny";
|
|
373
|
-
} else if (mcpProfile.riskLevel === "medium") {
|
|
374
|
-
riskScore = Math.max(riskScore, 2);
|
|
375
|
-
recommendedDecision = recommendedDecision === "approve"
|
|
376
|
-
? (mcpProfile.recommendedDecision || "limit")
|
|
377
|
-
: recommendedDecision;
|
|
378
|
-
} else {
|
|
379
|
-
riskScore = Math.max(riskScore, 1);
|
|
380
|
-
recommendedDecision = recommendedDecision === "approve"
|
|
381
|
-
? (mcpProfile.recommendedDecision || "limit")
|
|
382
|
-
: recommendedDecision;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (hasPattern(targetAndCommand, /\b(curl|wget)\b[^\n]*\|\s*(bash|sh|pwsh|powershell)\b|\b(invoke-webrequest|invoke-restmethod|downloadstring)\b/i)) {
|
|
387
|
-
reasons.push("Remote script execution was detected.");
|
|
388
|
-
riskScore = Math.max(riskScore, 3);
|
|
389
|
-
recommendedDecision = "deny";
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
if (hasPattern(targetAndCommand, /\brm\s+-rf\b|\bdel\s+\/[qs]\b|\bdelete\b|\bforce push\b|\bgit push\b[^\n]*--force\b|\bremove-item\b/i)) {
|
|
393
|
-
reasons.push("Destructive command behavior was detected.");
|
|
394
|
-
riskScore = Math.max(riskScore, 3);
|
|
395
|
-
recommendedDecision = "deny";
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
if (!mcpProfile && (normalizedAction.actionType === "mcp.write" || normalizedAction.actionType === "mcp.delete" || hasPattern(targetAndCommand, /\badmin\b|\bdelete\b/))) {
|
|
399
|
-
reasons.push("External mutation through MCP requires approval.");
|
|
400
|
-
riskScore = Math.max(riskScore, 3);
|
|
401
|
-
recommendedDecision = normalizedAction.actionType === "mcp.delete" || hasPattern(targetAndCommand, /\badmin\b|\bdelete\b/) ? "deny" : "limit";
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (normalizedAction.actionType === "network.call" || capabilities.includes("network")) {
|
|
405
|
-
reasons.push("Remote network access is involved.");
|
|
406
|
-
riskScore = Math.max(riskScore, 2);
|
|
407
|
-
recommendedDecision = recommendedDecision === "approve" ? "limit" : recommendedDecision;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
if (normalizedAction.actionType === "shell.run" && !isSafeTestCommand(normalizedAction.command)) {
|
|
411
|
-
reasons.push("Shell execution is involved.");
|
|
412
|
-
riskScore = Math.max(riskScore, 2);
|
|
413
|
-
recommendedDecision = recommendedDecision === "approve" ? "limit" : recommendedDecision;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (normalizedAction.actionType === "filesystem.write" || normalizedAction.actionType === "config.modify") {
|
|
417
|
-
reasons.push("Filesystem write access is requested.");
|
|
418
|
-
if (!writeProfile || writeProfile.riskLevel !== "low") {
|
|
419
|
-
riskScore = Math.max(riskScore, 2);
|
|
420
|
-
}
|
|
421
|
-
recommendedDecision = recommendedDecision === "approve" ? "limit" : recommendedDecision;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
if (componentStatus === "new" || componentStatus === "changed") {
|
|
425
|
-
reasons.push("The component is new or changed since the last recorded scan.");
|
|
426
|
-
riskScore = Math.max(riskScore, 2);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
if (componentTrust === "unknown" || componentTrust === "review-needed") {
|
|
430
|
-
reasons.push("The component trust level still needs review.");
|
|
431
|
-
riskScore = Math.max(riskScore, 2);
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
if (permissionExpansion) {
|
|
435
|
-
reasons.push("This action expands beyond the component's recorded posture.");
|
|
436
|
-
riskScore = Math.max(riskScore, 2);
|
|
437
|
-
recommendedDecision = recommendedDecision === "approve" ? "limit" : recommendedDecision;
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
const intentMismatch = buildIntentMismatchSignal(normalizedAction, relatedSources);
|
|
441
|
-
if (intentMismatch) {
|
|
442
|
-
reasons.push(intentMismatch.message);
|
|
443
|
-
riskScore = Math.max(riskScore, 3);
|
|
444
|
-
recommendedDecision = normalizedAction.actionType === "filesystem.read" ? "limit" : "deny";
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
if (reasons.length === 0) {
|
|
448
|
-
reasons.push("No elevated risk indicators were detected.");
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
const riskLevel = riskScore >= 3 ? "high" : riskScore >= 2 ? "medium" : "low";
|
|
452
|
-
const decisionRequired =
|
|
453
|
-
riskLevel === "high" ||
|
|
454
|
-
riskLevel === "medium" && (
|
|
455
|
-
normalizedAction.actionType !== "filesystem.read" ||
|
|
456
|
-
sensitiveTargets.length > 0 ||
|
|
457
|
-
capabilities.includes("shell") ||
|
|
458
|
-
capabilities.includes("network") ||
|
|
459
|
-
capabilities.includes("externalMutation")
|
|
460
|
-
);
|
|
461
|
-
|
|
462
|
-
return {
|
|
463
|
-
actionId: normalizedAction.actionId,
|
|
464
|
-
riskLevel,
|
|
465
|
-
decisionRequired,
|
|
466
|
-
recommendedDecision,
|
|
467
|
-
reasons,
|
|
468
|
-
capabilities,
|
|
469
|
-
sensitiveTargets,
|
|
470
|
-
availableChoices: decisionRequired ? ["approve_once", "deny", "let_wuz_limit"] : [],
|
|
471
|
-
componentId: normalizedAction.componentId,
|
|
472
|
-
componentType: normalizedAction.componentType,
|
|
473
|
-
actionType: normalizedAction.actionType,
|
|
474
|
-
target: normalizedAction.target,
|
|
475
|
-
command: normalizedAction.command,
|
|
476
|
-
packageManager: packageProfile?.packageManager || normalizedAction.packageManager || "unknown",
|
|
477
|
-
scriptName: packageProfile?.scriptName || normalizedAction.scriptName || "",
|
|
478
|
-
packageName: packageProfile?.packageName || normalizedAction.packageName || "",
|
|
479
|
-
mcpServer: mcpProfile?.mcpServer || normalizedAction.mcpServer || "unknown",
|
|
480
|
-
toolName: mcpProfile?.toolName || normalizedAction.toolName || "",
|
|
481
|
-
argsHash: mcpProfile?.argsHash || normalizedAction.argsHash || null,
|
|
482
|
-
targetHash: mcpProfile?.targetHash || normalizedAction.targetHash || null,
|
|
483
|
-
commandHash: normalizedAction.commandHash || null,
|
|
484
|
-
contentHash: normalizedAction.contentHash || null,
|
|
485
|
-
scopeKey: normalizedAction.scopeKey || null,
|
|
486
|
-
context: normalizedAction.context,
|
|
487
|
-
relatedSourceIds: explicitRelatedSourceIds,
|
|
488
|
-
relatedSources: relatedSources.map((source) => ({
|
|
489
|
-
sourceId: source.sourceId,
|
|
490
|
-
sourceType: source.sourceType,
|
|
491
|
-
trustLevel: source.trustLevel,
|
|
492
|
-
instructionRisk: source.instructionRisk,
|
|
493
|
-
allowedToInfluenceTools: source.allowedToInfluenceTools,
|
|
494
|
-
remediationActions: Array.isArray(source.remediationActions) ? source.remediationActions : [],
|
|
495
|
-
})),
|
|
496
|
-
instructionRisk: highRiskRelatedSource ? "high" : suspiciousExternalSource ? "medium" : "low",
|
|
497
|
-
intentMismatch: intentMismatch ? intentMismatch.signal : null,
|
|
498
|
-
};
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
module.exports = {
|
|
502
|
-
buildActionId,
|
|
503
|
-
normalizeAgentSecurityAction,
|
|
504
|
-
evaluateAgentSecurityAction,
|
|
505
|
-
isSafeTestCommand,
|
|
506
|
-
stableStringify,
|
|
507
|
-
};
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { safeWriteJson } = require("../fsx");
|
|
4
|
-
const { SHELL_COMMAND_ADAPTER } = require("./enforcement-adapter");
|
|
5
|
-
const { FILE_WRITE_ADAPTER } = require("./file-write-adapter");
|
|
6
|
-
const { PACKAGE_ACTION_ADAPTER } = require("./package-action-adapter");
|
|
7
|
-
const { MCP_ACTION_ADAPTER } = require("./mcp-action-adapter");
|
|
8
|
-
|
|
9
|
-
const ENFORCEMENT_CAPABILITIES_REL_PATH = ".claude/cco/security/agent-enforcement-capabilities.json";
|
|
10
|
-
|
|
11
|
-
function buildAdapterRegistry(adapters) {
|
|
12
|
-
const normalizedAdapters = [];
|
|
13
|
-
const byActionType = new Map();
|
|
14
|
-
|
|
15
|
-
for (const adapter of Array.isArray(adapters) ? adapters : []) {
|
|
16
|
-
if (!adapter || typeof adapter !== "object") continue;
|
|
17
|
-
const normalized = {
|
|
18
|
-
adapterId: String(adapter.adapterId || ""),
|
|
19
|
-
canEvaluate: adapter.canEvaluate === true,
|
|
20
|
-
canEnforce: adapter.canEnforce === true,
|
|
21
|
-
supportedActionTypes: Array.isArray(adapter.supportedActionTypes)
|
|
22
|
-
? adapter.supportedActionTypes.map((item) => String(item))
|
|
23
|
-
: [],
|
|
24
|
-
enforce: typeof adapter.enforce === "function" ? adapter.enforce : null,
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
if (!normalized.adapterId) {
|
|
28
|
-
throw new Error("Agent Security adapter registry requires adapterId.");
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
normalized.supportedActionTypes.forEach((actionType) => {
|
|
32
|
-
if (!actionType) return;
|
|
33
|
-
if (byActionType.has(actionType)) {
|
|
34
|
-
throw new Error(`Duplicate Agent Security adapter mapping for action type: ${actionType}`);
|
|
35
|
-
}
|
|
36
|
-
byActionType.set(actionType, normalized);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
normalizedAdapters.push(Object.freeze(normalized));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return Object.freeze({
|
|
43
|
-
adapters: normalizedAdapters,
|
|
44
|
-
byActionType,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const ADAPTER_REGISTRY = buildAdapterRegistry([
|
|
49
|
-
SHELL_COMMAND_ADAPTER,
|
|
50
|
-
FILE_WRITE_ADAPTER,
|
|
51
|
-
PACKAGE_ACTION_ADAPTER,
|
|
52
|
-
MCP_ACTION_ADAPTER,
|
|
53
|
-
]);
|
|
54
|
-
|
|
55
|
-
function listAgentSecurityAdapters() {
|
|
56
|
-
return ADAPTER_REGISTRY.adapters.map((adapter) => ({
|
|
57
|
-
adapterId: adapter.adapterId,
|
|
58
|
-
supportedActionTypes: adapter.supportedActionTypes.slice(),
|
|
59
|
-
canEvaluate: adapter.canEvaluate,
|
|
60
|
-
canEnforce: adapter.canEnforce,
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function resolveAgentSecurityAdapter(actionType) {
|
|
65
|
-
return ADAPTER_REGISTRY.byActionType.get(String(actionType || "")) || null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function buildEnforcementCapabilityMatrix(timestamp, mode = "warn", unsupportedActionTypes = []) {
|
|
69
|
-
return {
|
|
70
|
-
generatedAt: timestamp || null,
|
|
71
|
-
mode: String(mode || "warn"),
|
|
72
|
-
adapters: listAgentSecurityAdapters().map((adapter) => ({
|
|
73
|
-
adapterId: adapter.adapterId,
|
|
74
|
-
actionTypes: adapter.supportedActionTypes,
|
|
75
|
-
status: adapter.canEnforce ? "available" : "unavailable",
|
|
76
|
-
})),
|
|
77
|
-
unsupportedActionTypes: Array.from(new Set(
|
|
78
|
-
(Array.isArray(unsupportedActionTypes) ? unsupportedActionTypes : [])
|
|
79
|
-
.map((item) => String(item || ""))
|
|
80
|
-
.filter(Boolean),
|
|
81
|
-
)),
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function writeEnforcementCapabilityMatrix(cwd, timestamp, mode = "warn", unsupportedActionTypes = []) {
|
|
86
|
-
const matrix = buildEnforcementCapabilityMatrix(timestamp, mode, unsupportedActionTypes);
|
|
87
|
-
safeWriteJson(cwd, ENFORCEMENT_CAPABILITIES_REL_PATH, matrix);
|
|
88
|
-
return matrix;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = {
|
|
92
|
-
ENFORCEMENT_CAPABILITIES_REL_PATH,
|
|
93
|
-
buildAdapterRegistry,
|
|
94
|
-
listAgentSecurityAdapters,
|
|
95
|
-
resolveAgentSecurityAdapter,
|
|
96
|
-
buildEnforcementCapabilityMatrix,
|
|
97
|
-
writeEnforcementCapabilityMatrix,
|
|
98
|
-
};
|