avorelo 0.1.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 +21 -0
- package/README.md +56 -0
- package/bin/avorelo +9 -0
- package/package.json +135 -0
- package/scripts/README.md +40 -0
- package/scripts/cco-dashboard.js +252 -0
- package/scripts/cco-status.js +430 -0
- package/scripts/lib/activation/account-state.js +37 -0
- package/scripts/lib/activation/activation-runner.js +546 -0
- package/scripts/lib/activation/activation-self-healing.js +480 -0
- package/scripts/lib/activation/activation-state.js +83 -0
- package/scripts/lib/activation/activation-summary.js +191 -0
- package/scripts/lib/activation/adapters/claude-code.js +77 -0
- package/scripts/lib/activation/adapters/codex-cli.js +52 -0
- package/scripts/lib/activation/adapters/cursor.js +37 -0
- package/scripts/lib/activation/adapters/github-agent.js +39 -0
- package/scripts/lib/activation/adapters/terminal.js +42 -0
- package/scripts/lib/activation/adapters/vscode.js +39 -0
- package/scripts/lib/activation/adapters/windsurf.js +37 -0
- package/scripts/lib/activation/ai-surface-detector.js +151 -0
- package/scripts/lib/activation/connect-account.js +145 -0
- package/scripts/lib/activation/detect-environment.js +75 -0
- package/scripts/lib/activation/detect-hosts.js +62 -0
- package/scripts/lib/activation/format-activation-output.js +109 -0
- package/scripts/lib/activation/next-action.js +43 -0
- package/scripts/lib/activation/repair-engine.js +219 -0
- package/scripts/lib/activation-distribution-readiness.js +507 -0
- package/scripts/lib/adapter-conformance.js +176 -0
- package/scripts/lib/adapter-readiness.js +417 -0
- package/scripts/lib/adapter-safety-boundaries.js +335 -0
- package/scripts/lib/adapter-technical-readiness-gate.js +205 -0
- package/scripts/lib/agent-access-governance.js +455 -0
- package/scripts/lib/agent-enforcement.js +765 -0
- package/scripts/lib/agent-policy-profile.js +210 -0
- package/scripts/lib/agent-security/action-evaluator.js +507 -0
- package/scripts/lib/agent-security/adapter-registry.js +98 -0
- package/scripts/lib/agent-security/auto-policy.js +139 -0
- package/scripts/lib/agent-security/bounded-scan.js +93 -0
- package/scripts/lib/agent-security/enforcement-adapter.js +174 -0
- package/scripts/lib/agent-security/enforcement-engine.js +1129 -0
- package/scripts/lib/agent-security/file-write-adapter.js +183 -0
- package/scripts/lib/agent-security/file-write-rules.js +178 -0
- package/scripts/lib/agent-security/index.js +3342 -0
- package/scripts/lib/agent-security/instruction-risk.js +181 -0
- package/scripts/lib/agent-security/mcp-action-adapter.js +185 -0
- package/scripts/lib/agent-security/mcp-action-rules.js +184 -0
- package/scripts/lib/agent-security/package-action-adapter.js +175 -0
- package/scripts/lib/agent-security/package-action-rules.js +233 -0
- package/scripts/lib/agent-security/performance.js +148 -0
- package/scripts/lib/agent-security/permission-minimizer.js +403 -0
- package/scripts/lib/agent-security/scan-cache.js +74 -0
- package/scripts/lib/agent-security/source-trust.js +146 -0
- package/scripts/lib/ai-install-prompt.js +288 -0
- package/scripts/lib/ai-workspace-hygiene.js +1499 -0
- package/scripts/lib/alpha-activation.js +520 -0
- package/scripts/lib/alpha-feedback.js +263 -0
- package/scripts/lib/alpha-readiness-gate.js +332 -0
- package/scripts/lib/anti-gaming.js +169 -0
- package/scripts/lib/artifact-health.js +431 -0
- package/scripts/lib/attribution.js +180 -0
- package/scripts/lib/audit.js +289 -0
- package/scripts/lib/avorelo-skill-registry.js +810 -0
- package/scripts/lib/batch-jobs.js +71 -0
- package/scripts/lib/brain-pack.js +578 -0
- package/scripts/lib/brand-boundary.js +424 -0
- package/scripts/lib/brand.js +74 -0
- package/scripts/lib/browser-capability.js +1048 -0
- package/scripts/lib/browser-proof-preflight.js +321 -0
- package/scripts/lib/cache-readiness.js +187 -0
- package/scripts/lib/canonical-reentry.js +162 -0
- package/scripts/lib/capability-packs.js +314 -0
- package/scripts/lib/capability-recommender.js +512 -0
- package/scripts/lib/capability-registry.js +1059 -0
- package/scripts/lib/carry-forward-surfacing.js +194 -0
- package/scripts/lib/ccusage-adapter.js +188 -0
- package/scripts/lib/company-loop.js +1149 -0
- package/scripts/lib/config.js +637 -0
- package/scripts/lib/context-acquisition-plan.js +287 -0
- package/scripts/lib/context-budget-guard.js +170 -0
- package/scripts/lib/context-budget-scanner.js +257 -0
- package/scripts/lib/context-optimizer.js +715 -0
- package/scripts/lib/context-reduction-plan.js +178 -0
- package/scripts/lib/context-safety.js +88 -0
- package/scripts/lib/context-savings-engine.js +158 -0
- package/scripts/lib/cost-evidence.js +254 -0
- package/scripts/lib/cross-host-install-plan.js +308 -0
- package/scripts/lib/cross-host-install-readiness.js +237 -0
- package/scripts/lib/cross-host-value-flow.js +268 -0
- package/scripts/lib/dashboard.js +900 -0
- package/scripts/lib/design-partner-feedback.js +346 -0
- package/scripts/lib/entitlements.js +100 -0
- package/scripts/lib/execution-packet.js +559 -0
- package/scripts/lib/experimentation-events.js +547 -0
- package/scripts/lib/external-capability-compliance.js +107 -0
- package/scripts/lib/external-user-simulation.js +166 -0
- package/scripts/lib/failure-recovery-readiness.js +81 -0
- package/scripts/lib/failure-recovery.js +419 -0
- package/scripts/lib/feedback-intelligence.js +537 -0
- package/scripts/lib/feedback-signals.js +205 -0
- package/scripts/lib/file-integrity.js +68 -0
- package/scripts/lib/fsx.js +127 -0
- package/scripts/lib/full-readiness-gate.js +451 -0
- package/scripts/lib/guidance-builder.js +174 -0
- package/scripts/lib/hook-apply.js +1019 -0
- package/scripts/lib/hook-baseline.js +310 -0
- package/scripts/lib/hook-config-preview.js +275 -0
- package/scripts/lib/hook-contracts.js +290 -0
- package/scripts/lib/hook-safety-boundary-readiness.js +80 -0
- package/scripts/lib/host-capability-matrix.js +351 -0
- package/scripts/lib/host-support-context.js +254 -0
- package/scripts/lib/http-hook-action.js +538 -0
- package/scripts/lib/install-ai-readiness.js +84 -0
- package/scripts/lib/install-intake-risk.js +1037 -0
- package/scripts/lib/install-journey-intelligence.js +329 -0
- package/scripts/lib/intervention-guidance.js +57 -0
- package/scripts/lib/known-limitations.js +115 -0
- package/scripts/lib/l8-path-truth.js +146 -0
- package/scripts/lib/launch-hardening-gate.js +436 -0
- package/scripts/lib/launch-readiness.js +628 -0
- package/scripts/lib/learning-memory.js +686 -0
- package/scripts/lib/lifecycle-hooks.js +802 -0
- package/scripts/lib/local-package-smoke.js +423 -0
- package/scripts/lib/local-pricing.js +299 -0
- package/scripts/lib/mcp-enforcement.js +311 -0
- package/scripts/lib/mcp-least-privilege-policy.js +303 -0
- package/scripts/lib/mcp-tool-inventory.js +388 -0
- package/scripts/lib/mcp-tool-risk.js +0 -0
- package/scripts/lib/memory.js +335 -0
- package/scripts/lib/metrics.js +699 -0
- package/scripts/lib/micro-proof.js +133 -0
- package/scripts/lib/next-run-context.js +436 -0
- package/scripts/lib/operating-value.js +1648 -0
- package/scripts/lib/optimization-v3.js +122 -0
- package/scripts/lib/orchestration/adapters/_shared.js +49 -0
- package/scripts/lib/orchestration/adapters/aider.js +18 -0
- package/scripts/lib/orchestration/adapters/claude-code.js +35 -0
- package/scripts/lib/orchestration/adapters/codex.js +35 -0
- package/scripts/lib/orchestration/adapters/gemini-cli.js +18 -0
- package/scripts/lib/orchestration/adapters/git.js +25 -0
- package/scripts/lib/orchestration/adapters/index.js +31 -0
- package/scripts/lib/orchestration/adapters/lm-studio.js +18 -0
- package/scripts/lib/orchestration/adapters/ollama.js +18 -0
- package/scripts/lib/orchestration/adapters/opencode.js +18 -0
- package/scripts/lib/orchestration/adapters/openrouter.js +18 -0
- package/scripts/lib/orchestration/adapters/test-runner.js +25 -0
- package/scripts/lib/orchestration/cli.js +438 -0
- package/scripts/lib/orchestration/execution-manager.js +279 -0
- package/scripts/lib/orchestration/handoff.js +314 -0
- package/scripts/lib/orchestration/index.js +456 -0
- package/scripts/lib/orchestration/inventory.js +47 -0
- package/scripts/lib/orchestration/model-discovery.js +498 -0
- package/scripts/lib/orchestration/model-profiler.js +170 -0
- package/scripts/lib/orchestration/model-profiles.js +252 -0
- package/scripts/lib/orchestration/model-refresh-policy.js +72 -0
- package/scripts/lib/orchestration/proof-writer.js +349 -0
- package/scripts/lib/orchestration/provider-discovery/aider.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/claude-code.js +56 -0
- package/scripts/lib/orchestration/provider-discovery/codex.js +49 -0
- package/scripts/lib/orchestration/provider-discovery/common.js +186 -0
- package/scripts/lib/orchestration/provider-discovery/gemini.js +106 -0
- package/scripts/lib/orchestration/provider-discovery/lm-studio.js +118 -0
- package/scripts/lib/orchestration/provider-discovery/models-dev.js +12 -0
- package/scripts/lib/orchestration/provider-discovery/ollama.js +100 -0
- package/scripts/lib/orchestration/provider-discovery/opencode.js +47 -0
- package/scripts/lib/orchestration/provider-discovery/openrouter.js +44 -0
- package/scripts/lib/orchestration/risk-classifier.js +130 -0
- package/scripts/lib/orchestration/routing-policy.js +486 -0
- package/scripts/lib/orchestration/settings.js +112 -0
- package/scripts/lib/orchestration/state.js +165 -0
- package/scripts/lib/orchestration/verification-manager.js +138 -0
- package/scripts/lib/output-profiles.js +146 -0
- package/scripts/lib/package-content-audit.js +368 -0
- package/scripts/lib/package-runtime.js +278 -0
- package/scripts/lib/plan-surface.js +53 -0
- package/scripts/lib/plans.js +2318 -0
- package/scripts/lib/policy-provider.js +27 -0
- package/scripts/lib/prelaunch-activation-readiness.js +409 -0
- package/scripts/lib/prelaunch-evidence-store.js +816 -0
- package/scripts/lib/prelaunch-intelligence.js +869 -0
- package/scripts/lib/pricing-experiment.js +118 -0
- package/scripts/lib/pro-moment-events.js +77 -0
- package/scripts/lib/pro-moment-state.js +227 -0
- package/scripts/lib/pro-moments.js +1216 -0
- package/scripts/lib/product-learning-events.js +629 -0
- package/scripts/lib/project-profile.js +555 -0
- package/scripts/lib/prompt-compiler.js +280 -0
- package/scripts/lib/prompt-lint.js +32 -0
- package/scripts/lib/prompt-suggestions.js +52 -0
- package/scripts/lib/proof-canonical.js +398 -0
- package/scripts/lib/proof-drilldown.js +383 -0
- package/scripts/lib/proof-events.js +342 -0
- package/scripts/lib/proof-history.js +243 -0
- package/scripts/lib/proof-metrics.js +296 -0
- package/scripts/lib/proof-outcome-evidence.js +134 -0
- package/scripts/lib/proof-receipt.js +335 -0
- package/scripts/lib/proof-record.js +461 -0
- package/scripts/lib/public-activation-distribution-gate.js +258 -0
- package/scripts/lib/public-cli.js +3891 -0
- package/scripts/lib/public-distribution-truth.js +211 -0
- package/scripts/lib/public-install-claim-checker.js +294 -0
- package/scripts/lib/publish-provenance-readiness.js +283 -0
- package/scripts/lib/readiness-delta.js +218 -0
- package/scripts/lib/readiness-evidence-closure.js +196 -0
- package/scripts/lib/reentry-memory-capture.js +241 -0
- package/scripts/lib/reentry-memory-retrieval.js +302 -0
- package/scripts/lib/reentry-memory-status.js +146 -0
- package/scripts/lib/reentry-memory-store.js +178 -0
- package/scripts/lib/reentry-state.js +66 -0
- package/scripts/lib/release-candidate-bundle.js +166 -0
- package/scripts/lib/remediation.js +81 -0
- package/scripts/lib/repo-map.js +391 -0
- package/scripts/lib/run-improvements-lifecycle.js +330 -0
- package/scripts/lib/run-improvements.js +789 -0
- package/scripts/lib/runtime-decision-policy.js +387 -0
- package/scripts/lib/safe-path-engine.js +705 -0
- package/scripts/lib/safe-run-controller.js +887 -0
- package/scripts/lib/score.js +262 -0
- package/scripts/lib/seamless-enforcement.js +329 -0
- package/scripts/lib/seamless-outcome.js +689 -0
- package/scripts/lib/seamless-reality-gate.js +5043 -0
- package/scripts/lib/security-risk-classifier.js +511 -0
- package/scripts/lib/security-scan.js +384 -0
- package/scripts/lib/session-context-optimizer.js +1211 -0
- package/scripts/lib/session-timing.js +315 -0
- package/scripts/lib/skill-hygiene.js +805 -0
- package/scripts/lib/skill-packs.js +161 -0
- package/scripts/lib/skills-operating-layer.js +580 -0
- package/scripts/lib/smart-work-routing.js +768 -0
- package/scripts/lib/source-catalog.js +700 -0
- package/scripts/lib/status-value-summary.js +32 -0
- package/scripts/lib/support-bundle.js +578 -0
- package/scripts/lib/task-continuation.js +440 -0
- package/scripts/lib/test-helpers.js +15 -0
- package/scripts/lib/tier.js +38 -0
- package/scripts/lib/token-context-quality-gate.js +370 -0
- package/scripts/lib/token-cost-capture.js +187 -0
- package/scripts/lib/token-cost-intelligence.js +358 -0
- package/scripts/lib/token-efficiency-evidence.js +213 -0
- package/scripts/lib/token-evidence.js +699 -0
- package/scripts/lib/tokenish.js +17 -0
- package/scripts/lib/tool-output-sandbox.js +304 -0
- package/scripts/lib/trust-audit.js +136 -0
- package/scripts/lib/unified-events.js +396 -0
- package/scripts/lib/upgrade-interruption-recovery.js +407 -0
- package/scripts/lib/usage-ledger.js +201 -0
- package/scripts/lib/value-ledger.js +130 -0
- package/scripts/lib/value-proof-calibration.js +531 -0
- package/scripts/lib/visual-qa.js +231 -0
- package/scripts/lib/voice-alpha.js +29 -0
- package/scripts/lib/work-aware-orchestration.js +976 -0
- package/scripts/lib/work-control-receipts.js +577 -0
- package/scripts/lib/work-ledger.js +1123 -0
- package/scripts/lib/work-panel-preview.js +352 -0
- package/scripts/lib/workflow-discipline.js +280 -0
- package/scripts/lib/workflow-signals.js +419 -0
- package/scripts/lib/workspace-map.js +281 -0
- package/scripts/lib/workspace-registry.js +1367 -0
- package/scripts/lib/workspace-resolver.js +480 -0
|
@@ -0,0 +1,507 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
};
|