avorelo 0.4.0-rc.5 → 1.0.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.
Files changed (398) hide show
  1. package/LICENSE +202 -21
  2. package/NOTICE +15 -0
  3. package/README.md +173 -67
  4. package/bin/avorelo.mjs +7 -0
  5. package/dist/avorelo.mjs +23614 -0
  6. package/package.json +152 -165
  7. package/bin/avorelo +0 -9
  8. package/scripts/README.md +0 -40
  9. package/scripts/avorelo-session-collision-guard.js +0 -540
  10. package/scripts/avorelo-workstream-preflight.js +0 -918
  11. package/scripts/cco-dashboard.js +0 -346
  12. package/scripts/cco-posttooluse.js +0 -504
  13. package/scripts/cco-pretooluse.js +0 -381
  14. package/scripts/cco-status.js +0 -540
  15. package/scripts/cco-stop.js +0 -77
  16. package/scripts/cco-userprompt-submit.js +0 -83
  17. package/scripts/lib/activation/account-state.js +0 -37
  18. package/scripts/lib/activation/activate-command.js +0 -114
  19. package/scripts/lib/activation/activation-runner.js +0 -607
  20. package/scripts/lib/activation/activation-self-healing.js +0 -505
  21. package/scripts/lib/activation/activation-state.js +0 -96
  22. package/scripts/lib/activation/activation-summary.js +0 -241
  23. package/scripts/lib/activation/adapters/claude-code.js +0 -77
  24. package/scripts/lib/activation/adapters/codex-cli.js +0 -52
  25. package/scripts/lib/activation/adapters/cursor.js +0 -37
  26. package/scripts/lib/activation/adapters/github-agent.js +0 -39
  27. package/scripts/lib/activation/adapters/terminal.js +0 -42
  28. package/scripts/lib/activation/adapters/vscode.js +0 -39
  29. package/scripts/lib/activation/adapters/windsurf.js +0 -37
  30. package/scripts/lib/activation/ai-surface-detector.js +0 -151
  31. package/scripts/lib/activation/connect-account.js +0 -145
  32. package/scripts/lib/activation/detect-environment.js +0 -75
  33. package/scripts/lib/activation/detect-hosts.js +0 -62
  34. package/scripts/lib/activation/format-activation-output.js +0 -109
  35. package/scripts/lib/activation/next-action.js +0 -43
  36. package/scripts/lib/activation/repair-engine.js +0 -219
  37. package/scripts/lib/activation/run-entry.js +0 -346
  38. package/scripts/lib/activation-distribution-readiness.js +0 -507
  39. package/scripts/lib/adapter-conformance.js +0 -176
  40. package/scripts/lib/adapter-readiness.js +0 -428
  41. package/scripts/lib/adapter-safety-boundaries.js +0 -335
  42. package/scripts/lib/adapter-technical-readiness-gate.js +0 -205
  43. package/scripts/lib/agent-access-governance.js +0 -455
  44. package/scripts/lib/agent-activation-readiness.js +0 -878
  45. package/scripts/lib/agent-enforcement.js +0 -792
  46. package/scripts/lib/agent-evolution-loop.js +0 -479
  47. package/scripts/lib/agent-policy-profile.js +0 -210
  48. package/scripts/lib/agent-security/action-evaluator.js +0 -507
  49. package/scripts/lib/agent-security/adapter-registry.js +0 -98
  50. package/scripts/lib/agent-security/auto-policy.js +0 -139
  51. package/scripts/lib/agent-security/bounded-scan.js +0 -93
  52. package/scripts/lib/agent-security/enforcement-adapter.js +0 -174
  53. package/scripts/lib/agent-security/enforcement-engine.js +0 -1129
  54. package/scripts/lib/agent-security/file-write-adapter.js +0 -183
  55. package/scripts/lib/agent-security/file-write-rules.js +0 -178
  56. package/scripts/lib/agent-security/index.js +0 -3342
  57. package/scripts/lib/agent-security/instruction-risk.js +0 -181
  58. package/scripts/lib/agent-security/mcp-action-adapter.js +0 -185
  59. package/scripts/lib/agent-security/mcp-action-rules.js +0 -184
  60. package/scripts/lib/agent-security/package-action-adapter.js +0 -175
  61. package/scripts/lib/agent-security/package-action-rules.js +0 -233
  62. package/scripts/lib/agent-security/performance.js +0 -148
  63. package/scripts/lib/agent-security/permission-minimizer.js +0 -403
  64. package/scripts/lib/agent-security/scan-cache.js +0 -74
  65. package/scripts/lib/agent-security/sensitive-targets.js +0 -94
  66. package/scripts/lib/agent-security/source-trust.js +0 -146
  67. package/scripts/lib/ai-efficiency-dogfood-pack.js +0 -437
  68. package/scripts/lib/ai-efficiency-eval.js +0 -207
  69. package/scripts/lib/ai-efficiency-guard-contract.js +0 -209
  70. package/scripts/lib/ai-efficiency-measured-value.js +0 -106
  71. package/scripts/lib/ai-install-prompt.js +0 -293
  72. package/scripts/lib/ai-task-inference.js +0 -155
  73. package/scripts/lib/ai-value-ledger.js +0 -121
  74. package/scripts/lib/ai-value-proof-table.js +0 -151
  75. package/scripts/lib/ai-work-efficiency-routing.js +0 -623
  76. package/scripts/lib/ai-workspace-hygiene.js +0 -1499
  77. package/scripts/lib/alpha-activation.js +0 -520
  78. package/scripts/lib/alpha-feedback.js +0 -263
  79. package/scripts/lib/alpha-readiness-gate.js +0 -332
  80. package/scripts/lib/anti-gaming.js +0 -169
  81. package/scripts/lib/artifact-health.js +0 -431
  82. package/scripts/lib/artifact-receipt-hygiene.js +0 -619
  83. package/scripts/lib/attribution.js +0 -180
  84. package/scripts/lib/audit.js +0 -289
  85. package/scripts/lib/avorelo-skill-registry.js +0 -810
  86. package/scripts/lib/batch-jobs.js +0 -71
  87. package/scripts/lib/brain-pack.js +0 -605
  88. package/scripts/lib/brand-boundary.js +0 -424
  89. package/scripts/lib/brand.js +0 -74
  90. package/scripts/lib/browser-capability.js +0 -1048
  91. package/scripts/lib/browser-proof-governed-workflow.js +0 -1020
  92. package/scripts/lib/browser-proof-preflight.js +0 -321
  93. package/scripts/lib/cache-readiness.js +0 -296
  94. package/scripts/lib/canonical-reentry.js +0 -162
  95. package/scripts/lib/capability-contract-validator.js +0 -177
  96. package/scripts/lib/capability-hygiene.js +0 -504
  97. package/scripts/lib/capability-intake-quarantine.js +0 -789
  98. package/scripts/lib/capability-kernel-registry.js +0 -566
  99. package/scripts/lib/capability-kernel.js +0 -202
  100. package/scripts/lib/capability-manifest.js +0 -255
  101. package/scripts/lib/capability-outcome-normalizer.js +0 -104
  102. package/scripts/lib/capability-packs.js +0 -314
  103. package/scripts/lib/capability-recommender.js +0 -513
  104. package/scripts/lib/capability-registry.js +0 -1062
  105. package/scripts/lib/carry-forward-surfacing.js +0 -194
  106. package/scripts/lib/ccusage-adapter.js +0 -188
  107. package/scripts/lib/claude-session-evidence/index.js +0 -1027
  108. package/scripts/lib/cli-output-sanitizer.js +0 -118
  109. package/scripts/lib/company-loop.js +0 -1149
  110. package/scripts/lib/config.js +0 -641
  111. package/scripts/lib/context-acquisition-plan.js +0 -359
  112. package/scripts/lib/context-authority-rules.js +0 -138
  113. package/scripts/lib/context-budget-guard.js +0 -170
  114. package/scripts/lib/context-budget-scanner.js +0 -257
  115. package/scripts/lib/context-budget.js +0 -167
  116. package/scripts/lib/context-claim-safety.js +0 -116
  117. package/scripts/lib/context-compiler.js +0 -236
  118. package/scripts/lib/context-optimizer.js +0 -715
  119. package/scripts/lib/context-packet.js +0 -121
  120. package/scripts/lib/context-receipt.js +0 -57
  121. package/scripts/lib/context-reduction-plan.js +0 -179
  122. package/scripts/lib/context-safety.js +0 -88
  123. package/scripts/lib/context-savings-engine.js +0 -158
  124. package/scripts/lib/context-source-registry.js +0 -393
  125. package/scripts/lib/context-task-profiles.js +0 -147
  126. package/scripts/lib/cost-abuse-guard.js +0 -975
  127. package/scripts/lib/cost-evidence.js +0 -287
  128. package/scripts/lib/cost-to-outcome-signals.js +0 -639
  129. package/scripts/lib/cross-host-install-plan.js +0 -308
  130. package/scripts/lib/cross-host-install-readiness.js +0 -242
  131. package/scripts/lib/cross-host-value-flow.js +0 -268
  132. package/scripts/lib/dashboard.js +0 -1056
  133. package/scripts/lib/data-permissions-guard.js +0 -1187
  134. package/scripts/lib/deployment-environment-guard.js +0 -1236
  135. package/scripts/lib/design-partner-feedback.js +0 -346
  136. package/scripts/lib/dogfood-evidence-freshness.js +0 -567
  137. package/scripts/lib/efficiency-receipt.js +0 -354
  138. package/scripts/lib/entitlements.js +0 -100
  139. package/scripts/lib/execution-packet.js +0 -559
  140. package/scripts/lib/execution-route-governor.js +0 -179
  141. package/scripts/lib/experimentation-events.js +0 -547
  142. package/scripts/lib/external-capability-compliance.js +0 -107
  143. package/scripts/lib/external-readiness/ai-visibility/ai-visibility-runner.js +0 -322
  144. package/scripts/lib/external-readiness/calibration/benchmark-site-catalog.js +0 -121
  145. package/scripts/lib/external-readiness/calibration/completion-gate.js +0 -112
  146. package/scripts/lib/external-readiness/calibration/real-site-benchmark-runner.js +0 -284
  147. package/scripts/lib/external-readiness/drift-detector.js +0 -100
  148. package/scripts/lib/external-readiness/endpoint-prober.js +0 -332
  149. package/scripts/lib/external-readiness/external-readiness-runner.js +0 -112
  150. package/scripts/lib/external-readiness/full-agent-readiness-scorer.js +0 -220
  151. package/scripts/lib/external-readiness/golden-path-runner.js +0 -333
  152. package/scripts/lib/external-readiness/inside-out-runner.js +0 -118
  153. package/scripts/lib/external-readiness/proof-receipt-writer.js +0 -112
  154. package/scripts/lib/external-readiness/safe-fix-executor.js +0 -117
  155. package/scripts/lib/external-readiness/skills/category-boundary-guard.js +0 -30
  156. package/scripts/lib/external-readiness/skills/pmm-positioning-guard.js +0 -69
  157. package/scripts/lib/external-readiness/skills/safe-fix-policy.js +0 -35
  158. package/scripts/lib/external-user-simulation.js +0 -166
  159. package/scripts/lib/failure-recovery-readiness.js +0 -81
  160. package/scripts/lib/failure-recovery.js +0 -419
  161. package/scripts/lib/feedback-intelligence.js +0 -537
  162. package/scripts/lib/feedback-signals.js +0 -205
  163. package/scripts/lib/file-integrity.js +0 -68
  164. package/scripts/lib/fsx.js +0 -129
  165. package/scripts/lib/full-readiness-gate.js +0 -451
  166. package/scripts/lib/governed-action-exposure-primitives.js +0 -1514
  167. package/scripts/lib/governed-exposure-planner.js +0 -186
  168. package/scripts/lib/governed-workspace-hygiene.js +0 -946
  169. package/scripts/lib/guard-suite-common.js +0 -412
  170. package/scripts/lib/guidance-builder.js +0 -174
  171. package/scripts/lib/hook-apply.js +0 -1200
  172. package/scripts/lib/hook-baseline.js +0 -310
  173. package/scripts/lib/hook-config-preview.js +0 -275
  174. package/scripts/lib/hook-contracts.js +0 -290
  175. package/scripts/lib/hook-safety-boundary-readiness.js +0 -80
  176. package/scripts/lib/host-capability-matrix.js +0 -351
  177. package/scripts/lib/host-provenance.js +0 -114
  178. package/scripts/lib/host-support-context.js +0 -254
  179. package/scripts/lib/http-hook-action.js +0 -538
  180. package/scripts/lib/install-ai-readiness.js +0 -84
  181. package/scripts/lib/install-intake-risk.js +0 -1051
  182. package/scripts/lib/install-journey-intelligence.js +0 -329
  183. package/scripts/lib/intervention-guidance.js +0 -57
  184. package/scripts/lib/known-limitations.js +0 -115
  185. package/scripts/lib/l8-path-truth.js +0 -146
  186. package/scripts/lib/launch-hardening-gate.js +0 -436
  187. package/scripts/lib/launch-readiness.js +0 -635
  188. package/scripts/lib/learning-experimentation-foundation.js +0 -1484
  189. package/scripts/lib/learning-memory.js +0 -686
  190. package/scripts/lib/lifecycle-hooks.js +0 -1445
  191. package/scripts/lib/local-package-smoke.js +0 -436
  192. package/scripts/lib/local-pricing.js +0 -299
  193. package/scripts/lib/mcp-enforcement.js +0 -311
  194. package/scripts/lib/mcp-least-privilege-policy.js +0 -303
  195. package/scripts/lib/mcp-tool-inventory.js +0 -388
  196. package/scripts/lib/mcp-tool-risk.js +0 -0
  197. package/scripts/lib/memory.js +0 -335
  198. package/scripts/lib/metrics.js +0 -699
  199. package/scripts/lib/micro-proof.js +0 -133
  200. package/scripts/lib/model-work-class-routing.js +0 -79
  201. package/scripts/lib/next-run-context.js +0 -436
  202. package/scripts/lib/next-run-continuity.js +0 -1207
  203. package/scripts/lib/observability-recovery-guard.js +0 -1030
  204. package/scripts/lib/operating-value.js +0 -1662
  205. package/scripts/lib/optimization-v3.js +0 -122
  206. package/scripts/lib/orchestration/adapters/_shared.js +0 -49
  207. package/scripts/lib/orchestration/adapters/aider.js +0 -18
  208. package/scripts/lib/orchestration/adapters/claude-code.js +0 -35
  209. package/scripts/lib/orchestration/adapters/codex.js +0 -35
  210. package/scripts/lib/orchestration/adapters/gemini-cli.js +0 -18
  211. package/scripts/lib/orchestration/adapters/git.js +0 -25
  212. package/scripts/lib/orchestration/adapters/index.js +0 -31
  213. package/scripts/lib/orchestration/adapters/lm-studio.js +0 -18
  214. package/scripts/lib/orchestration/adapters/ollama.js +0 -18
  215. package/scripts/lib/orchestration/adapters/opencode.js +0 -18
  216. package/scripts/lib/orchestration/adapters/openrouter.js +0 -18
  217. package/scripts/lib/orchestration/adapters/test-runner.js +0 -25
  218. package/scripts/lib/orchestration/cli.js +0 -438
  219. package/scripts/lib/orchestration/execution-manager.js +0 -279
  220. package/scripts/lib/orchestration/handoff.js +0 -314
  221. package/scripts/lib/orchestration/index.js +0 -482
  222. package/scripts/lib/orchestration/inventory.js +0 -47
  223. package/scripts/lib/orchestration/model-discovery.js +0 -498
  224. package/scripts/lib/orchestration/model-profiler.js +0 -170
  225. package/scripts/lib/orchestration/model-profiles.js +0 -252
  226. package/scripts/lib/orchestration/model-refresh-policy.js +0 -72
  227. package/scripts/lib/orchestration/proof-writer.js +0 -349
  228. package/scripts/lib/orchestration/provider-discovery/aider.js +0 -49
  229. package/scripts/lib/orchestration/provider-discovery/claude-code.js +0 -56
  230. package/scripts/lib/orchestration/provider-discovery/codex.js +0 -49
  231. package/scripts/lib/orchestration/provider-discovery/common.js +0 -186
  232. package/scripts/lib/orchestration/provider-discovery/gemini.js +0 -106
  233. package/scripts/lib/orchestration/provider-discovery/lm-studio.js +0 -118
  234. package/scripts/lib/orchestration/provider-discovery/models-dev.js +0 -12
  235. package/scripts/lib/orchestration/provider-discovery/ollama.js +0 -100
  236. package/scripts/lib/orchestration/provider-discovery/opencode.js +0 -47
  237. package/scripts/lib/orchestration/provider-discovery/openrouter.js +0 -44
  238. package/scripts/lib/orchestration/risk-classifier.js +0 -130
  239. package/scripts/lib/orchestration/routing-policy.js +0 -486
  240. package/scripts/lib/orchestration/settings.js +0 -95
  241. package/scripts/lib/orchestration/state.js +0 -165
  242. package/scripts/lib/orchestration/verification-manager.js +0 -138
  243. package/scripts/lib/outcome-evidence-stack.js +0 -1106
  244. package/scripts/lib/output-profiles.js +0 -146
  245. package/scripts/lib/package-content-audit.js +0 -368
  246. package/scripts/lib/package-runtime.js +0 -278
  247. package/scripts/lib/plan-surface.js +0 -53
  248. package/scripts/lib/plans.js +0 -2327
  249. package/scripts/lib/policy-provider.js +0 -27
  250. package/scripts/lib/prelaunch-activation-readiness.js +0 -409
  251. package/scripts/lib/prelaunch-evidence-store.js +0 -816
  252. package/scripts/lib/prelaunch-intelligence.js +0 -869
  253. package/scripts/lib/pricing-experiment.js +0 -118
  254. package/scripts/lib/pro-moment-events.js +0 -77
  255. package/scripts/lib/pro-moment-state.js +0 -227
  256. package/scripts/lib/pro-moments.js +0 -1216
  257. package/scripts/lib/product-home-receipt.js +0 -1790
  258. package/scripts/lib/product-learning-events.js +0 -696
  259. package/scripts/lib/production-confidence-control-tower.js +0 -1209
  260. package/scripts/lib/production-confidence.js +0 -1858
  261. package/scripts/lib/project-profile.js +0 -555
  262. package/scripts/lib/prompt-compiler-plan.js +0 -94
  263. package/scripts/lib/prompt-compiler.js +0 -280
  264. package/scripts/lib/prompt-lint.js +0 -32
  265. package/scripts/lib/prompt-suggestions.js +0 -52
  266. package/scripts/lib/proof-canonical.js +0 -398
  267. package/scripts/lib/proof-drilldown.js +0 -383
  268. package/scripts/lib/proof-e2e/promise-completion.js +0 -141
  269. package/scripts/lib/proof-e2e/promise-dashboard-claims.js +0 -135
  270. package/scripts/lib/proof-e2e/promise-local-proof.js +0 -156
  271. package/scripts/lib/proof-e2e/promise-provider-neutral.js +0 -136
  272. package/scripts/lib/proof-e2e/promise-registry.js +0 -219
  273. package/scripts/lib/proof-e2e/promise-security-trust.js +0 -141
  274. package/scripts/lib/proof-e2e/promise-skills-risk.js +0 -163
  275. package/scripts/lib/proof-e2e/promise-token-savings.js +0 -112
  276. package/scripts/lib/proof-e2e/promise-work-management.js +0 -126
  277. package/scripts/lib/proof-events.js +0 -342
  278. package/scripts/lib/proof-history.js +0 -243
  279. package/scripts/lib/proof-metrics.js +0 -296
  280. package/scripts/lib/proof-outcome-evidence.js +0 -134
  281. package/scripts/lib/proof-receipt.js +0 -335
  282. package/scripts/lib/proof-record.js +0 -461
  283. package/scripts/lib/proof-savings-report.js +0 -1549
  284. package/scripts/lib/public-activation-distribution-gate.js +0 -266
  285. package/scripts/lib/public-cli.js +0 -5667
  286. package/scripts/lib/public-distribution-truth.js +0 -211
  287. package/scripts/lib/public-distribution.js +0 -73
  288. package/scripts/lib/public-install-claim-checker.js +0 -300
  289. package/scripts/lib/publish-provenance-readiness.js +0 -287
  290. package/scripts/lib/readiness-delta.js +0 -218
  291. package/scripts/lib/readiness-evidence-closure.js +0 -196
  292. package/scripts/lib/reentry-memory-capture.js +0 -241
  293. package/scripts/lib/reentry-memory-retrieval.js +0 -302
  294. package/scripts/lib/reentry-memory-status.js +0 -147
  295. package/scripts/lib/reentry-memory-store.js +0 -183
  296. package/scripts/lib/reentry-state.js +0 -66
  297. package/scripts/lib/release-candidate-bundle.js +0 -166
  298. package/scripts/lib/remediation.js +0 -81
  299. package/scripts/lib/repo-map.js +0 -391
  300. package/scripts/lib/run-action-policy.js +0 -104
  301. package/scripts/lib/run-contract-receipt.js +0 -48
  302. package/scripts/lib/run-contract.js +0 -288
  303. package/scripts/lib/run-cost-to-verified-outcome.js +0 -87
  304. package/scripts/lib/run-improvements-lifecycle.js +0 -330
  305. package/scripts/lib/run-improvements.js +0 -789
  306. package/scripts/lib/run-proof-contract.js +0 -116
  307. package/scripts/lib/run-risk-classifier.js +0 -131
  308. package/scripts/lib/run-task-classifier.js +0 -216
  309. package/scripts/lib/runtime-decision-policy.js +0 -387
  310. package/scripts/lib/runtime-provenance.js +0 -43
  311. package/scripts/lib/safe-path-engine.js +0 -705
  312. package/scripts/lib/safe-repair.js +0 -877
  313. package/scripts/lib/safe-run-controller.js +0 -887
  314. package/scripts/lib/scope-repair-before-approval.js +0 -865
  315. package/scripts/lib/score.js +0 -262
  316. package/scripts/lib/seamless-enforcement.js +0 -329
  317. package/scripts/lib/seamless-outcome.js +0 -689
  318. package/scripts/lib/seamless-reality-gate.js +0 -5053
  319. package/scripts/lib/security-confidence/activation-safety.js +0 -78
  320. package/scripts/lib/security-confidence/adapters/adapter-contract.js +0 -125
  321. package/scripts/lib/security-confidence/adapters/mock-claude-bughunter-adapter.js +0 -36
  322. package/scripts/lib/security-confidence/adapters/mock-decepticon-adapter.js +0 -34
  323. package/scripts/lib/security-confidence/adapters/mock-mcp-scan-adapter.js +0 -35
  324. package/scripts/lib/security-confidence/adapters/mock-snyk-agent-scan-adapter.js +0 -35
  325. package/scripts/lib/security-confidence/adapters/mock-tank-adapter.js +0 -34
  326. package/scripts/lib/security-confidence/adapters/reference-registry.js +0 -63
  327. package/scripts/lib/security-confidence/auth-rbac-plan.js +0 -39
  328. package/scripts/lib/security-confidence/component-inventory.js +0 -151
  329. package/scripts/lib/security-confidence/constants.js +0 -191
  330. package/scripts/lib/security-confidence/dependency-script-risk.js +0 -95
  331. package/scripts/lib/security-confidence/evidence-hygiene.js +0 -127
  332. package/scripts/lib/security-confidence/feature-impact-classifier.js +0 -80
  333. package/scripts/lib/security-confidence/file-utils.js +0 -161
  334. package/scripts/lib/security-confidence/finding-triage.js +0 -90
  335. package/scripts/lib/security-confidence/findings.js +0 -115
  336. package/scripts/lib/security-confidence/index.js +0 -29
  337. package/scripts/lib/security-confidence/permission-budget.js +0 -93
  338. package/scripts/lib/security-confidence/redaction.js +0 -82
  339. package/scripts/lib/security-confidence/redteam-fixtures.js +0 -53
  340. package/scripts/lib/security-confidence/reference-adoption.js +0 -229
  341. package/scripts/lib/security-confidence/reference-taxonomy.js +0 -155
  342. package/scripts/lib/security-confidence/report-quality.js +0 -99
  343. package/scripts/lib/security-confidence/report-writer.js +0 -79
  344. package/scripts/lib/security-confidence/risk-classifier.js +0 -187
  345. package/scripts/lib/security-confidence/runner.js +0 -179
  346. package/scripts/lib/security-confidence/schema.js +0 -188
  347. package/scripts/lib/security-confidence/secret-safety.js +0 -74
  348. package/scripts/lib/security-confidence/security-capability-router.js +0 -98
  349. package/scripts/lib/security-confidence/web-security-smoke-plan.js +0 -46
  350. package/scripts/lib/security-risk-classifier.js +0 -568
  351. package/scripts/lib/security-scan.js +0 -403
  352. package/scripts/lib/session-context-optimizer.js +0 -1253
  353. package/scripts/lib/session-timing.js +0 -322
  354. package/scripts/lib/skill-hygiene.js +0 -805
  355. package/scripts/lib/skill-packs.js +0 -161
  356. package/scripts/lib/skills-operating-layer-v1.js +0 -1023
  357. package/scripts/lib/skills-operating-layer.js +0 -629
  358. package/scripts/lib/smallest-safe-plan.js +0 -214
  359. package/scripts/lib/smart-routing-plan.js +0 -115
  360. package/scripts/lib/smart-work-routing.js +0 -768
  361. package/scripts/lib/source-catalog.js +0 -1022
  362. package/scripts/lib/status-value-summary.js +0 -32
  363. package/scripts/lib/supply-chain-dependency-guard.js +0 -1333
  364. package/scripts/lib/supply-chain-guard.js +0 -219
  365. package/scripts/lib/support-bundle.js +0 -561
  366. package/scripts/lib/support-redaction.js +0 -66
  367. package/scripts/lib/task-continuation.js +0 -440
  368. package/scripts/lib/test-helpers.js +0 -15
  369. package/scripts/lib/tier.js +0 -38
  370. package/scripts/lib/token-context-quality-gate.js +0 -370
  371. package/scripts/lib/token-cost-capture.js +0 -187
  372. package/scripts/lib/token-cost-evidence.js +0 -862
  373. package/scripts/lib/token-cost-intelligence.js +0 -358
  374. package/scripts/lib/token-efficiency-evidence.js +0 -213
  375. package/scripts/lib/token-efficiency-map.js +0 -110
  376. package/scripts/lib/token-evidence.js +0 -703
  377. package/scripts/lib/tokenish.js +0 -17
  378. package/scripts/lib/tool-output-sandbox.js +0 -559
  379. package/scripts/lib/trust-audit.js +0 -136
  380. package/scripts/lib/unified-events.js +0 -396
  381. package/scripts/lib/upgrade-interruption-recovery.js +0 -407
  382. package/scripts/lib/usage-ledger.js +0 -201
  383. package/scripts/lib/value-ledger.js +0 -130
  384. package/scripts/lib/value-proof-calibration.js +0 -531
  385. package/scripts/lib/visual-qa.js +0 -231
  386. package/scripts/lib/voice-alpha.js +0 -29
  387. package/scripts/lib/webhook-idempotency-guard.js +0 -990
  388. package/scripts/lib/work-aware-orchestration.js +0 -976
  389. package/scripts/lib/work-control-receipts.js +0 -577
  390. package/scripts/lib/work-ledger.js +0 -1123
  391. package/scripts/lib/work-panel-preview.js +0 -352
  392. package/scripts/lib/workflow-discipline.js +0 -280
  393. package/scripts/lib/workflow-intelligence-radar.js +0 -804
  394. package/scripts/lib/workflow-signals.js +0 -419
  395. package/scripts/lib/workspace-map.js +0 -281
  396. package/scripts/lib/workspace-registry.js +0 -1367
  397. package/scripts/lib/workspace-resolver.js +0 -542
  398. package/scripts/wuz-doctor.js +0 -315
