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,765 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const crypto = require("crypto");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
|
-
const { ensureCcoDirs, safeReadJson, safeWriteJson, nowIso } = require("./fsx");
|
|
7
|
-
const { canExportReports, getCurrentPlan } = require("./entitlements");
|
|
8
|
-
const { buildTaskContinuation } = require("./task-continuation");
|
|
9
|
-
const { buildPolicyProfile, describePolicyProfile } = require("./agent-policy-profile");
|
|
10
|
-
const {
|
|
11
|
-
buildGovernanceReceipt,
|
|
12
|
-
writeGovernanceReceipt,
|
|
13
|
-
applyGovernanceDecisionFloor,
|
|
14
|
-
buildAgentAccessGovernanceSurface,
|
|
15
|
-
} = require("./agent-access-governance");
|
|
16
|
-
const {
|
|
17
|
-
buildSafePathReceipt,
|
|
18
|
-
writeSafePathReceipt,
|
|
19
|
-
buildSafePathSurface,
|
|
20
|
-
recordSafePathLearningSignals,
|
|
21
|
-
} = require("./safe-path-engine");
|
|
22
|
-
const {
|
|
23
|
-
buildActionIntakeContext,
|
|
24
|
-
LATEST_INSTALL_INTAKE_RECEIPT_REL_PATH,
|
|
25
|
-
} = require("./install-intake-risk");
|
|
26
|
-
const { appendProductLearningEvent } = require("./product-learning-events");
|
|
27
|
-
const {
|
|
28
|
-
maxRisk,
|
|
29
|
-
classifyActionRisk,
|
|
30
|
-
classifyPathRisk,
|
|
31
|
-
classifyCommandRisk,
|
|
32
|
-
classifyToolRisk,
|
|
33
|
-
classifyBrowserRisk,
|
|
34
|
-
classifyInstructionRisk,
|
|
35
|
-
classifyPromptInjectionRisk,
|
|
36
|
-
classifySourceTrustRisk,
|
|
37
|
-
classifyIntentMismatchRisk,
|
|
38
|
-
classifySecretExposureRisk,
|
|
39
|
-
classifyExternalExportRisk,
|
|
40
|
-
} = require("./security-risk-classifier");
|
|
41
|
-
|
|
42
|
-
const DECISIONS = Object.freeze(["allow", "warn", "approval_required", "block"]);
|
|
43
|
-
const EVIDENCE_DIR_REL_PATH = ".claude/cco/evidence/agent-security";
|
|
44
|
-
const LATEST_EVIDENCE_REL_PATH = `${EVIDENCE_DIR_REL_PATH}/latest-enforcement.json`;
|
|
45
|
-
const HISTORY_DIR_REL_PATH = `${EVIDENCE_DIR_REL_PATH}/history`;
|
|
46
|
-
const EVENT_LOG_REL_PATH = ".claude/cco/events/agent-security-enforcement.jsonl";
|
|
47
|
-
const SCHEMA_VERSION = 1;
|
|
48
|
-
|
|
49
|
-
function sha256(value) {
|
|
50
|
-
return crypto.createHash("sha256").update(String(value || "")).digest("hex");
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function stableStringify(value) {
|
|
54
|
-
if (Array.isArray(value)) {
|
|
55
|
-
return `[${value.map((item) => stableStringify(item)).join(",")}]`;
|
|
56
|
-
}
|
|
57
|
-
if (value && typeof value === "object") {
|
|
58
|
-
return `{${Object.keys(value)
|
|
59
|
-
.sort((left, right) => left.localeCompare(right))
|
|
60
|
-
.map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`)
|
|
61
|
-
.join(",")}}`;
|
|
62
|
-
}
|
|
63
|
-
return JSON.stringify(value);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function unique(values) {
|
|
67
|
-
return [...new Set((values || []).filter(Boolean))];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function normalizeActionType(value) {
|
|
71
|
-
const actionType = String(value || "unknown").trim().toLowerCase();
|
|
72
|
-
return actionType || "unknown";
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function normalizePathList(value) {
|
|
76
|
-
const list = Array.isArray(value) ? value : value ? [value] : [];
|
|
77
|
-
return list.map((item) => String(item || "").replace(/\\/g, "/").trim()).filter(Boolean);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function redactSecrets(value) {
|
|
81
|
-
if (Array.isArray(value)) {
|
|
82
|
-
return value.map((item) => redactSecrets(item));
|
|
83
|
-
}
|
|
84
|
-
if (value && typeof value === "object") {
|
|
85
|
-
const out = {};
|
|
86
|
-
Object.keys(value).forEach((key) => {
|
|
87
|
-
out[key] = redactSecrets(value[key]);
|
|
88
|
-
});
|
|
89
|
-
return out;
|
|
90
|
-
}
|
|
91
|
-
if (typeof value !== "string") {
|
|
92
|
-
return value;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
return value
|
|
96
|
-
.replace(/sk-[A-Za-z0-9]{16,}/g, "[redacted-openai-key]")
|
|
97
|
-
.replace(/ghp_[A-Za-z0-9]{20,}/g, "[redacted-github-token]")
|
|
98
|
-
.replace(/AKIA[0-9A-Z]{16}/g, "[redacted-aws-key]")
|
|
99
|
-
.replace(/(bearer\s+)[A-Za-z0-9._-]{8,}/ig, "$1[redacted]")
|
|
100
|
-
.replace(/((?:api[_ -]?key|token|password|secret|authorization)\s*[:=]\s*)([^\s'"]+)/ig, "$1[redacted]")
|
|
101
|
-
.replace(/(-----BEGIN [A-Z ]+-----)[\s\S]{0,4000}?(-----END [A-Z ]+-----)/g, "$1 [redacted] $2");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function appendJsonl(cwd, relPathValue, entry) {
|
|
105
|
-
const absPath = path.join(cwd, relPathValue);
|
|
106
|
-
fs.mkdirSync(path.dirname(absPath), { recursive: true });
|
|
107
|
-
fs.appendFileSync(absPath, `${JSON.stringify(entry)}\n`, "utf8");
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function buildDecisionId(input, plan) {
|
|
111
|
-
return `guard-${sha256(stableStringify({ plan, input })).slice(0, 12)}`;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function buildSanitizedInputSummary(input = {}) {
|
|
115
|
-
return redactSecrets({
|
|
116
|
-
actionType: normalizeActionType(input.actionType),
|
|
117
|
-
requestedBy: input.requestedBy || "unknown",
|
|
118
|
-
taskType: input.taskType || null,
|
|
119
|
-
userIntent: input.userIntent || null,
|
|
120
|
-
targetPaths: normalizePathList(input.targetPaths || input.target || []),
|
|
121
|
-
command: input.command || null,
|
|
122
|
-
toolName: input.toolName || null,
|
|
123
|
-
mcpServer: input.mcpServer || null,
|
|
124
|
-
domain: input.domain || null,
|
|
125
|
-
url: input.url || input.target || null,
|
|
126
|
-
skillPackIds: Array.isArray(input.skillPackIds) ? input.skillPackIds : [],
|
|
127
|
-
sourceTrust: input.sourceTrust || null,
|
|
128
|
-
instructionText: input.instructionText ? redactSecrets(String(input.instructionText).slice(0, 300)) : null,
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function classifyAction(input = {}) {
|
|
133
|
-
const actionType = normalizeActionType(input.actionType);
|
|
134
|
-
const pathRisk = classifyPathRisk(input.targetPaths || input.target || [], input);
|
|
135
|
-
const commandRisk = classifyCommandRisk(input.command || input.target || "");
|
|
136
|
-
const toolRisk = classifyToolRisk({
|
|
137
|
-
toolName: input.toolName,
|
|
138
|
-
mcpServer: input.mcpServer,
|
|
139
|
-
metadata: input.toolMetadata,
|
|
140
|
-
});
|
|
141
|
-
const browserRisk = classifyBrowserRisk({
|
|
142
|
-
url: input.url || input.target,
|
|
143
|
-
domain: input.domain,
|
|
144
|
-
domainBoundaryReady: input.domainBoundaryReady,
|
|
145
|
-
cookieAccess: input.cookieAccess,
|
|
146
|
-
sessionAccess: input.sessionAccess,
|
|
147
|
-
secretAccess: input.secretAccess,
|
|
148
|
-
});
|
|
149
|
-
const instructionRisk = classifyInstructionRisk({
|
|
150
|
-
text: input.instructionText,
|
|
151
|
-
sourceTrust: input.sourceTrust,
|
|
152
|
-
sourceType: input.sourceType,
|
|
153
|
-
});
|
|
154
|
-
const promptInjectionRisk = classifyPromptInjectionRisk({
|
|
155
|
-
text: input.instructionText,
|
|
156
|
-
sourceTrust: input.sourceTrust,
|
|
157
|
-
sourceType: input.sourceType,
|
|
158
|
-
});
|
|
159
|
-
const sourceTrustRisk = classifySourceTrustRisk(input);
|
|
160
|
-
const intentMismatchRisk = classifyIntentMismatchRisk(input);
|
|
161
|
-
const secretExposureRisk = classifySecretExposureRisk(input);
|
|
162
|
-
const externalExportRisk = classifyExternalExportRisk(input);
|
|
163
|
-
const combined = classifyActionRisk(input);
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
actionType,
|
|
167
|
-
pathRisk,
|
|
168
|
-
commandRisk,
|
|
169
|
-
toolRisk,
|
|
170
|
-
browserRisk,
|
|
171
|
-
instructionRisk,
|
|
172
|
-
promptInjectionRisk,
|
|
173
|
-
sourceTrustRisk,
|
|
174
|
-
intentMismatchRisk,
|
|
175
|
-
secretExposureRisk,
|
|
176
|
-
externalExportRisk,
|
|
177
|
-
combined,
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function getMatchedRules(input = {}, classification, profile) {
|
|
182
|
-
const actionType = classification.actionType;
|
|
183
|
-
const rules = [];
|
|
184
|
-
const risk = classification.combined;
|
|
185
|
-
const reasons = new Set(risk.reasonCodes || []);
|
|
186
|
-
const intakeReasons = new Set(input.intakeContext?.reasonCodes || []);
|
|
187
|
-
const isSensitiveFileWrite = (actionType === "file_write" || actionType === "config_change")
|
|
188
|
-
&& (reasons.has("SENSITIVE_ENV_FILE") || reasons.has("SECRET_LIKE_TARGET") || reasons.has("AUTH_OR_BILLING_SCOPE") || reasons.has("DEPLOYMENT_CONFIG") || reasons.has("CI_CONFIG"));
|
|
189
|
-
const hasPromptInjection = input.hasPromptInjectionSignal === true || reasons.has("PROMPT_INJECTION_SIGNAL");
|
|
190
|
-
const hasIntentMismatch = input.hasIntentMismatchSignal === true || reasons.has("INTENT_MISMATCH") || reasons.has("OUT_OF_SCOPE_FILE_CHANGE");
|
|
191
|
-
const browserExternal = (actionType === "browser_action" || actionType === "visual_qa_run") && reasons.has("BROWSER_EXTERNAL_DOMAIN");
|
|
192
|
-
const browserSecretRisk = reasons.has("BROWSER_COOKIE_OR_SESSION_RISK");
|
|
193
|
-
const unknownTool = reasons.has("UNKNOWN_MCP_TOOL");
|
|
194
|
-
const writeCapableTool = reasons.has("WRITE_CAPABLE_TOOL");
|
|
195
|
-
const destructiveCommand = reasons.has("DESTRUCTIVE_COMMAND") || reasons.has("FORCE_PUSH_OR_HISTORY_REWRITE");
|
|
196
|
-
const externalExport = reasons.has("EXTERNAL_REPO_EXPORT");
|
|
197
|
-
const externalNetwork = reasons.has("EXTERNAL_NETWORK_REQUEST");
|
|
198
|
-
const localhostVisualQa = actionType === "visual_qa_run" && reasons.has("VISUAL_QA_LOCAL_TARGET");
|
|
199
|
-
const secretExposure = actionType === "secret_access" || reasons.has("SECRET_LIKE_TARGET") && (actionType === "network_request" || actionType === "tool_call" || actionType === "mcp_tool_call");
|
|
200
|
-
const blockedIntake = input.intakeContext?.matchedItems?.some((item) => item.reviewStatus === "blocked");
|
|
201
|
-
const riskyInstallIntake =
|
|
202
|
-
intakeReasons.has("UNKNOWN_PACKAGE_INSTALL")
|
|
203
|
-
|| intakeReasons.has("PACKAGE_NON_REGISTRY_SOURCE")
|
|
204
|
-
|| intakeReasons.has("INSTALL_SCRIPT_PRESENT")
|
|
205
|
-
|| intakeReasons.has("NETWORK_SCRIPT_PRESENT")
|
|
206
|
-
|| intakeReasons.has("DESTRUCTIVE_SCRIPT_PRESENT")
|
|
207
|
-
|| intakeReasons.has("UNKNOWN_MCP_SOURCE")
|
|
208
|
-
|| intakeReasons.has("UNKNOWN_EXTENSION_SOURCE");
|
|
209
|
-
|
|
210
|
-
if (actionType === "prompt_compile") {
|
|
211
|
-
rules.push({ id: "safe_prompt_compile_allow", outcome: "allow", summary: "Safe prompt compilation stays local." });
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (localhostVisualQa) {
|
|
215
|
-
rules.push({
|
|
216
|
-
id: "local_visual_qa_allow",
|
|
217
|
-
outcome: input.runnerAvailable === false ? "warn" : "allow",
|
|
218
|
-
summary: input.runnerAvailable === false
|
|
219
|
-
? "Local Visual QA target is safe, but the local runner is unavailable."
|
|
220
|
-
: "Local Visual QA target stays inside localhost scope.",
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
if (isSensitiveFileWrite) {
|
|
225
|
-
rules.push({
|
|
226
|
-
id: "sensitive_file_write_guard",
|
|
227
|
-
outcome: reasons.has("SECRET_LIKE_TARGET") || reasons.has("SENSITIVE_ENV_FILE") ? "approval_required" : "warn",
|
|
228
|
-
summary: "Sensitive file writes need a narrower scope or explicit approval.",
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (secretExposure) {
|
|
233
|
-
rules.push({
|
|
234
|
-
id: "secret_exposure_block",
|
|
235
|
-
outcome: "block",
|
|
236
|
-
summary: "Secret access or exposure is not allowed.",
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if (blockedIntake) {
|
|
241
|
-
rules.push({
|
|
242
|
-
id: "blocked_intake_guard",
|
|
243
|
-
outcome: "block",
|
|
244
|
-
summary: "The requested runtime surface is blocked by local intake review and must not be trusted automatically.",
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (hasPromptInjection && (isSensitiveFileWrite || writeCapableTool || externalExport || browserExternal || externalNetwork)) {
|
|
249
|
-
rules.push({
|
|
250
|
-
id: "prompt_injection_sensitive_action_guard",
|
|
251
|
-
outcome: risk.riskLevel === "critical" ? "block" : "approval_required",
|
|
252
|
-
summary: "Prompt-injection signals plus a sensitive action require a hard stop or approval.",
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
if (hasIntentMismatch) {
|
|
257
|
-
rules.push({
|
|
258
|
-
id: "intent_mismatch_guard",
|
|
259
|
-
outcome: profile.plan === "pro" && risk.riskLevel !== "low" ? "approval_required" : "warn",
|
|
260
|
-
summary: "The requested action does not match the user’s stated task.",
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (browserExternal) {
|
|
265
|
-
rules.push({
|
|
266
|
-
id: "browser_external_domain_guard",
|
|
267
|
-
outcome: profile.plan === "pro" ? "approval_required" : "warn",
|
|
268
|
-
summary: "External browser targets need a boundary or review before proceeding.",
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
if (browserSecretRisk) {
|
|
273
|
-
rules.push({
|
|
274
|
-
id: "browser_cookie_session_block",
|
|
275
|
-
outcome: "block",
|
|
276
|
-
summary: "Browser actions touching cookies, sessions, or secrets are blocked.",
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (unknownTool) {
|
|
281
|
-
rules.push({
|
|
282
|
-
id: "unknown_tool_guard",
|
|
283
|
-
outcome: profile.plan === "pro" ? "approval_required" : "warn",
|
|
284
|
-
summary: "Unknown tools and MCP targets should not be blindly trusted.",
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (riskyInstallIntake) {
|
|
289
|
-
rules.push({
|
|
290
|
-
id: "install_intake_review_guard",
|
|
291
|
-
outcome: profile.plan === "pro" || blockedIntake ? "approval_required" : "warn",
|
|
292
|
-
summary: "Local intake signals show this package, MCP, extension, or guidance surface needs review before normal runtime trust.",
|
|
293
|
-
});
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (writeCapableTool) {
|
|
297
|
-
rules.push({
|
|
298
|
-
id: "write_capable_tool_guard",
|
|
299
|
-
outcome: profile.plan === "pro" ? "approval_required" : "warn",
|
|
300
|
-
summary: "Write-capable tools require a narrower reviewed scope.",
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (destructiveCommand) {
|
|
305
|
-
rules.push({
|
|
306
|
-
id: "destructive_command_block",
|
|
307
|
-
outcome: "block",
|
|
308
|
-
summary: "Destructive commands are blocked.",
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if (externalExport) {
|
|
313
|
-
rules.push({
|
|
314
|
-
id: "external_export_guard",
|
|
315
|
-
outcome: "block",
|
|
316
|
-
summary: "External repository export is blocked by default.",
|
|
317
|
-
});
|
|
318
|
-
} else if (externalNetwork) {
|
|
319
|
-
rules.push({
|
|
320
|
-
id: "external_network_guard",
|
|
321
|
-
outcome: profile.plan === "pro" ? "approval_required" : "warn",
|
|
322
|
-
summary: "External network requests need scoped review.",
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
if ((actionType === "tool_call" || actionType === "mcp_tool_call") && !unknownTool && !writeCapableTool && risk.riskLevel === "low") {
|
|
327
|
-
rules.push({
|
|
328
|
-
id: "trusted_tool_allow",
|
|
329
|
-
outcome: "allow",
|
|
330
|
-
summary: "Trusted local tool usage stays within normal scope.",
|
|
331
|
-
});
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
if ((actionType === "file_read" || actionType === "unknown") && risk.riskLevel === "low") {
|
|
335
|
-
rules.push({
|
|
336
|
-
id: "low_risk_local_read_allow",
|
|
337
|
-
outcome: "allow",
|
|
338
|
-
summary: "The action looks like a low-risk local read or inspection.",
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
if (!rules.length && risk.riskLevel === "medium") {
|
|
343
|
-
rules.push({
|
|
344
|
-
id: "medium_risk_default_warn",
|
|
345
|
-
outcome: "warn",
|
|
346
|
-
summary: "The action carries moderate uncertainty and should stay visible.",
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
if (!rules.length && risk.riskLevel === "high") {
|
|
351
|
-
rules.push({
|
|
352
|
-
id: "high_risk_default_review",
|
|
353
|
-
outcome: profile.plan === "pro" ? "approval_required" : "warn",
|
|
354
|
-
summary: "The action is high risk and should not proceed silently.",
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (!rules.length && risk.riskLevel === "critical") {
|
|
359
|
-
rules.push({
|
|
360
|
-
id: "critical_risk_default_block",
|
|
361
|
-
outcome: "block",
|
|
362
|
-
summary: "The action is critically risky and should not proceed.",
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
return rules;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
function decisionSeverity(decision) {
|
|
370
|
-
switch (decision) {
|
|
371
|
-
case "block":
|
|
372
|
-
return 4;
|
|
373
|
-
case "approval_required":
|
|
374
|
-
return 3;
|
|
375
|
-
case "warn":
|
|
376
|
-
return 2;
|
|
377
|
-
default:
|
|
378
|
-
return 1;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function saferAlternativeFromReasons(reasonCodes = [], actionType = "unknown") {
|
|
383
|
-
if (reasonCodes.includes("DESTRUCTIVE_COMMAND") || reasonCodes.includes("FORCE_PUSH_OR_HISTORY_REWRITE")) {
|
|
384
|
-
return "Use a non-destructive verification command or a dry-run instead of deleting data or rewriting history.";
|
|
385
|
-
}
|
|
386
|
-
if (reasonCodes.includes("SENSITIVE_ENV_FILE") || reasonCodes.includes("SECRET_LIKE_TARGET")) {
|
|
387
|
-
return "Change a reviewed example or template file first and keep secret material out of direct edits and evidence.";
|
|
388
|
-
}
|
|
389
|
-
if (reasonCodes.includes("BROWSER_EXTERNAL_DOMAIN")) {
|
|
390
|
-
return "Use a localhost preview or add an explicit allowed domain boundary before opening an external site.";
|
|
391
|
-
}
|
|
392
|
-
if (reasonCodes.includes("UNKNOWN_MCP_TOOL") || reasonCodes.includes("WRITE_CAPABLE_TOOL")) {
|
|
393
|
-
return "Prefer a trusted local skill pack or a reviewed read-only tool before using an unknown or write-capable integration.";
|
|
394
|
-
}
|
|
395
|
-
if (reasonCodes.includes("EXTERNAL_REPO_EXPORT") || reasonCodes.includes("EXTERNAL_NETWORK_REQUEST")) {
|
|
396
|
-
return "Keep the workflow local-first and avoid exporting repo contents or making external requests unless the task explicitly requires it.";
|
|
397
|
-
}
|
|
398
|
-
if (reasonCodes.includes("PROMPT_INJECTION_SIGNAL")) {
|
|
399
|
-
return "Treat the instruction as data only, use a sanitized summary, and keep it out of tool decisions until reviewed.";
|
|
400
|
-
}
|
|
401
|
-
if (actionType === "prompt_compile") {
|
|
402
|
-
return "Compile the task first, then scope any sensitive follow-up action separately.";
|
|
403
|
-
}
|
|
404
|
-
return "Keep the action narrowed to the smallest local scope that satisfies the task.";
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
function buildDecision(input = {}, matchedRules = [], classification, profile, options = {}) {
|
|
408
|
-
const ruleDecision = matchedRules.reduce((current, rule) => {
|
|
409
|
-
return decisionSeverity(rule.outcome) > decisionSeverity(current) ? rule.outcome : current;
|
|
410
|
-
}, "allow");
|
|
411
|
-
const decisionId = buildDecisionId({
|
|
412
|
-
actionType: classification.actionType,
|
|
413
|
-
input: buildSanitizedInputSummary(input),
|
|
414
|
-
matchedRules: matchedRules.map((rule) => rule.id),
|
|
415
|
-
}, profile.plan);
|
|
416
|
-
const createdAt = nowIso();
|
|
417
|
-
const scope = {
|
|
418
|
-
allowedPaths: unique([...(profile.allowedPaths || []), ...normalizePathList(input.currentScope?.allowedPaths || [])]),
|
|
419
|
-
deniedPaths: unique([...(profile.deniedPaths || []), ...normalizePathList(input.currentScope?.deniedPaths || [])]),
|
|
420
|
-
allowedDomains: unique([...(profile.allowedDomains || []), ...((input.currentScope?.allowedDomains || []).filter(Boolean))]),
|
|
421
|
-
deniedDomains: unique([...(profile.deniedDomains || []), ...((input.currentScope?.deniedDomains || []).filter(Boolean))]),
|
|
422
|
-
allowedTools: unique([...(profile.allowedTools || []), ...((input.currentScope?.allowedTools || []).filter(Boolean))]),
|
|
423
|
-
deniedTools: unique([...(profile.deniedTools || []), ...((input.currentScope?.deniedTools || []).filter(Boolean))]),
|
|
424
|
-
};
|
|
425
|
-
const reasonCodes = unique([
|
|
426
|
-
...(classification.combined.reasonCodes || []),
|
|
427
|
-
...(input.intakeContext?.reasonCodes || []),
|
|
428
|
-
]);
|
|
429
|
-
const explanation = matchedRules.length
|
|
430
|
-
? matchedRules.map((rule) => rule.summary).join(" ")
|
|
431
|
-
: classification.combined.explanation || "No additional rule explanation was available.";
|
|
432
|
-
|
|
433
|
-
return {
|
|
434
|
-
decisionId,
|
|
435
|
-
decision: DECISIONS.includes(ruleDecision) ? ruleDecision : "warn",
|
|
436
|
-
actionType: classification.actionType,
|
|
437
|
-
riskLevel: classification.combined.riskLevel,
|
|
438
|
-
reasonCodes,
|
|
439
|
-
matchedRules: matchedRules.map((rule) => rule.id),
|
|
440
|
-
explanation,
|
|
441
|
-
saferAlternative: (() => {
|
|
442
|
-
const ruleDecisionFinal = DECISIONS.includes(ruleDecision) ? ruleDecision : "warn";
|
|
443
|
-
const continuation = buildTaskContinuation({
|
|
444
|
-
actionType: classification.actionType,
|
|
445
|
-
target: input.target || input.command || input.url || input.toolName || "",
|
|
446
|
-
task: input.userIntent || input.taskType || "",
|
|
447
|
-
riskLevel: classification.combined.riskLevel,
|
|
448
|
-
decision: ruleDecisionFinal,
|
|
449
|
-
reasonCodes,
|
|
450
|
-
});
|
|
451
|
-
// Task-continuation is primary; fall back to intake action only as a supplement
|
|
452
|
-
const intakeAction = input.intakeContext?.safeNextAction;
|
|
453
|
-
const taskAction = continuation.safeNextAction;
|
|
454
|
-
return sanitizeText(taskAction || intakeAction || "Keep the action narrowed to the smallest local scope.");
|
|
455
|
-
})(),
|
|
456
|
-
requiresApproval: ruleDecision === "approval_required",
|
|
457
|
-
blocked: ruleDecision === "block",
|
|
458
|
-
scope,
|
|
459
|
-
ttlSeconds: ruleDecision === "approval_required" ? Number(profile.ttlSeconds || 0) : null,
|
|
460
|
-
evidencePath: null,
|
|
461
|
-
createdAt,
|
|
462
|
-
plan: profile.plan,
|
|
463
|
-
mode: profile.mode,
|
|
464
|
-
sanitizedInputSummary: buildSanitizedInputSummary(input),
|
|
465
|
-
schemaVersion: SCHEMA_VERSION,
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function sanitizeText(value) {
|
|
470
|
-
return redactSecrets(String(value || ""));
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function recordGovernanceLearningSignals(cwd, receipt) {
|
|
474
|
-
const events = [
|
|
475
|
-
{
|
|
476
|
-
eventName: "access_governance_evaluated",
|
|
477
|
-
category: "access_governance",
|
|
478
|
-
status: receipt.decision,
|
|
479
|
-
payload: {
|
|
480
|
-
subjectType: receipt.subjectSummary.type,
|
|
481
|
-
trustStatus: receipt.subjectSummary.trustStatus,
|
|
482
|
-
actionType: receipt.requestedActionSummary.type,
|
|
483
|
-
decision: receipt.decision,
|
|
484
|
-
reasonCodes: receipt.reasonCodes,
|
|
485
|
-
},
|
|
486
|
-
},
|
|
487
|
-
{
|
|
488
|
-
eventName: "access_receipt_written",
|
|
489
|
-
category: "access_governance",
|
|
490
|
-
status: "recorded",
|
|
491
|
-
payload: {
|
|
492
|
-
decisionId: receipt.decisionId,
|
|
493
|
-
subjectType: receipt.subjectSummary.type,
|
|
494
|
-
trustStatus: receipt.subjectSummary.trustStatus,
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
];
|
|
498
|
-
|
|
499
|
-
if (receipt.subjectSummary.trustStatus === "unknown") {
|
|
500
|
-
events.push({
|
|
501
|
-
eventName: "access_subject_unknown",
|
|
502
|
-
category: "access_governance",
|
|
503
|
-
status: receipt.decision,
|
|
504
|
-
payload: {
|
|
505
|
-
subjectType: receipt.subjectSummary.type,
|
|
506
|
-
requestedActionType: receipt.requestedActionSummary.type,
|
|
507
|
-
},
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
if (receipt.decision === "approval_required") {
|
|
512
|
-
events.push({
|
|
513
|
-
eventName: "access_scope_requires_approval",
|
|
514
|
-
category: "access_governance",
|
|
515
|
-
status: "approval_required",
|
|
516
|
-
payload: {
|
|
517
|
-
subjectType: receipt.subjectSummary.type,
|
|
518
|
-
requestedActionType: receipt.requestedActionSummary.type,
|
|
519
|
-
},
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
if (receipt.decision === "block") {
|
|
524
|
-
events.push({
|
|
525
|
-
eventName: "access_blocked",
|
|
526
|
-
category: "access_governance",
|
|
527
|
-
status: "blocked",
|
|
528
|
-
payload: {
|
|
529
|
-
subjectType: receipt.subjectSummary.type,
|
|
530
|
-
reasonCodes: receipt.reasonCodes,
|
|
531
|
-
},
|
|
532
|
-
});
|
|
533
|
-
} else if (receipt.decision === "warn") {
|
|
534
|
-
events.push({
|
|
535
|
-
eventName: "access_warned",
|
|
536
|
-
category: "access_governance",
|
|
537
|
-
status: "warned",
|
|
538
|
-
payload: {
|
|
539
|
-
subjectType: receipt.subjectSummary.type,
|
|
540
|
-
reasonCodes: receipt.reasonCodes,
|
|
541
|
-
},
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
|
|
545
|
-
events.forEach((event) => {
|
|
546
|
-
try {
|
|
547
|
-
appendProductLearningEvent(cwd, event);
|
|
548
|
-
} catch {}
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
function writeEnforcementEvidence(decision, options = {}) {
|
|
553
|
-
const cwd = path.resolve(options.cwd || process.cwd());
|
|
554
|
-
ensureCcoDirs(cwd);
|
|
555
|
-
|
|
556
|
-
const payload = redactSecrets({
|
|
557
|
-
schemaVersion: SCHEMA_VERSION,
|
|
558
|
-
decisionId: decision.decisionId,
|
|
559
|
-
timestamp: decision.createdAt,
|
|
560
|
-
plan: decision.plan,
|
|
561
|
-
mode: decision.mode,
|
|
562
|
-
actionType: decision.actionType,
|
|
563
|
-
sanitizedInputSummary: decision.sanitizedInputSummary,
|
|
564
|
-
decision: decision.decision,
|
|
565
|
-
riskLevel: decision.riskLevel,
|
|
566
|
-
reasonCodes: decision.reasonCodes,
|
|
567
|
-
matchedRules: decision.matchedRules,
|
|
568
|
-
saferAlternative: decision.saferAlternative,
|
|
569
|
-
source: options.source || decision.sanitizedInputSummary.requestedBy || "cli",
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
safeWriteJson(cwd, LATEST_EVIDENCE_REL_PATH, payload);
|
|
573
|
-
appendJsonl(cwd, EVENT_LOG_REL_PATH, payload);
|
|
574
|
-
|
|
575
|
-
let historyPath = null;
|
|
576
|
-
if (canExportReports(decision.plan)) {
|
|
577
|
-
historyPath = `${HISTORY_DIR_REL_PATH}/${decision.decisionId}.json`;
|
|
578
|
-
safeWriteJson(cwd, historyPath, payload);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
return historyPath || LATEST_EVIDENCE_REL_PATH;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function readLatestEnforcementEvidence(cwd) {
|
|
585
|
-
return safeReadJson(cwd, LATEST_EVIDENCE_REL_PATH, null);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
function summarizeEnforcementEvidence(cwd) {
|
|
589
|
-
try {
|
|
590
|
-
const latest = readLatestEnforcementEvidence(cwd);
|
|
591
|
-
if (!latest) return null;
|
|
592
|
-
return {
|
|
593
|
-
decisionId: latest.decisionId || null,
|
|
594
|
-
decision: latest.decision || null,
|
|
595
|
-
riskLevel: latest.riskLevel || null,
|
|
596
|
-
reasonCodes: Array.isArray(latest.reasonCodes) ? latest.reasonCodes : [],
|
|
597
|
-
matchedRules: Array.isArray(latest.matchedRules) ? latest.matchedRules : [],
|
|
598
|
-
createdAt: latest.timestamp || null,
|
|
599
|
-
summary: latest.decision
|
|
600
|
-
? `${latest.decision} ${latest.actionType || "action"} (${latest.riskLevel || "unknown"} risk)`
|
|
601
|
-
: "Latest enforcement evidence is present.",
|
|
602
|
-
};
|
|
603
|
-
} catch {
|
|
604
|
-
return {
|
|
605
|
-
decisionId: null,
|
|
606
|
-
decision: null,
|
|
607
|
-
riskLevel: null,
|
|
608
|
-
reasonCodes: [],
|
|
609
|
-
matchedRules: [],
|
|
610
|
-
createdAt: null,
|
|
611
|
-
summary: "Latest enforcement evidence is unreadable.",
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
function explainDecision(decision) {
|
|
617
|
-
return `${decision.decision} ${decision.actionType} (${decision.riskLevel} risk): ${decision.explanation}`;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
function isApprovalRequired(decision) {
|
|
621
|
-
return decision?.decision === "approval_required";
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
function isBlocked(decision) {
|
|
625
|
-
return decision?.decision === "block";
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
function evaluateAgentAction(input = {}, options = {}) {
|
|
629
|
-
const cwd = path.resolve(options.cwd || process.cwd());
|
|
630
|
-
const plan = String(input.plan || options.plan || getCurrentPlan({ cwd })).trim().toLowerCase() === "pro" ? "pro" : "free";
|
|
631
|
-
const profile = buildPolicyProfile({
|
|
632
|
-
cwd,
|
|
633
|
-
plan,
|
|
634
|
-
overrides: options.profileOverrides,
|
|
635
|
-
});
|
|
636
|
-
const intakeContext = buildActionIntakeContext(cwd, input, {
|
|
637
|
-
writeReceipt: options.writeEvidence !== false,
|
|
638
|
-
plan,
|
|
639
|
-
});
|
|
640
|
-
const enrichedInput = {
|
|
641
|
-
...input,
|
|
642
|
-
subject: input.subject || intakeContext.subject || undefined,
|
|
643
|
-
toolMetadata: {
|
|
644
|
-
...(input.toolMetadata || {}),
|
|
645
|
-
...(intakeContext.toolMetadata || {}),
|
|
646
|
-
},
|
|
647
|
-
intakeContext,
|
|
648
|
-
};
|
|
649
|
-
const classification = classifyAction(enrichedInput);
|
|
650
|
-
classification.combined = {
|
|
651
|
-
...classification.combined,
|
|
652
|
-
riskLevel: maxRisk(classification.combined.riskLevel, intakeContext.riskLevel || "low"),
|
|
653
|
-
reasonCodes: unique([
|
|
654
|
-
...(classification.combined.reasonCodes || []),
|
|
655
|
-
...(intakeContext.reasonCodes || []),
|
|
656
|
-
]),
|
|
657
|
-
explanation: [
|
|
658
|
-
classification.combined.explanation,
|
|
659
|
-
intakeContext.reasonCodes?.length ? `Install intake signals: ${(intakeContext.reasonCodes || []).join(", ")}.` : null,
|
|
660
|
-
].filter(Boolean).join(" "),
|
|
661
|
-
recommendedAction: unique([
|
|
662
|
-
classification.combined.recommendedAction,
|
|
663
|
-
intakeContext.safeNextAction,
|
|
664
|
-
]).filter(Boolean).join(" "),
|
|
665
|
-
};
|
|
666
|
-
const matchedRules = getMatchedRules(enrichedInput, classification, profile);
|
|
667
|
-
const initialDecision = buildDecision(enrichedInput, matchedRules, classification, profile, options);
|
|
668
|
-
const initialReceipt = buildGovernanceReceipt(enrichedInput, initialDecision, classification);
|
|
669
|
-
const decision = applyGovernanceDecisionFloor(initialDecision, initialReceipt);
|
|
670
|
-
const governanceReceipt = buildGovernanceReceipt(enrichedInput, decision, classification);
|
|
671
|
-
const safePathReceipt = buildSafePathReceipt(enrichedInput, decision, governanceReceipt, {
|
|
672
|
-
cwd,
|
|
673
|
-
classification,
|
|
674
|
-
profile,
|
|
675
|
-
intakeContext,
|
|
676
|
-
});
|
|
677
|
-
|
|
678
|
-
if (options.writeEvidence !== false) {
|
|
679
|
-
decision.evidencePath = writeEnforcementEvidence(decision, {
|
|
680
|
-
cwd,
|
|
681
|
-
source: input.requestedBy || options.source || "cli",
|
|
682
|
-
});
|
|
683
|
-
governanceReceipt.evidencePath = writeGovernanceReceipt(cwd, governanceReceipt, { plan });
|
|
684
|
-
decision.governanceReceiptPath = governanceReceipt.evidencePath;
|
|
685
|
-
decision.governance = governanceReceipt;
|
|
686
|
-
decision.safePathReceiptPath = writeSafePathReceipt(cwd, safePathReceipt, { plan });
|
|
687
|
-
decision.safePath = safePathReceipt;
|
|
688
|
-
decision.installIntakeReceiptPath = intakeContext.receiptPath || LATEST_INSTALL_INTAKE_RECEIPT_REL_PATH;
|
|
689
|
-
decision.installIntake = {
|
|
690
|
-
summary: intakeContext.receipt.summary,
|
|
691
|
-
matchedItems: intakeContext.matchedItems.map((item) => ({
|
|
692
|
-
id: item.id,
|
|
693
|
-
type: item.type,
|
|
694
|
-
name: item.name,
|
|
695
|
-
reviewStatus: item.reviewStatus,
|
|
696
|
-
riskLevel: item.riskLevel,
|
|
697
|
-
reasonCodes: item.reasonCodes,
|
|
698
|
-
})),
|
|
699
|
-
nextAction: intakeContext.safeNextAction || intakeContext.receipt.nextAction,
|
|
700
|
-
topReasonCodes: intakeContext.receipt.topReasonCodes || [],
|
|
701
|
-
};
|
|
702
|
-
recordGovernanceLearningSignals(cwd, governanceReceipt);
|
|
703
|
-
recordSafePathLearningSignals(cwd, safePathReceipt);
|
|
704
|
-
} else {
|
|
705
|
-
decision.governanceReceiptPath = null;
|
|
706
|
-
decision.governance = governanceReceipt;
|
|
707
|
-
decision.safePathReceiptPath = null;
|
|
708
|
-
decision.safePath = safePathReceipt;
|
|
709
|
-
decision.installIntakeReceiptPath = null;
|
|
710
|
-
decision.installIntake = {
|
|
711
|
-
summary: intakeContext.receipt.summary,
|
|
712
|
-
matchedItems: intakeContext.matchedItems,
|
|
713
|
-
nextAction: intakeContext.safeNextAction || intakeContext.receipt.nextAction,
|
|
714
|
-
topReasonCodes: intakeContext.receipt.topReasonCodes || [],
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
return decision;
|
|
719
|
-
}
|
|
720
|
-
|
|
721
|
-
function buildPlanSecuritySurface(cwd, options = {}) {
|
|
722
|
-
const plan = String(options.plan || getCurrentPlan({ cwd })).trim().toLowerCase() === "pro" ? "pro" : "free";
|
|
723
|
-
const profile = buildPolicyProfile({ cwd, plan });
|
|
724
|
-
const description = describePolicyProfile(profile);
|
|
725
|
-
const latestEvidence = summarizeEnforcementEvidence(cwd);
|
|
726
|
-
|
|
727
|
-
return {
|
|
728
|
-
plan,
|
|
729
|
-
headline: "Powerful AI agents, safer by default.",
|
|
730
|
-
customerPromise: "Avorelo helps protect AI coding workflows with prompt-injection defense, risky-skill detection, destructive-action blocking, and local evidence, while access-reduction paths stay scoped to the surfaces that support them.",
|
|
731
|
-
mode: profile.mode,
|
|
732
|
-
profileId: profile.profileId,
|
|
733
|
-
zeroStandingPermissions: profile.zeroStandingPermissions === true,
|
|
734
|
-
scopedJitStyleAccess: profile.scopedJitStyleAccess === true,
|
|
735
|
-
enforcementAvailability: profile.enforcementAvailable,
|
|
736
|
-
headlineLine: description.headline,
|
|
737
|
-
postureLine: plan === "pro"
|
|
738
|
-
? "Security posture: approve/enforce where supported."
|
|
739
|
-
: "Security posture: visibility and warnings first, with blocks for clearly unsafe actions.",
|
|
740
|
-
summary: description.summary,
|
|
741
|
-
latestEvidence,
|
|
742
|
-
};
|
|
743
|
-
}
|
|
744
|
-
|
|
745
|
-
module.exports = {
|
|
746
|
-
DECISIONS,
|
|
747
|
-
EVIDENCE_DIR_REL_PATH,
|
|
748
|
-
LATEST_EVIDENCE_REL_PATH,
|
|
749
|
-
HISTORY_DIR_REL_PATH,
|
|
750
|
-
EVENT_LOG_REL_PATH,
|
|
751
|
-
redactSecrets,
|
|
752
|
-
classifyAction,
|
|
753
|
-
getMatchedRules,
|
|
754
|
-
buildDecision,
|
|
755
|
-
writeEnforcementEvidence,
|
|
756
|
-
readLatestEnforcementEvidence,
|
|
757
|
-
summarizeEnforcementEvidence,
|
|
758
|
-
explainDecision,
|
|
759
|
-
isApprovalRequired,
|
|
760
|
-
isBlocked,
|
|
761
|
-
evaluateAgentAction,
|
|
762
|
-
buildPlanSecuritySurface,
|
|
763
|
-
buildAgentAccessGovernanceSurface,
|
|
764
|
-
buildSafePathSurface,
|
|
765
|
-
};
|