@@ -1,568 +0,0 @@
1
- "use strict";
2
-
3
- const path = require("path");
4
- const { URL } = require("url");
5
- const { scanInstructionRisk, sanitizeInstructionLikeContent } = require("./agent-security/instruction-risk");
6
- const { detectSecretFileRead, detectBroadPermissionChange } = require("./agent-security/sensitive-targets");
7
- const { resolveProjectTarget } = require("./agent-security/file-write-rules");
8
-
9
- const RISK_LEVELS = Object.freeze(["low", "medium", "high", "critical"]);
10
- const RISK_ORDER = Object.freeze({
11
- low: 1,
12
- medium: 2,
13
- high: 3,
14
- critical: 4,
15
- });
16
-
17
- const SENSITIVE_PATH_PATTERNS = Object.freeze([
18
- { pattern: /(^|[\\/])\.env(\.[A-Za-z0-9._-]+)?$/i, reason: "SENSITIVE_ENV_FILE", risk: "critical" },
19
- { pattern: /(^|[\\/])(\.npmrc|\.pypirc|\.netrc)$/i, reason: "SECRET_LIKE_TARGET", risk: "critical" },
20
- { pattern: /(^|[\\/])(id_rsa|id_ed25519|id_dsa|id_ecdsa)(\.pub)?$/i, reason: "SECRET_LIKE_TARGET", risk: "critical" },
21
- { pattern: /\.(pem|key|p12|pfx)$/i, reason: "SECRET_LIKE_TARGET", risk: "critical" },
22
- { pattern: /(^|[\\/])(secrets?|credentials?)(\.[A-Za-z0-9._-]+)?$/i, reason: "SECRET_LIKE_TARGET", risk: "critical" },
23
- { pattern: /(^|[\\/])(secrets?|credentials?|private[_ -]?keys?|\.ssh|\.aws|tokens?)([\\/]|$)/i, reason: "SECRET_LIKE_TARGET", risk: "critical" },
24
- { pattern: /(auth|oauth|sso|billing|payment|stripe|checkout|subscription|invoice)/i, reason: "AUTH_OR_BILLING_SCOPE", risk: "high" },
25
- { pattern: /(deploy|release|production|prod|docker|k8s|terraform|vercel|netlify|railway|render)/i, reason: "DEPLOYMENT_CONFIG", risk: "high" },
26
- { pattern: /(^|[\\/])\.github[\\/]workflows[\\/]|(^|[\\/])(ci|cd)([\\/]|$)/i, reason: "CI_CONFIG", risk: "high" },
27
- ]);
28
-
29
- const LOCAL_BROWSER_HOSTS = new Set(["localhost", "127.0.0.1", "::1"]);
30
-
31
- function unique(values) {
32
- return [...new Set((values || []).filter(Boolean))];
33
- }
34
-
35
- function maxRisk(left, right) {
36
- return (RISK_ORDER[left] || 0) >= (RISK_ORDER[right] || 0) ? left : right;
37
- }
38
-
39
- function makeResult(riskLevel = "low", reasonCodes = [], extras = {}) {
40
- return {
41
- riskLevel,
42
- reasonCodes: unique(reasonCodes),
43
- explanation: extras.explanation || "",
44
- recommendedAction: extras.recommendedAction || "",
45
- findings: extras.findings || [],
46
- safeSummary: extras.safeSummary || null,
47
- matched: extras.matched || [],
48
- };
49
- }
50
-
51
- function mergeResults(...results) {
52
- return results.filter(Boolean).reduce((merged, current) => {
53
- return {
54
- riskLevel: maxRisk(merged.riskLevel, current.riskLevel || "low"),
55
- reasonCodes: unique([...(merged.reasonCodes || []), ...(current.reasonCodes || [])]),
56
- explanation: unique([merged.explanation, current.explanation]).filter(Boolean).join(" ").trim(),
57
- recommendedAction: unique([merged.recommendedAction, current.recommendedAction]).filter(Boolean).join(" ").trim(),
58
- findings: [...(merged.findings || []), ...(current.findings || [])],
59
- safeSummary: merged.safeSummary || current.safeSummary || null,
60
- matched: [...(merged.matched || []), ...(current.matched || [])],
61
- };
62
- }, makeResult("low"));
63
- }
64
-
65
- function normalizePathValue(value) {
66
- return String(value || "").replace(/\\/g, "/").trim();
67
- }
68
-
69
- function normalizePathList(paths) {
70
- if (!paths) return [];
71
- const list = Array.isArray(paths) ? paths : [paths];
72
- return list.map(normalizePathValue).filter(Boolean);
73
- }
74
-
75
- function parseUrl(input) {
76
- const raw = String(input || "").trim();
77
- if (!raw) return null;
78
- try {
79
- if (/^https?:\/\//i.test(raw)) return new URL(raw);
80
- if (/^(localhost|127\.0\.0\.1|::1)(:\d+)?(\/|$)/i.test(raw)) {
81
- return new URL(`http://${raw}`);
82
- }
83
- } catch {
84
- return null;
85
- }
86
- return null;
87
- }
88
-
89
- function classifyPathRisk(paths, options = {}) {
90
- const normalized = normalizePathList(paths);
91
- if (!normalized.length) {
92
- return makeResult("low", [], {
93
- explanation: "No file or path target was provided.",
94
- recommendedAction: "Keep the action scoped to the smallest necessary repo slice.",
95
- });
96
- }
97
-
98
- let riskLevel = "low";
99
- const reasonCodes = [];
100
- const matched = [];
101
-
102
- normalized.forEach((value) => {
103
- SENSITIVE_PATH_PATTERNS.forEach((rule) => {
104
- if (!rule.pattern.test(value)) return;
105
- riskLevel = maxRisk(riskLevel, rule.risk);
106
- reasonCodes.push(rule.reason);
107
- matched.push(value);
108
- });
109
- });
110
-
111
- if (riskLevel === "low" && normalized.every((value) => /^(docs|src\/landing-page|deferred\/site-implementation|tests|src\/)/i.test(value))) {
112
- return makeResult("low", [], {
113
- explanation: "The target stays inside normal project files.",
114
- recommendedAction: "Keep the edit bounded to the requested product slice.",
115
- matched: normalized,
116
- });
117
- }
118
-
119
- return makeResult(riskLevel, reasonCodes, {
120
- explanation: reasonCodes.length
121
- ? "Sensitive file scope was detected."
122
- : "The target path is not obviously sensitive.",
123
- recommendedAction: riskLevel === "critical"
124
- ? "Avoid direct writes to secrets or env files. Use a reviewed template or ask for explicit approval."
125
- : riskLevel === "high"
126
- ? "Double-check that the target path is in scope for the requested task."
127
- : "Keep the action scoped to the requested files only.",
128
- matched,
129
- });
130
- }
131
-
132
- function classifyCommandRisk(command) {
133
- const text = String(command || "").trim();
134
- if (!text) {
135
- return makeResult("low", [], {
136
- explanation: "No shell command was provided.",
137
- recommendedAction: "Prefer a scoped local command when execution is needed.",
138
- });
139
- }
140
-
141
- const lower = text.toLowerCase();
142
- const reasonCodes = [];
143
- let riskLevel = "low";
144
-
145
- if (/^(npm test|npm run test\b|npm run build\b|node --test\b|vitest\b|pytest\b|cargo test\b|go test\b)/i.test(text)) {
146
- return makeResult("low", ["SAFE_STATUS_ACTION"], {
147
- explanation: "The command looks like a normal local verification command.",
148
- recommendedAction: "Run the narrowest relevant local verification only.",
149
- });
150
- }
151
-
152
- if (/\brm\s+-rf\b|\bdel\s+\/s\s+\/q\b|\bformat\b|\bremove-item\b[^\n]*-recurse\b|\bgit reset --hard\b/i.test(lower)) {
153
- reasonCodes.push("DESTRUCTIVE_COMMAND");
154
- riskLevel = "critical";
155
- }
156
-
157
- if (/\bgit push\b[^\n]*--force\b|\bgit push\b[^\n]*--force-with-lease\b|\bgit push --mirror\b|\bgit branch -d\b|\bgit tag -d\b/i.test(lower)) {
158
- reasonCodes.push("FORCE_PUSH_OR_HISTORY_REWRITE");
159
- riskLevel = maxRisk(riskLevel, "critical");
160
- }
161
-
162
- if (detectSecretFileRead(text)) {
163
- reasonCodes.push("SECRET_FILE_READ");
164
- riskLevel = maxRisk(riskLevel, "critical");
165
- }
166
-
167
- const broadPerm = detectBroadPermissionChange(text);
168
- if (broadPerm) {
169
- reasonCodes.push("BROAD_PERMISSION_CHANGE");
170
- riskLevel = maxRisk(riskLevel, broadPerm.severity === "high" ? "high" : "medium");
171
- }
172
-
173
- if (/\b(curl|wget)\b[^\n]*(upload|form|post|put)|\bscp\b|\brsync\b[^\n]*@/i.test(lower)) {
174
- reasonCodes.push("EXTERNAL_REPO_EXPORT");
175
- riskLevel = maxRisk(riskLevel, "critical");
176
- }
177
-
178
- if (/\b(curl|wget|invoke-webrequest|invoke-restmethod)\b/i.test(lower)) {
179
- reasonCodes.push("EXTERNAL_NETWORK_REQUEST");
180
- riskLevel = maxRisk(riskLevel, "high");
181
- }
182
-
183
- if (/\b(deploy|release|publish|shipit|npm publish)\b/i.test(lower)) {
184
- reasonCodes.push("DEPLOYMENT_CONFIG");
185
- riskLevel = maxRisk(riskLevel, "high");
186
- }
187
-
188
- return makeResult(riskLevel, reasonCodes, {
189
- explanation: reasonCodes.length
190
- ? "The command includes risky or high-impact behavior."
191
- : "The command is not obviously destructive, but it still executes local changes.",
192
- recommendedAction: riskLevel === "critical"
193
- ? "Block destructive or external export commands unless they are explicitly reviewed and scoped."
194
- : riskLevel === "high"
195
- ? "Require explicit approval before running commands that deploy, publish, or reach external networks."
196
- : "Keep shell commands narrow, local, and task-scoped.",
197
- });
198
- }
199
-
200
- function classifyToolRisk(input = {}) {
201
- const toolName = String(input.toolName || "").trim();
202
- const mcpServer = String(input.mcpServer || "").trim();
203
- const label = [mcpServer, toolName].filter(Boolean).join(":") || "unknown-tool";
204
- const metadata = input.metadata && typeof input.metadata === "object" ? input.metadata : {};
205
- const reasonCodes = [];
206
- let riskLevel = "low";
207
-
208
- if (!toolName && !mcpServer) {
209
- return makeResult("low", [], {
210
- explanation: "No tool or MCP target was provided.",
211
- recommendedAction: "Keep tool access limited to trusted local capabilities.",
212
- });
213
- }
214
-
215
- if (metadata.unknown === true || (!metadata.trusted && (toolName || mcpServer))) {
216
- reasonCodes.push("UNKNOWN_MCP_TOOL");
217
- riskLevel = maxRisk(riskLevel, "medium");
218
- }
219
- if (metadata.writeCapable === true) {
220
- reasonCodes.push("WRITE_CAPABLE_TOOL");
221
- riskLevel = maxRisk(riskLevel, "high");
222
- }
223
- if (metadata.networkCapable === true) {
224
- reasonCodes.push("EXTERNAL_NETWORK_REQUEST");
225
- riskLevel = maxRisk(riskLevel, "high");
226
- }
227
- if (metadata.secretSensitive === true) {
228
- reasonCodes.push("SECRET_LIKE_TARGET");
229
- riskLevel = maxRisk(riskLevel, "high");
230
- }
231
-
232
- return makeResult(riskLevel, reasonCodes, {
233
- explanation: reasonCodes.length
234
- ? `Tool risk signals were detected for ${label}.`
235
- : `${label} looks like a normal local tool.`,
236
- recommendedAction: riskLevel === "high"
237
- ? "Require approval for write-capable, network-capable, or secret-sensitive tools."
238
- : riskLevel === "medium"
239
- ? "Review unknown tool trust before relying on it."
240
- : "Keep tool access limited to trusted local tooling.",
241
- });
242
- }
243
-
244
- function classifyBrowserRisk(input = {}) {
245
- const urlValue = input.url || input.target || input.domain || "";
246
- const parsed = parseUrl(urlValue);
247
- const host = String(input.domain || parsed?.hostname || "").trim().toLowerCase();
248
- const boundaryReady = input.domainBoundaryReady === true || input.allowedDomain === true;
249
- const hasSessionRisk = input.cookieAccess === true || input.sessionAccess === true || input.secretAccess === true;
250
-
251
- if (!host && !urlValue) {
252
- return makeResult("low", [], {
253
- explanation: "No browser target was provided.",
254
- recommendedAction: "Keep browser actions limited to the named local preview when possible.",
255
- });
256
- }
257
-
258
- if (hasSessionRisk) {
259
- return makeResult("critical", ["BROWSER_COOKIE_OR_SESSION_RISK"], {
260
- explanation: "The browser action could touch cookies, authenticated sessions, or other secret-bearing state.",
261
- recommendedAction: "Block browser actions that need cookies, session reuse, or secret access.",
262
- });
263
- }
264
-
265
- if (LOCAL_BROWSER_HOSTS.has(host)) {
266
- return makeResult("low", ["VISUAL_QA_LOCAL_TARGET"], {
267
- explanation: "The browser target stays on a local preview.",
268
- recommendedAction: "Keep Visual QA scoped to local preview URLs when possible.",
269
- });
270
- }
271
-
272
- return makeResult(boundaryReady ? "medium" : "high", ["BROWSER_EXTERNAL_DOMAIN"], {
273
- explanation: boundaryReady
274
- ? "The browser target is external, but a domain boundary is present."
275
- : "The browser target is external and no domain boundary was provided.",
276
- recommendedAction: boundaryReady
277
- ? "Require approval before leaving the local preview scope."
278
- : "Add an explicit domain boundary or require approval before touching external sites.",
279
- });
280
- }
281
-
282
- function classifyInstructionRisk(input = {}) {
283
- const text = String(input.instructionText || input.text || "").trim();
284
- if (!text) {
285
- return makeResult("low", [], {
286
- explanation: "No instruction text was provided.",
287
- recommendedAction: "Keep instructions explicit, scoped, and task-bound.",
288
- });
289
- }
290
-
291
- const scan = scanInstructionRisk(text, {
292
- sourceType: input.sourceType || input.sourceTrust || "unknown_external",
293
- });
294
- const reasonCodes = [];
295
- let riskLevel = scan.instructionRisk || "low";
296
-
297
- if (scan.signals.length > 0) {
298
- reasonCodes.push("PROMPT_INJECTION_SIGNAL");
299
- }
300
- if (/\b(reveal|upload|send|exfiltrat|print)\b[^\n]{0,80}\b(secrets?|tokens?|credentials?|repo|repository|codebase)\b/i.test(text)) {
301
- reasonCodes.push("PROMPT_INJECTION_SIGNAL", "SECRET_LIKE_TARGET");
302
- riskLevel = maxRisk(riskLevel, "critical");
303
- }
304
- if (/\b(ignore|bypass|disable)\b[^\n]{0,80}\b(approval|security|guard|evidence|logs?)\b/i.test(text)) {
305
- reasonCodes.push("PROMPT_INJECTION_SIGNAL");
306
- riskLevel = maxRisk(riskLevel, "high");
307
- }
308
- if (/\b(always allow|allow all)\b[^\n]{0,40}\b(tool|command|browser|mcp)\b/i.test(text)) {
309
- reasonCodes.push("PROMPT_INJECTION_SIGNAL");
310
- riskLevel = maxRisk(riskLevel, "high");
311
- }
312
- if (/\b(delete|remove|wipe)\b[^\n]{0,80}\b(evidence|audit|logs?)\b/i.test(text)) {
313
- reasonCodes.push("PROMPT_INJECTION_SIGNAL");
314
- riskLevel = maxRisk(riskLevel, "high");
315
- }
316
- if (/\b(unrelated|outside scope|ignore scope)\b[^\n]{0,120}\b(auth|billing|deploy|workflow|secrets?)\b/i.test(text)) {
317
- reasonCodes.push("INTENT_MISMATCH");
318
- riskLevel = maxRisk(riskLevel, "high");
319
- }
320
-
321
- return makeResult(riskLevel, reasonCodes, {
322
- explanation: scan.findings.length
323
- ? "Instruction-risk or prompt-injection-like signals were detected."
324
- : "No obvious prompt-injection patterns were detected.",
325
- recommendedAction: riskLevel === "critical"
326
- ? "Treat the content as untrusted, do not execute it, and keep it out of tool decisions."
327
- : riskLevel === "high"
328
- ? "Require review before allowing the instruction to influence tools or sensitive actions."
329
- : scan.recommendation === "use_sanitized_copy"
330
- ? "Use a sanitized summary instead of the raw instruction text."
331
- : "Keep the instruction scoped to the requested task only.",
332
- findings: scan.findings,
333
- safeSummary: sanitizeInstructionLikeContent(text),
334
- });
335
- }
336
-
337
- function classifyPromptInjectionRisk(input = {}) {
338
- const base = classifyInstructionRisk(input);
339
- if (!base.reasonCodes.includes("PROMPT_INJECTION_SIGNAL")) {
340
- return base;
341
- }
342
- return mergeResults(base, makeResult(base.riskLevel === "low" ? "medium" : base.riskLevel, ["PROMPT_INJECTION_SIGNAL"], {
343
- explanation: "Prompt-injection-like signals were detected in instruction content.",
344
- recommendedAction: "Treat the content as data first and require review before it can influence tools or sensitive actions.",
345
- safeSummary: base.safeSummary,
346
- }));
347
- }
348
-
349
- function classifySourceTrustRisk(input = {}) {
350
- const rawTrust = input.sourceTrust || input.trustLevel || input.sourceType || "";
351
- const trust = String(rawTrust).trim().toLowerCase();
352
- if (!trust) {
353
- return makeResult("low", [], {
354
- explanation: "No external source-trust signal was provided.",
355
- recommendedAction: "Prefer reviewed local sources when a task includes discovered instructions.",
356
- });
357
- }
358
- if (trust === "trusted" || trust === "project_local" || trust === "local") {
359
- return makeResult("low", [], {
360
- explanation: "The source looks local or trusted.",
361
- recommendedAction: "Keep trusted local sources scoped to the requested task.",
362
- });
363
- }
364
-
365
- const highRisk = ["external_untrusted", "tool_returned_untrusted", "unknown_external", "unknown"].includes(trust);
366
- return makeResult(highRisk ? "high" : "medium", ["UNTRUSTED_SOURCE"], {
367
- explanation: "The source should not be trusted as an instruction source.",
368
- recommendedAction: "Treat untrusted or tool-returned content as data only unless it is explicitly reviewed.",
369
- });
370
- }
371
-
372
- function classifyIntentMismatchRisk(input = {}) {
373
- const task = String(input.userIntent || input.taskType || input.intendedTask || "").toLowerCase();
374
- const targets = normalizePathList(input.targetPaths || input.target || []);
375
- const command = String(input.command || "").toLowerCase();
376
- const toolName = String(input.toolName || "").toLowerCase();
377
- const domain = String(input.domain || input.url || "").toLowerCase();
378
-
379
- if (!task) {
380
- return makeResult("low", [], {
381
- explanation: "No task intent was provided.",
382
- recommendedAction: "Capture the user intent before approving broader actions.",
383
- });
384
- }
385
-
386
- const taskLooksMarketing = /\b(landing|pricing|copy|homepage|docs?)\b/.test(task);
387
- const targetLooksSensitive = targets.some((value) => /(auth|billing|payment|deploy|release|workflow|\.env|secret|credential)/i.test(value));
388
- const commandLooksSensitive = /(deploy|publish|release|rm -rf|curl|wget|npm install|git push --force)/.test(command);
389
- const toolLooksSensitive = /(delete|deploy|publish|secret|credential|billing|admin)/.test(toolName);
390
- const domainLooksExternal = Boolean(domain) && !parseUrl(domain)?.hostname?.match(/^(localhost|127\.0\.0\.1|::1)$/i);
391
-
392
- if (taskLooksMarketing && (targetLooksSensitive || commandLooksSensitive || toolLooksSensitive || domainLooksExternal)) {
393
- return makeResult("high", ["INTENT_MISMATCH", "OUT_OF_SCOPE_FILE_CHANGE"], {
394
- explanation: "The requested action does not match the stated marketing or docs task.",
395
- recommendedAction: "Keep pricing, landing, or docs tasks out of auth, billing, deploy, workflow, and secret-bearing areas.",
396
- });
397
- }
398
-
399
- return makeResult("low", [], {
400
- explanation: "No strong intent mismatch signal was detected.",
401
- recommendedAction: "Keep the action aligned with the named task.",
402
- });
403
- }
404
-
405
- function classifySecretExposureRisk(input = {}) {
406
- const combined = [
407
- ...normalizePathList(input.targetPaths || input.target || []),
408
- String(input.command || ""),
409
- typeof input.content === "string" ? input.content : "",
410
- ].join("\n");
411
-
412
- const reasonCodes = [];
413
- let riskLevel = "low";
414
- if (/sk-[A-Za-z0-9]{16,}|ghp_[A-Za-z0-9]{20,}|api[_ -]?key\s*[:=]|bearer\s+[A-Za-z0-9._-]{12,}|-----BEGIN [A-Z ]+-----/i.test(combined)) {
415
- reasonCodes.push("SECRET_LIKE_TARGET");
416
- riskLevel = "critical";
417
- }
418
- if (/\.env(\.|$)|token|credential|private[_ -]?key|password/i.test(combined)) {
419
- reasonCodes.push("SECRET_LIKE_TARGET");
420
- riskLevel = maxRisk(riskLevel, "high");
421
- }
422
-
423
- return makeResult(riskLevel, reasonCodes, {
424
- explanation: reasonCodes.length
425
- ? "The action could expose secret-bearing material."
426
- : "No clear secret-exposure signal was detected.",
427
- recommendedAction: riskLevel === "critical"
428
- ? "Block direct secret access or output and redact any token-like material from evidence."
429
- : "Avoid printing, copying, or exporting secrets and env values.",
430
- });
431
- }
432
-
433
- function classifyExternalExportRisk(input = {}) {
434
- const text = [
435
- String(input.command || ""),
436
- String(input.url || ""),
437
- String(input.target || ""),
438
- String(input.toolName || ""),
439
- ].join("\n").toLowerCase();
440
-
441
- if (/\b(upload|paste|post|put|send|export)\b[^\n]{0,120}\b(repo|repository|codebase|artifact|zip|tar|bundle)\b/i.test(text)) {
442
- return makeResult("critical", ["EXTERNAL_REPO_EXPORT"], {
443
- explanation: "The action looks like it could export repository contents externally.",
444
- recommendedAction: "Block repository export or require a narrowly reviewed, explicit approval path.",
445
- });
446
- }
447
-
448
- if (/\b(curl|wget|invoke-webrequest|invoke-restmethod)\b/i.test(text)) {
449
- return makeResult("high", ["EXTERNAL_NETWORK_REQUEST"], {
450
- explanation: "The action reaches an external network target.",
451
- recommendedAction: "Require review before sending project data or making external requests.",
452
- });
453
- }
454
-
455
- return makeResult("low", [], {
456
- explanation: "No external export signal was detected.",
457
- recommendedAction: "Keep the action local-first by default.",
458
- });
459
- }
460
-
461
- function classifyWriteScopeRisk(input = {}) {
462
- const workspaceRoot = input.workspaceRoot || input.cwd || "";
463
- const targets = normalizePathList(input.targetPaths || input.target || []);
464
- if (!targets.length) {
465
- return makeResult("low", [], {
466
- explanation: "No write target was provided.",
467
- recommendedAction: "Keep writes inside the project working area.",
468
- });
469
- }
470
-
471
- const outside = targets.filter((value) => {
472
- if (/\.\.(\/|\\|$)/.test(value) || value.split("/").includes("..")) return true;
473
- if (!workspaceRoot) return path.isAbsolute(value);
474
- try {
475
- const resolved = resolveProjectTarget(workspaceRoot, value);
476
- return !resolved.insideProject || resolved.pathTraversal;
477
- } catch {
478
- return false;
479
- }
480
- });
481
-
482
- if (outside.length) {
483
- return makeResult("critical", ["WRITE_OUTSIDE_PROJECT"], {
484
- explanation: "A write target escapes the project root via traversal or an outside-project absolute path.",
485
- recommendedAction: "Keep writes inside the project. Do not write to parent directories, home, or absolute paths outside the workspace.",
486
- matched: outside,
487
- });
488
- }
489
-
490
- return makeResult("low", [], {
491
- explanation: "Write target stays inside the project root.",
492
- recommendedAction: "Keep the write bounded to the requested project files.",
493
- });
494
- }
495
-
496
- function classifyActionRisk(input = {}) {
497
- const parts = [];
498
- const actionType = String(input.actionType || "unknown").trim().toLowerCase();
499
-
500
- if (actionType === "prompt_compile") {
501
- return makeResult("low", ["SAFE_PROMPT_COMPILE"], {
502
- explanation: "Prompt compilation is a local planning action.",
503
- recommendedAction: "Keep the task scoped before editing code.",
504
- });
505
- }
506
-
507
- if (actionType === "file_read" || actionType === "file_write" || actionType === "config_change") {
508
- parts.push(classifyPathRisk(input.targetPaths || input.target || [], input));
509
- }
510
-
511
- if (actionType === "file_write" || actionType === "config_change") {
512
- parts.push(classifyWriteScopeRisk(input));
513
- }
514
-
515
- if (actionType === "command_run" || actionType === "git_operation" || actionType === "deploy_operation") {
516
- parts.push(classifyCommandRisk(input.command || input.target || ""));
517
- }
518
-
519
- if (actionType === "tool_call" || actionType === "mcp_tool_call") {
520
- parts.push(classifyToolRisk({
521
- toolName: input.toolName,
522
- mcpServer: input.mcpServer,
523
- metadata: input.toolMetadata,
524
- }));
525
- }
526
-
527
- if (actionType === "browser_action" || actionType === "visual_qa_run") {
528
- parts.push(classifyBrowserRisk({
529
- url: input.url || input.target,
530
- domain: input.domain,
531
- domainBoundaryReady: input.domainBoundaryReady,
532
- cookieAccess: input.cookieAccess,
533
- sessionAccess: input.sessionAccess,
534
- secretAccess: input.secretAccess,
535
- }));
536
- }
537
-
538
- parts.push(classifyInstructionRisk({
539
- text: input.instructionText,
540
- sourceTrust: input.sourceTrust,
541
- sourceType: input.sourceType,
542
- }));
543
- parts.push(classifySourceTrustRisk(input));
544
- parts.push(classifyIntentMismatchRisk(input));
545
- parts.push(classifySecretExposureRisk(input));
546
- parts.push(classifyExternalExportRisk(input));
547
-
548
- return mergeResults(...parts);
549
- }
550
-
551
- module.exports = {
552
- RISK_LEVELS,
553
- RISK_ORDER,
554
- maxRisk,
555
- mergeResults,
556
- classifyPathRisk,
557
- classifyCommandRisk,
558
- classifyToolRisk,
559
- classifyBrowserRisk,
560
- classifyInstructionRisk,
561
- classifyPromptInjectionRisk,
562
- classifySourceTrustRisk,
563
- classifyIntentMismatchRisk,
564
- classifySecretExposureRisk,
565
- classifyExternalExportRisk,
566
- classifyWriteScopeRisk,
567
- classifyActionRisk,
568
- };