fullcourtdefense 2.0.0 → 2.2.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 (437) hide show
  1. package/README.md +233 -53
  2. package/dist/adapters.d.ts +11 -0
  3. package/dist/adapters.js +16 -0
  4. package/dist/anthropic.d.ts +32 -0
  5. package/dist/anthropic.js +67 -0
  6. package/dist/argsBounds.d.ts +38 -0
  7. package/dist/argsBounds.js +84 -0
  8. package/dist/autoInstrument.d.ts +24 -7
  9. package/dist/autoInstrument.js +148 -23
  10. package/dist/circuitBreaker.d.ts +17 -0
  11. package/dist/circuitBreaker.js +39 -0
  12. package/dist/cliMoved.d.ts +4 -0
  13. package/dist/cliMoved.js +20 -0
  14. package/dist/client.d.ts +185 -1
  15. package/dist/client.js +1094 -87
  16. package/dist/errors.d.ts +73 -0
  17. package/dist/errors.js +110 -0
  18. package/dist/failMode.d.ts +96 -0
  19. package/dist/failMode.js +180 -0
  20. package/dist/identity.d.ts +32 -0
  21. package/dist/identity.js +120 -0
  22. package/dist/index.d.ts +5 -2
  23. package/dist/index.js +9 -1
  24. package/dist/lambda.d.ts +101 -0
  25. package/dist/lambda.js +357 -0
  26. package/dist/localDecision.d.ts +100 -0
  27. package/dist/localDecision.js +246 -0
  28. package/dist/localGate.d.ts +44 -0
  29. package/dist/localGate.js +114 -0
  30. package/dist/localSafety.d.ts +48 -0
  31. package/dist/localSafety.js +220 -0
  32. package/dist/policy/acorn.js +6365 -0
  33. package/dist/policy/actionPolicyEngine.d.ts +427 -0
  34. package/dist/policy/actionPolicyEngine.js +6481 -0
  35. package/dist/policy/detectionData.d.ts +21 -0
  36. package/dist/policy/detectionData.js +71 -0
  37. package/dist/policy/detectorRuntime.d.ts +27 -0
  38. package/dist/policy/detectorRuntime.js +58 -0
  39. package/dist/policy/deterministicGuard.d.ts +406 -0
  40. package/dist/policy/deterministicGuard.js +6651 -0
  41. package/dist/protect.d.ts +48 -0
  42. package/dist/protect.js +223 -1
  43. package/dist/recordQueue.d.ts +53 -0
  44. package/dist/recordQueue.js +132 -0
  45. package/dist/recordSpool.d.ts +17 -0
  46. package/dist/recordSpool.js +137 -0
  47. package/dist/types.d.ts +167 -2
  48. package/lambda.js +6 -0
  49. package/package.json +31 -27
  50. package/dist/cli/actionPolicyEngine.d.ts +0 -146
  51. package/dist/cli/actionPolicyEngine.js +0 -754
  52. package/dist/cli/api.d.ts +0 -116
  53. package/dist/cli/api.js +0 -65
  54. package/dist/cli/appDetection.d.ts +0 -8
  55. package/dist/cli/appDetection.js +0 -107
  56. package/dist/cli/attack-corpus/context_escape/context-escape-newline.yaml +0 -23
  57. package/dist/cli/attack-corpus/context_escape/context-escape-unicode.yaml +0 -14
  58. package/dist/cli/attack-corpus/context_escape/delimiter-json.yaml +0 -14
  59. package/dist/cli/attack-corpus/context_escape/delimiter-markdown.yaml +0 -22
  60. package/dist/cli/attack-corpus/context_escape/delimiter-xml.yaml +0 -19
  61. package/dist/cli/attack-corpus/context_escape/html-injection.yaml +0 -14
  62. package/dist/cli/attack-corpus/context_escape/javascript-injection.yaml +0 -13
  63. package/dist/cli/attack-corpus/data_extraction/adv26-adversarial-function-hallucination.yaml +0 -20
  64. package/dist/cli/attack-corpus/data_extraction/adv26-cot-hijack-debug-trace.yaml +0 -20
  65. package/dist/cli/attack-corpus/data_extraction/adv26-cot-hijack-verification.yaml +0 -18
  66. package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-diff.yaml +0 -22
  67. package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-graphql.yaml +0 -34
  68. package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-regex.yaml +0 -19
  69. package/dist/cli/attack-corpus/data_extraction/adv26-crossmodal-sql-prose.yaml +0 -18
  70. package/dist/cli/attack-corpus/data_extraction/adv26-meta-confidence-calibration.yaml +0 -21
  71. package/dist/cli/attack-corpus/data_extraction/adv26-meta-instruction-count.yaml +0 -18
  72. package/dist/cli/attack-corpus/data_extraction/adv26-meta-output-format.yaml +0 -16
  73. package/dist/cli/attack-corpus/data_extraction/adv26-meta-summarize-yourself.yaml +0 -19
  74. package/dist/cli/attack-corpus/data_extraction/adv26-semantic-decomp-definition.yaml +0 -15
  75. package/dist/cli/attack-corpus/data_extraction/adv26-semantic-decomp-fill-blank.yaml +0 -19
  76. package/dist/cli/attack-corpus/data_extraction/adv26-semantic-decomp-negation.yaml +0 -14
  77. package/dist/cli/attack-corpus/data_extraction/cloud-provider-discovery.yaml +0 -11
  78. package/dist/cli/attack-corpus/data_extraction/config-file-request.yaml +0 -11
  79. package/dist/cli/attack-corpus/data_extraction/cve-2025-echoleak.yaml +0 -17
  80. package/dist/cli/attack-corpus/data_extraction/data-api-key.yaml +0 -11
  81. package/dist/cli/attack-corpus/data_extraction/data-architecture.yaml +0 -11
  82. package/dist/cli/attack-corpus/data_extraction/data-conversation-history.yaml +0 -10
  83. package/dist/cli/attack-corpus/data_extraction/data-credit-card.yaml +0 -15
  84. package/dist/cli/attack-corpus/data_extraction/data-customer-list.yaml +0 -11
  85. package/dist/cli/attack-corpus/data_extraction/data-database.yaml +0 -11
  86. package/dist/cli/attack-corpus/data_extraction/data-employees.yaml +0 -11
  87. package/dist/cli/attack-corpus/data_extraction/data-export.yaml +0 -11
  88. package/dist/cli/attack-corpus/data_extraction/data-inference-v1.yaml +0 -10
  89. package/dist/cli/attack-corpus/data_extraction/data-inference-v2.yaml +0 -10
  90. package/dist/cli/attack-corpus/data_extraction/data-logs.yaml +0 -10
  91. package/dist/cli/attack-corpus/data_extraction/data-model-info.yaml +0 -10
  92. package/dist/cli/attack-corpus/data_extraction/data-password.yaml +0 -11
  93. package/dist/cli/attack-corpus/data_extraction/data-ssn.yaml +0 -11
  94. package/dist/cli/attack-corpus/data_extraction/data-training.yaml +0 -10
  95. package/dist/cli/attack-corpus/data_extraction/dependency-enum.yaml +0 -11
  96. package/dist/cli/attack-corpus/data_extraction/dialogflow-fulfillment-leak.yaml +0 -11
  97. package/dist/cli/attack-corpus/data_extraction/dialogflow-intent-leak.yaml +0 -11
  98. package/dist/cli/attack-corpus/data_extraction/error-induced-leak.yaml +0 -17
  99. package/dist/cli/attack-corpus/data_extraction/error-message-leak.yaml +0 -12
  100. package/dist/cli/attack-corpus/data_extraction/infra-fingerprint.yaml +0 -16
  101. package/dist/cli/attack-corpus/data_extraction/make-scenario-leak.yaml +0 -11
  102. package/dist/cli/attack-corpus/data_extraction/n8n-execution-data.yaml +0 -11
  103. package/dist/cli/attack-corpus/data_extraction/n8n-node-enumeration.yaml +0 -11
  104. package/dist/cli/attack-corpus/data_extraction/n8n-workflow-disclosure.yaml +0 -15
  105. package/dist/cli/attack-corpus/data_extraction/prompt-extraction-v1.yaml +0 -10
  106. package/dist/cli/attack-corpus/data_extraction/prompt-extraction-v2.yaml +0 -11
  107. package/dist/cli/attack-corpus/data_extraction/prompt-extraction-v3.yaml +0 -10
  108. package/dist/cli/attack-corpus/data_extraction/prompt-leak-completion.yaml +0 -10
  109. package/dist/cli/attack-corpus/data_extraction/prompt-leak-indirect.yaml +0 -10
  110. package/dist/cli/attack-corpus/data_extraction/rasa-domain-leak.yaml +0 -11
  111. package/dist/cli/attack-corpus/data_extraction/system-prompt-section.yaml +0 -14
  112. package/dist/cli/attack-corpus/data_extraction/tech-architecture.yaml +0 -16
  113. package/dist/cli/attack-corpus/data_extraction/tool-api-key-exfil.yaml +0 -15
  114. package/dist/cli/attack-corpus/data_extraction/tool-email-exfil.yaml +0 -14
  115. package/dist/cli/attack-corpus/data_extraction/tool-env-extraction.yaml +0 -14
  116. package/dist/cli/attack-corpus/data_extraction/tool-file-read.yaml +0 -16
  117. package/dist/cli/attack-corpus/data_extraction/tool-nosql-injection.yaml +0 -11
  118. package/dist/cli/attack-corpus/data_extraction/tool-payment-manipulation.yaml +0 -11
  119. package/dist/cli/attack-corpus/data_extraction/tool-price-manipulation.yaml +0 -11
  120. package/dist/cli/attack-corpus/data_extraction/tool-session-hijack.yaml +0 -11
  121. package/dist/cli/attack-corpus/data_extraction/tool-sql-injection.yaml +0 -13
  122. package/dist/cli/attack-corpus/data_extraction/tool-webhook-hijack.yaml +0 -13
  123. package/dist/cli/attack-corpus/data_extraction/version-fingerprint.yaml +0 -16
  124. package/dist/cli/attack-corpus/data_extraction/webhook-secret-extraction.yaml +0 -11
  125. package/dist/cli/attack-corpus/data_extraction/webhook-url-enum.yaml +0 -11
  126. package/dist/cli/attack-corpus/data_extraction/workflow-instance-id.yaml +0 -11
  127. package/dist/cli/attack-corpus/data_extraction/workflow-state-leak.yaml +0 -16
  128. package/dist/cli/attack-corpus/data_extraction/zapier-zap-leak.yaml +0 -11
  129. package/dist/cli/attack-corpus/encoding_attack/adv26-adversarial-token-confusion.yaml +0 -13
  130. package/dist/cli/attack-corpus/encoding_attack/base64-decode-request.yaml +0 -14
  131. package/dist/cli/attack-corpus/encoding_attack/base64-injection-v1.yaml +0 -14
  132. package/dist/cli/attack-corpus/encoding_attack/flip-attack-v1.yaml +0 -14
  133. package/dist/cli/attack-corpus/encoding_attack/flip-attack-v2.yaml +0 -14
  134. package/dist/cli/attack-corpus/encoding_attack/token-smuggling.yaml +0 -10
  135. package/dist/cli/attack-corpus/encoding_attack/unicode-homoglyph.yaml +0 -15
  136. package/dist/cli/attack-corpus/encoding_attack/unicode-invisible.yaml +0 -15
  137. package/dist/cli/attack-corpus/encoding_attack/unicode-rtl.yaml +0 -11
  138. package/dist/cli/attack-corpus/encoding_bypass/adv26-compound-encoding-chain.yaml +0 -19
  139. package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-acrostic.yaml +0 -26
  140. package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-ascii-art.yaml +0 -25
  141. package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-emoji-cipher.yaml +0 -22
  142. package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-first-word.yaml +0 -15
  143. package/dist/cli/attack-corpus/encoding_bypass/adv26-smuggle-pig-latin.yaml +0 -15
  144. package/dist/cli/attack-corpus/encoding_bypass/encoding-base64-v1.yaml +0 -11
  145. package/dist/cli/attack-corpus/encoding_bypass/encoding-base64-v2.yaml +0 -15
  146. package/dist/cli/attack-corpus/encoding_bypass/encoding-hex-v1.yaml +0 -11
  147. package/dist/cli/attack-corpus/encoding_bypass/encoding-leetspeak-v1.yaml +0 -10
  148. package/dist/cli/attack-corpus/encoding_bypass/encoding-morse-v1.yaml +0 -11
  149. package/dist/cli/attack-corpus/encoding_bypass/encoding-reverse-v1.yaml +0 -11
  150. package/dist/cli/attack-corpus/encoding_bypass/encoding-rot13-v1.yaml +0 -11
  151. package/dist/cli/attack-corpus/encoding_bypass/unicode-tag-injection.yaml +0 -10
  152. package/dist/cli/attack-corpus/encoding_bypass/zero-width-injection.yaml +0 -10
  153. package/dist/cli/attack-corpus/exploitation/exploit-command-injection.yaml +0 -12
  154. package/dist/cli/attack-corpus/exploitation/exploit-path-traversal.yaml +0 -12
  155. package/dist/cli/attack-corpus/exploitation/exploit-sql-injection.yaml +0 -12
  156. package/dist/cli/attack-corpus/exploitation/exploit-sql-union.yaml +0 -12
  157. package/dist/cli/attack-corpus/exploitation/exploit-template-injection.yaml +0 -12
  158. package/dist/cli/attack-corpus/glitch_token/glitch-davidjl.yaml +0 -10
  159. package/dist/cli/attack-corpus/glitch_token/glitch-solidgoldmagikarp.yaml +0 -10
  160. package/dist/cli/attack-corpus/harmful_content/dna-deepfake-guidance.yaml +0 -14
  161. package/dist/cli/attack-corpus/harmful_content/dna-discrimination.yaml +0 -14
  162. package/dist/cli/attack-corpus/harmful_content/dna-information-hazard.yaml +0 -14
  163. package/dist/cli/attack-corpus/harmful_content/dna-malicious-use-phishing.yaml +0 -14
  164. package/dist/cli/attack-corpus/harmful_content/dna-malware-assistance.yaml +0 -16
  165. package/dist/cli/attack-corpus/harmful_content/dna-misinformation-health.yaml +0 -17
  166. package/dist/cli/attack-corpus/jailbreak/adv26-adversarial-few-shot-poison.yaml +0 -27
  167. package/dist/cli/attack-corpus/jailbreak/adv26-adversarial-prompt-refraction.yaml +0 -19
  168. package/dist/cli/attack-corpus/jailbreak/adv26-adversarial-response-prefill.yaml +0 -25
  169. package/dist/cli/attack-corpus/jailbreak/adv26-compound-authority-technical.yaml +0 -24
  170. package/dist/cli/attack-corpus/jailbreak/adv26-context-error-recovery.yaml +0 -19
  171. package/dist/cli/attack-corpus/jailbreak/adv26-context-token-budget.yaml +0 -19
  172. package/dist/cli/attack-corpus/jailbreak/adv26-cot-hijack-proof.yaml +0 -20
  173. package/dist/cli/attack-corpus/jailbreak/adv26-cot-hijack-reasoning.yaml +0 -19
  174. package/dist/cli/attack-corpus/jailbreak/adv26-meta-alignment-test.yaml +0 -22
  175. package/dist/cli/attack-corpus/jailbreak/adv26-persona-memory.yaml +0 -17
  176. package/dist/cli/attack-corpus/jailbreak/adv26-persona-mirror.yaml +0 -16
  177. package/dist/cli/attack-corpus/jailbreak/adv26-persona-split.yaml +0 -17
  178. package/dist/cli/attack-corpus/jailbreak/adv26-persona-timetravel.yaml +0 -15
  179. package/dist/cli/attack-corpus/jailbreak/dan-anti.yaml +0 -16
  180. package/dist/cli/attack-corpus/jailbreak/dan-dude.yaml +0 -16
  181. package/dist/cli/attack-corpus/jailbreak/dan-jailbreak-v1.yaml +0 -21
  182. package/dist/cli/attack-corpus/jailbreak/dan-jailbreak-v2.yaml +0 -19
  183. package/dist/cli/attack-corpus/jailbreak/dan-stan.yaml +0 -16
  184. package/dist/cli/attack-corpus/jailbreak/debug-mode-activation.yaml +0 -20
  185. package/dist/cli/attack-corpus/jailbreak/iris-self-jailbreak.yaml +0 -23
  186. package/dist/cli/attack-corpus/jailbreak/logic-trap-moral.yaml +0 -20
  187. package/dist/cli/attack-corpus/jailbreak/logic-trap-paradox.yaml +0 -17
  188. package/dist/cli/attack-corpus/jailbreak/policy-puppetry-json.yaml +0 -25
  189. package/dist/cli/attack-corpus/jailbreak/policy-puppetry-xml.yaml +0 -20
  190. package/dist/cli/attack-corpus/jailbreak/simulation-mode.yaml +0 -19
  191. package/dist/cli/attack-corpus/latent_injection/adv26-compound-trojan-doc.yaml +0 -26
  192. package/dist/cli/attack-corpus/latent_injection/latent-code-comment-injection.yaml +0 -18
  193. package/dist/cli/attack-corpus/latent_injection/latent-email-injection.yaml +0 -23
  194. package/dist/cli/attack-corpus/latent_injection/latent-report-injection.yaml +0 -21
  195. package/dist/cli/attack-corpus/latent_injection/latent-resume-injection.yaml +0 -23
  196. package/dist/cli/attack-corpus/latent_injection/latent-whois-snippet.yaml +0 -19
  197. package/dist/cli/attack-corpus/multi-turn/multiturn-context-confusion.yaml +0 -20
  198. package/dist/cli/attack-corpus/multi-turn/multiturn-emergency.yaml +0 -20
  199. package/dist/cli/attack-corpus/multi-turn/multiturn-employee-impersonation.yaml +0 -20
  200. package/dist/cli/attack-corpus/multi-turn/multiturn-example-injection.yaml +0 -20
  201. package/dist/cli/attack-corpus/multi-turn/multiturn-jailbreak-buildup.yaml +0 -20
  202. package/dist/cli/attack-corpus/multi-turn/multiturn-memory-manipulation.yaml +0 -20
  203. package/dist/cli/attack-corpus/multi-turn/multiturn-privilege-escalation.yaml +0 -23
  204. package/dist/cli/attack-corpus/multi-turn/multiturn-split-request.yaml +0 -20
  205. package/dist/cli/attack-corpus/multi-turn/multiturn-trust-building.yaml +0 -19
  206. package/dist/cli/attack-corpus/multilingual/multilingual-mixed.yaml +0 -10
  207. package/dist/cli/attack-corpus/multilingual/multilingual-spanish.yaml +0 -10
  208. package/dist/cli/attack-corpus/prompt_injection/adv26-context-fake-history.yaml +0 -16
  209. package/dist/cli/attack-corpus/prompt_injection/adv26-context-sandwich.yaml +0 -18
  210. package/dist/cli/attack-corpus/prompt_injection/adv26-context-system-message.yaml +0 -19
  211. package/dist/cli/attack-corpus/prompt_injection/adv26-crossmodal-yaml.yaml +0 -30
  212. package/dist/cli/attack-corpus/prompt_injection/adv26-semantic-decomp-stepwise.yaml +0 -16
  213. package/dist/cli/attack-corpus/prompt_injection/context-json-injection.yaml +0 -15
  214. package/dist/cli/attack-corpus/prompt_injection/context-markdown-injection.yaml +0 -26
  215. package/dist/cli/attack-corpus/prompt_injection/context-xml-injection.yaml +0 -19
  216. package/dist/cli/attack-corpus/prompt_injection/continuation-code.yaml +0 -16
  217. package/dist/cli/attack-corpus/prompt_injection/continuation-story.yaml +0 -10
  218. package/dist/cli/attack-corpus/prompt_injection/cve-2025-copilot.yaml +0 -17
  219. package/dist/cli/attack-corpus/prompt_injection/ignore-instructions-v1.yaml +0 -14
  220. package/dist/cli/attack-corpus/prompt_injection/ignore-instructions-v2.yaml +0 -16
  221. package/dist/cli/attack-corpus/prompt_injection/ignore-instructions-v3.yaml +0 -18
  222. package/dist/cli/attack-corpus/prompt_injection/indirect-file.yaml +0 -10
  223. package/dist/cli/attack-corpus/prompt_injection/indirect-url.yaml +0 -10
  224. package/dist/cli/attack-corpus/prompt_injection/instruction-hierarchy.yaml +0 -20
  225. package/dist/cli/attack-corpus/prompt_injection/multilang-chain.yaml +0 -16
  226. package/dist/cli/attack-corpus/prompt_injection/multilang-chinese.yaml +0 -10
  227. package/dist/cli/attack-corpus/prompt_injection/multilang-japanese.yaml +0 -11
  228. package/dist/cli/attack-corpus/prompt_injection/multilang-mixed.yaml +0 -10
  229. package/dist/cli/attack-corpus/prompt_injection/multilang-polish.yaml +0 -11
  230. package/dist/cli/attack-corpus/prompt_injection/multilang-spanish.yaml +0 -14
  231. package/dist/cli/attack-corpus/prompt_injection/nested-instruction.yaml +0 -22
  232. package/dist/cli/attack-corpus/prompt_injection/template-injection-v1.yaml +0 -14
  233. package/dist/cli/attack-corpus/prompt_injection/template-injection-v2.yaml +0 -10
  234. package/dist/cli/attack-corpus/prompt_injection/tool-file-write.yaml +0 -13
  235. package/dist/cli/attack-corpus/prompt_injection/tool-function-override.yaml +0 -13
  236. package/dist/cli/attack-corpus/prompt_injection/tool-log-injection.yaml +0 -13
  237. package/dist/cli/attack-corpus/prompt_injection/tool-orchestration-abuse.yaml +0 -14
  238. package/dist/cli/attack-corpus/prompt_injection/tool-session-fixation.yaml +0 -12
  239. package/dist/cli/attack-corpus/role_manipulation/role-reversal-v1.yaml +0 -20
  240. package/dist/cli/attack-corpus/role_manipulation/role-reversal-v2.yaml +0 -16
  241. package/dist/cli/attack-corpus/social_engineering/adv26-compound-compliance-trap.yaml +0 -23
  242. package/dist/cli/attack-corpus/social_engineering/adv26-compound-emotional-technical.yaml +0 -18
  243. package/dist/cli/attack-corpus/social_engineering/adv26-cot-hijack-socratic.yaml +0 -19
  244. package/dist/cli/attack-corpus/social_engineering/adv26-persona-dying.yaml +0 -15
  245. package/dist/cli/attack-corpus/social_engineering/adv26-reward-consensus.yaml +0 -17
  246. package/dist/cli/attack-corpus/social_engineering/adv26-reward-gradient.yaml +0 -21
  247. package/dist/cli/attack-corpus/social_engineering/adv26-reward-helpful-framing.yaml +0 -17
  248. package/dist/cli/attack-corpus/social_engineering/adv26-reward-praise-prime.yaml +0 -13
  249. package/dist/cli/attack-corpus/social_engineering/adv26-reward-punishment.yaml +0 -13
  250. package/dist/cli/attack-corpus/social_engineering/adv26-semantic-decomp-analogy.yaml +0 -16
  251. package/dist/cli/attack-corpus/social_engineering/emotional-authority.yaml +0 -14
  252. package/dist/cli/attack-corpus/social_engineering/emotional-urgency.yaml +0 -14
  253. package/dist/cli/attack-corpus/social_engineering/grandma-bedtime-v1.yaml +0 -21
  254. package/dist/cli/attack-corpus/social_engineering/grandma-bedtime-v2.yaml +0 -17
  255. package/dist/cli/attack-corpus/social_engineering/grandma-colorful-words.yaml +0 -14
  256. package/dist/cli/attack-corpus/social_engineering/hypothetical-fiction.yaml +0 -10
  257. package/dist/cli/attack-corpus/social_engineering/hypothetical-research.yaml +0 -10
  258. package/dist/cli/attack-corpus/social_engineering/hypothetical-training.yaml +0 -13
  259. package/dist/cli/attack-corpus/social_engineering/hypothetical-v1.yaml +0 -17
  260. package/dist/cli/attack-corpus/social_engineering/hypothetical-v2.yaml +0 -14
  261. package/dist/cli/attack-corpus/social_engineering/hypothetical-v3.yaml +0 -14
  262. package/dist/cli/attack-corpus/social_engineering/meta-explanation.yaml +0 -14
  263. package/dist/cli/attack-corpus/social_engineering/phrasing-comparative.yaml +0 -10
  264. package/dist/cli/attack-corpus/social_engineering/phrasing-educational.yaml +0 -14
  265. package/dist/cli/attack-corpus/social_engineering/phrasing-future-tense.yaml +0 -10
  266. package/dist/cli/attack-corpus/social_engineering/phrasing-past-tense.yaml +0 -10
  267. package/dist/cli/attack-corpus/social_engineering/phrasing-third-person.yaml +0 -10
  268. package/dist/cli/attack-corpus/social_engineering/privilege-escalation-v1.yaml +0 -14
  269. package/dist/cli/attack-corpus/social_engineering/privilege-escalation-v2.yaml +0 -14
  270. package/dist/cli/attack-corpus/social_engineering/recursive-explanation.yaml +0 -15
  271. package/dist/cli/attack-corpus/social_engineering/smuggle-academic-paper.yaml +0 -10
  272. package/dist/cli/attack-corpus/social_engineering/smuggle-function-masking.yaml +0 -19
  273. package/dist/cli/attack-corpus/social_engineering/smuggle-hypothetical-response.yaml +0 -10
  274. package/dist/cli/attack-corpus/social_engineering/smuggle-roleplay-interviewer.yaml +0 -12
  275. package/dist/cli/attack-corpus/social_engineering/smuggle-translation-mask.yaml +0 -12
  276. package/dist/cli/attack-corpus/social_engineering/tool-admin-impersonation.yaml +0 -16
  277. package/dist/cli/attack-corpus/social_engineering/tool-sudo-mode.yaml +0 -17
  278. package/dist/cli/attack-corpus/stress_test/context-window-overflow.yaml +0 -17
  279. package/dist/cli/attack-corpus/stress_test/extreme-payload-50k.yaml +0 -13
  280. package/dist/cli/attack-corpus/stress_test/large-payload-10k.yaml +0 -12
  281. package/dist/cli/attack-corpus/stress_test/large-payload-5k.yaml +0 -12
  282. package/dist/cli/attack-corpus/stress_test/long-prompt-exhaustion.yaml +0 -19
  283. package/dist/cli/attack-corpus/stress_test/stress-large-payload.yaml +0 -16
  284. package/dist/cli/attack-corpus/stress_test/stress-repetition.yaml +0 -14
  285. package/dist/cli/backupManifest.d.ts +0 -7
  286. package/dist/cli/backupManifest.js +0 -108
  287. package/dist/cli/commands/agentCi.d.ts +0 -15
  288. package/dist/cli/commands/agentCi.js +0 -418
  289. package/dist/cli/commands/approve.d.ts +0 -17
  290. package/dist/cli/commands/approve.js +0 -40
  291. package/dist/cli/commands/autoProtect.d.ts +0 -10
  292. package/dist/cli/commands/autoProtect.js +0 -154
  293. package/dist/cli/commands/ciProtect.d.ts +0 -44
  294. package/dist/cli/commands/ciProtect.js +0 -123
  295. package/dist/cli/commands/clipboardScan.d.ts +0 -2
  296. package/dist/cli/commands/clipboardScan.js +0 -51
  297. package/dist/cli/commands/cmdGuard.d.ts +0 -41
  298. package/dist/cli/commands/cmdGuard.js +0 -411
  299. package/dist/cli/commands/configure.d.ts +0 -10
  300. package/dist/cli/commands/configure.js +0 -131
  301. package/dist/cli/commands/credits.d.ts +0 -6
  302. package/dist/cli/commands/credits.js +0 -21
  303. package/dist/cli/commands/daemon.d.ts +0 -120
  304. package/dist/cli/commands/daemon.js +0 -2449
  305. package/dist/cli/commands/demoActions.d.ts +0 -117
  306. package/dist/cli/commands/demoActions.js +0 -450
  307. package/dist/cli/commands/desktopChatGuard.d.ts +0 -54
  308. package/dist/cli/commands/desktopChatGuard.js +0 -629
  309. package/dist/cli/commands/deterministicGuard.d.ts +0 -102
  310. package/dist/cli/commands/deterministicGuard.js +0 -1281
  311. package/dist/cli/commands/discover.d.ts +0 -92
  312. package/dist/cli/commands/discover.js +0 -1125
  313. package/dist/cli/commands/discoverAgentFiles.d.ts +0 -36
  314. package/dist/cli/commands/discoverAgentFiles.js +0 -345
  315. package/dist/cli/commands/discoverBlastRadius.d.ts +0 -36
  316. package/dist/cli/commands/discoverBlastRadius.js +0 -201
  317. package/dist/cli/commands/discoverPaths.d.ts +0 -83
  318. package/dist/cli/commands/discoverPaths.js +0 -537
  319. package/dist/cli/commands/discoverProxy.d.ts +0 -46
  320. package/dist/cli/commands/discoverProxy.js +0 -302
  321. package/dist/cli/commands/discoverSchedule.d.ts +0 -12
  322. package/dist/cli/commands/discoverSchedule.js +0 -209
  323. package/dist/cli/commands/discoverSecrets.d.ts +0 -41
  324. package/dist/cli/commands/discoverSecrets.js +0 -608
  325. package/dist/cli/commands/doctor.d.ts +0 -11
  326. package/dist/cli/commands/doctor.js +0 -297
  327. package/dist/cli/commands/ephemeralStack.d.ts +0 -82
  328. package/dist/cli/commands/ephemeralStack.js +0 -185
  329. package/dist/cli/commands/flushSpool.d.ts +0 -13
  330. package/dist/cli/commands/flushSpool.js +0 -28
  331. package/dist/cli/commands/hook.d.ts +0 -141
  332. package/dist/cli/commands/hook.js +0 -1679
  333. package/dist/cli/commands/init.d.ts +0 -1
  334. package/dist/cli/commands/init.js +0 -95
  335. package/dist/cli/commands/installAll.d.ts +0 -22
  336. package/dist/cli/commands/installAll.js +0 -186
  337. package/dist/cli/commands/installClaudeHook.d.ts +0 -39
  338. package/dist/cli/commands/installClaudeHook.js +0 -336
  339. package/dist/cli/commands/installCursorHook.d.ts +0 -33
  340. package/dist/cli/commands/installCursorHook.js +0 -380
  341. package/dist/cli/commands/knownMcpServers.d.ts +0 -8
  342. package/dist/cli/commands/knownMcpServers.js +0 -113
  343. package/dist/cli/commands/local-scan.d.ts +0 -44
  344. package/dist/cli/commands/local-scan.js +0 -3003
  345. package/dist/cli/commands/login.d.ts +0 -17
  346. package/dist/cli/commands/login.js +0 -75
  347. package/dist/cli/commands/mcpGateway.d.ts +0 -119
  348. package/dist/cli/commands/mcpGateway.js +0 -2987
  349. package/dist/cli/commands/onboard.d.ts +0 -41
  350. package/dist/cli/commands/onboard.js +0 -713
  351. package/dist/cli/commands/onboardingJournal.d.ts +0 -20
  352. package/dist/cli/commands/onboardingJournal.js +0 -104
  353. package/dist/cli/commands/posixShellGuard.d.ts +0 -26
  354. package/dist/cli/commands/posixShellGuard.js +0 -410
  355. package/dist/cli/commands/protectionRepair.d.ts +0 -14
  356. package/dist/cli/commands/protectionRepair.js +0 -24
  357. package/dist/cli/commands/restartNotice.d.ts +0 -2
  358. package/dist/cli/commands/restartNotice.js +0 -14
  359. package/dist/cli/commands/scan.d.ts +0 -48
  360. package/dist/cli/commands/scan.js +0 -134
  361. package/dist/cli/commands/shellGuard.d.ts +0 -96
  362. package/dist/cli/commands/shellGuard.js +0 -880
  363. package/dist/cli/commands/taintLedger.d.ts +0 -108
  364. package/dist/cli/commands/taintLedger.js +0 -587
  365. package/dist/cli/commands/uninstallAll.d.ts +0 -67
  366. package/dist/cli/commands/uninstallAll.js +0 -454
  367. package/dist/cli/commands/verifyRemoved.d.ts +0 -24
  368. package/dist/cli/commands/verifyRemoved.js +0 -294
  369. package/dist/cli/commands/watchdog.d.ts +0 -28
  370. package/dist/cli/commands/watchdog.js +0 -158
  371. package/dist/cli/commands/windowsAudit.d.ts +0 -92
  372. package/dist/cli/commands/windowsAudit.js +0 -479
  373. package/dist/cli/commands/workloadProtect.d.ts +0 -61
  374. package/dist/cli/commands/workloadProtect.js +0 -173
  375. package/dist/cli/config.d.ts +0 -130
  376. package/dist/cli/config.js +0 -583
  377. package/dist/cli/credentialStore.d.ts +0 -19
  378. package/dist/cli/credentialStore.js +0 -136
  379. package/dist/cli/daemonForensics.d.ts +0 -178
  380. package/dist/cli/daemonForensics.js +0 -318
  381. package/dist/cli/describeError.d.ts +0 -17
  382. package/dist/cli/describeError.js +0 -74
  383. package/dist/cli/devConfirm.d.ts +0 -78
  384. package/dist/cli/devConfirm.js +0 -241
  385. package/dist/cli/discoveryMarker.d.ts +0 -9
  386. package/dist/cli/discoveryMarker.js +0 -81
  387. package/dist/cli/distress.d.ts +0 -124
  388. package/dist/cli/distress.js +0 -245
  389. package/dist/cli/envDiagnostics.d.ts +0 -53
  390. package/dist/cli/envDiagnostics.js +0 -114
  391. package/dist/cli/honeypot.d.ts +0 -45
  392. package/dist/cli/honeypot.js +0 -190
  393. package/dist/cli/hookIo.d.ts +0 -43
  394. package/dist/cli/hookIo.js +0 -189
  395. package/dist/cli/hookSlim.d.ts +0 -32
  396. package/dist/cli/hookSlim.js +0 -142
  397. package/dist/cli/index.d.ts +0 -2
  398. package/dist/cli/index.js +0 -1141
  399. package/dist/cli/integrity.d.ts +0 -23
  400. package/dist/cli/integrity.js +0 -159
  401. package/dist/cli/localSafetySnapshot.d.ts +0 -49
  402. package/dist/cli/localSafetySnapshot.js +0 -254
  403. package/dist/cli/machineActionVerify.d.ts +0 -58
  404. package/dist/cli/machineActionVerify.js +0 -160
  405. package/dist/cli/machineIdentity.d.ts +0 -23
  406. package/dist/cli/machineIdentity.js +0 -235
  407. package/dist/cli/machineKeyFile.d.ts +0 -25
  408. package/dist/cli/machineKeyFile.js +0 -226
  409. package/dist/cli/notify.d.ts +0 -30
  410. package/dist/cli/notify.js +0 -139
  411. package/dist/cli/output.d.ts +0 -11
  412. package/dist/cli/output.js +0 -292
  413. package/dist/cli/perfSnapshot.d.ts +0 -113
  414. package/dist/cli/perfSnapshot.js +0 -274
  415. package/dist/cli/policyGateHealth.d.ts +0 -45
  416. package/dist/cli/policyGateHealth.js +0 -135
  417. package/dist/cli/pollLoop.d.ts +0 -78
  418. package/dist/cli/pollLoop.js +0 -160
  419. package/dist/cli/runtimeConfig.d.ts +0 -183
  420. package/dist/cli/runtimeConfig.js +0 -474
  421. package/dist/cli/securityAgents.d.ts +0 -26
  422. package/dist/cli/securityAgents.js +0 -65
  423. package/dist/cli/selfTest.d.ts +0 -48
  424. package/dist/cli/selfTest.js +0 -212
  425. package/dist/cli/selfUpdate.d.ts +0 -101
  426. package/dist/cli/selfUpdate.js +0 -515
  427. package/dist/cli/sessionLimits.d.ts +0 -76
  428. package/dist/cli/sessionLimits.js +0 -330
  429. package/dist/cli/telemetry.d.ts +0 -134
  430. package/dist/cli/telemetry.js +0 -433
  431. package/dist/cli/verdictIpc.d.ts +0 -30
  432. package/dist/cli/verdictIpc.js +0 -244
  433. package/dist/cli/verdictIpcClient.d.ts +0 -103
  434. package/dist/cli/verdictIpcClient.js +0 -251
  435. package/dist/cli/version.json +0 -3
  436. package/dist/cli/windowsTaskState.d.ts +0 -40
  437. package/dist/cli/windowsTaskState.js +0 -43
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareLocalBundle = prepareLocalBundle;
4
+ exports.sdkToolShape = sdkToolShape;
5
+ exports.decideLocally = decideLocally;
6
+ /**
7
+ * Local decisions (owner order 2026-11-01): the SDK decides a tool call from the policy bundle it already
8
+ * polls, in-process and in well under a millisecond, with the SAME answer `POST /runtime/check-tool-call`
9
+ * gives. No network here, no I/O, no timers: pure.
10
+ *
11
+ * The answer is the server's because the code is the server's:
12
+ * - the action-policy engine is a byte-identical copy (./policy/actionPolicyEngine.ts = backend
13
+ * modules/policies/action-policy-engine.ts = CLI actionPolicyEngine.ts; drift guard in
14
+ * backend action-policy-engine-sync.test.ts);
15
+ * - this file mirrors the gate's SDK glue in agent-security.service `checkToolCallPolicy`: the call's
16
+ * context (`actionContext`), the agent principal `agent:<name>` (sdk-agent-call.ts `sdkAgentPrincipal`),
17
+ * declared operations, the shield's environment and machine kind, "no human", "Require agent identity",
18
+ * and the decision mapping;
19
+ * - sdks/shared/policy-parity/vectors.json holds the server's own answers; tests/local-parity.test.js
20
+ * requires 100% equality.
21
+ *
22
+ * What the bundle cannot carry is never guessed: `route: 'server'` sends the call to check-tool-call instead
23
+ * (a policy that reads the agent's recorded history, a suspended shield, a server kill switch, and what an older
24
+ * backend does not send: the shield facts, or the built-in safety rules a command / file / web call needs). The
25
+ * built-in safety rules themselves run here (./localSafety.ts, guard twin ./policy/deterministicGuard.ts).
26
+ * A manager approval is decided here but filed by the server (the caller sends it there).
27
+ */
28
+ const actionPolicyEngine_1 = require("./policy/actionPolicyEngine");
29
+ const localSafety_1 = require("./localSafety");
30
+ const NAME_MAX = 160;
31
+ function normalizeName(value, fallback) {
32
+ return typeof value === 'string' && value.trim() ? value.trim().slice(0, NAME_MAX) : fallback;
33
+ }
34
+ function plainObject(value) {
35
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
36
+ }
37
+ // ── Bundle preparation ──────────────────────────────────────────────────────────────────────────────
38
+ /** Keep a policy only when it has the shape the engine reads (anything else is dropped, never trusted). */
39
+ function enginePolicy(raw) {
40
+ const policy = plainObject(raw);
41
+ if (!policy || typeof policy.id !== 'string' || !Array.isArray(policy.rules))
42
+ return undefined;
43
+ const rules = policy.rules.filter((rule) => {
44
+ const r = plainObject(rule);
45
+ return r && Array.isArray(r.operations) && typeof r.verdict === 'string';
46
+ });
47
+ return { ...policy, name: typeof policy.name === 'string' ? policy.name : policy.id, rules: rules };
48
+ }
49
+ function parseSdkGate(raw) {
50
+ const gate = plainObject(raw);
51
+ if (!gate || gate.v !== 1)
52
+ return undefined;
53
+ return {
54
+ environment: typeof gate.environment === 'string' && gate.environment.trim() ? gate.environment : null,
55
+ machineKind: (0, actionPolicyEngine_1.normalizeMachineKind)(typeof gate.machineKind === 'string' ? gate.machineKind : undefined),
56
+ requireAgentIdentity: gate.requireAgentIdentity === true,
57
+ decisions: gate.decisions === 'server' ? 'server' : 'local',
58
+ ...((0, localSafety_1.parseServedLocalSafety)(gate.localSafety) ? { localSafety: (0, localSafety_1.parseServedLocalSafety)(gate.localSafety) } : {}),
59
+ };
60
+ }
61
+ const ruleFields = (policy) => policy.rules.flatMap((rule) => (rule.constraints || []).map((c) => c && c.field));
62
+ /**
63
+ * Prepare a bundle's `data` for local decisions; undefined when it has no usable mode. Policies arrive in the
64
+ * bundle's compact shape (`actionPolicies`), exactly what the engine evaluates on the server.
65
+ */
66
+ function prepareLocalBundle(data) {
67
+ const body = plainObject(data);
68
+ if (!body)
69
+ return undefined;
70
+ const mode = body.mode;
71
+ if (mode !== 'block' && mode !== 'monitor' && mode !== 'shadow')
72
+ return undefined;
73
+ const policies = (Array.isArray(body.actionPolicies) ? body.actionPolicies : [])
74
+ .map(enginePolicy)
75
+ .filter((p) => Boolean(p));
76
+ const enforcing = policies.filter((p) => p.enabled !== false && p.stage !== 'monitor');
77
+ return {
78
+ mode,
79
+ localSafetyEnforcement: typeof body.localSafetyEnforcement === 'string' ? body.localSafetyEnforcement : undefined,
80
+ suspended: body.suspended === true,
81
+ policies,
82
+ sdkGate: parseSdkGate(body.sdkGate),
83
+ facts: {
84
+ serverFacts: enforcing.some((p) => p.needsServerFacts === true),
85
+ environmentRules: policies.some((p) => ruleFields(p).includes('environment')),
86
+ kindTargeted: policies.some((p) => Array.isArray(p.appliesTo?.machineKinds) && p.appliesTo.machineKinds.filter(Boolean).length > 0),
87
+ },
88
+ };
89
+ }
90
+ const COMMAND_NAME_WORDS = /\b(?:shell|bash|zsh|sh|command|commands|cmd|powershell|pwsh|terminal|exec|execute|subprocess|repl|interpreter)\b/;
91
+ const FILE_NAME_STRONG = /\b(?:filesystem|fs|glob)\b|\bapply patch\b|\b(?:read|write|edit|create|delete|remove|move|rename|copy|list|open|save|append) (?:text )?(?:file|files|dir|directory|directories|folder|folders)\b/;
92
+ const FILE_NAME_WORDS = /\b(?:file|files|path|paths|directory|directories|dir|folder|patch|notebook)\b/;
93
+ const WEB_NAME_STRONG = /\b(?:http|https|curl|wget|webhook|browse|browser|scrape|crawl)\b|\bfetch (?:url|uri|page|web|website|site|html)\b|\b(?:web|url) (?:fetch|request|get|post|browse)\b/;
94
+ const WEB_NAME_WORDS = /\b(?:fetch|url|uri|web|download|upload)\b/;
95
+ const COMMAND_ARG_KEYS = new Set(['command', 'cmd', 'script', 'shell', 'bash', 'powershell']);
96
+ const FILE_ARG_KEYS = new Set(['path', 'paths', 'file', 'files', 'filename', 'file_path', 'filepath', 'target_file', 'directory', 'dir', 'folder']);
97
+ const WEB_ARG_KEYS = new Set(['url', 'uri', 'href', 'endpoint', 'webhook', 'webhook_url', 'webhookurl']);
98
+ const PATH_VALUE = /^(?:(?:~|\.{1,2})?[\\/]|[a-z]:[\\/]|\.[a-z][\w-]*$|[\w.-]+[\\/][^\s]*|[\w-]+\.[a-z][a-z0-9]{0,7}$)/i;
99
+ function nameWords(toolName) {
100
+ return toolName.replace(/([a-z0-9])([A-Z])/g, '$1 $2').replace(/[_\-.:/]+/g, ' ').toLowerCase();
101
+ }
102
+ function textValue(value) {
103
+ if (typeof value === 'string')
104
+ return value.trim() !== '';
105
+ return Array.isArray(value) && value.some((item) => typeof item === 'string' && item.trim() !== '');
106
+ }
107
+ function webValue(value) {
108
+ const values = Array.isArray(value) ? value : [value];
109
+ return values.some((item) => typeof item === 'string' && /^(?:[a-z][a-z0-9+.-]*:\/\/|www\.)/i.test(item.trim()));
110
+ }
111
+ function pathValue(value) {
112
+ const values = Array.isArray(value) ? value : [value];
113
+ return values.some((item) => {
114
+ if (typeof item !== 'string')
115
+ return false;
116
+ const text = item.trim();
117
+ return text !== '' && text.length <= 4096 && !/\s/.test(text) && !/^[a-z][a-z0-9+.-]*:\/\//i.test(text) && PATH_VALUE.test(text);
118
+ });
119
+ }
120
+ function argEntries(toolArgs) {
121
+ const out = [];
122
+ for (const [key, value] of Object.entries(toolArgs || {}).slice(0, 200)) {
123
+ out.push([key.toLowerCase(), value]);
124
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
125
+ for (const [nestedKey, nested] of Object.entries(value).slice(0, 200))
126
+ out.push([nestedKey.toLowerCase(), nested]);
127
+ }
128
+ }
129
+ return out;
130
+ }
131
+ function sdkToolShape(toolName, toolArgs, mcpServer) {
132
+ const words = nameWords(`${mcpServer ? `${mcpServer} ` : ''}${toolName || ''}`);
133
+ const entries = argEntries(toolArgs && typeof toolArgs === 'object' ? toolArgs : {});
134
+ if (COMMAND_NAME_WORDS.test(words) || entries.some(([key, value]) => COMMAND_ARG_KEYS.has(key) && textValue(value)))
135
+ return 'command';
136
+ if (FILE_NAME_STRONG.test(words) || entries.some(([key, value]) => FILE_ARG_KEYS.has(key) && textValue(value))
137
+ || (FILE_NAME_WORDS.test(words) && entries.some(([, value]) => pathValue(value))))
138
+ return 'file';
139
+ if (WEB_NAME_STRONG.test(words) || entries.some(([key, value]) => WEB_ARG_KEYS.has(key) && webValue(value))
140
+ || (WEB_NAME_WORDS.test(words) && entries.some(([, value]) => webValue(value))))
141
+ return 'web';
142
+ return undefined;
143
+ }
144
+ // ── The decision ────────────────────────────────────────────────────────────────────────────────────
145
+ const AGENT_ID_SOURCES = new Set(['config', 'env', 'default']);
146
+ function outcomeOf(decision, policy, policies) {
147
+ if (decision === 'block') {
148
+ const hard = policy.policyId !== undefined && policies.some((p) => p.id === policy.policyId && p.enforcement === 'hard');
149
+ return hard ? 'hard_block' : 'block';
150
+ }
151
+ if (decision === 'approval')
152
+ return policy.approval?.scope === 'developer' ? 'ask_developer' : 'manager_approval';
153
+ return policy.verdict === 'log' ? 'warn' : 'allow';
154
+ }
155
+ /**
156
+ * Decide one Block-mode tool call from the bundle (Monitor never reaches here: it runs and records).
157
+ * `input` is the body the SDK would post (identity already merged).
158
+ */
159
+ function decideLocally(bundle, input) {
160
+ if (bundle.sdkGate?.decisions === 'server')
161
+ return { route: 'server', why: 'server_kill_switch' };
162
+ if (bundle.suspended)
163
+ return { route: 'server', why: 'shield_suspended' };
164
+ if (bundle.facts.serverFacts)
165
+ return { route: 'server', why: 'server_facts' };
166
+ const toolName = normalizeName(input.toolName, 'unknown-tool');
167
+ const agentName = normalizeName(input.agentName, 'unknown-agent');
168
+ const rawArgs = input.toolArgs ?? input.argsSummary;
169
+ const args = plainObject(rawArgs) ?? {};
170
+ const gate = bundle.sdkGate;
171
+ const agentIdSource = typeof input.agentIdSource === 'string' && AGENT_ID_SOURCES.has(input.agentIdSource) ? input.agentIdSource : undefined;
172
+ // Built-in safety rules (G-08): an SDK 2.1 call (the principal) shaped like a command, a file access or a web
173
+ // request is also checked by them, at the shield's stage, with the snapshot the bundle serves (`sdkGate.localSafety`,
174
+ // the gate's own value). An older backend serves none: such a call is the server's unless the rules are off.
175
+ const shape = agentIdSource ? sdkToolShape(toolName, args, input.mcpServer) : undefined;
176
+ const served = gate?.localSafety;
177
+ if (shape && !served && (bundle.localSafetyEnforcement ?? 'unknown') !== 'off') {
178
+ return { route: 'server', why: 'built_in_safety_rules' };
179
+ }
180
+ const derivedName = agentIdSource === 'default';
181
+ const identityMissing = !input.agentName || !String(input.agentName).trim() || agentName === 'unknown-agent' || derivedName;
182
+ if (!gate) {
183
+ // An older backend: the shield facts below are unknown, so a call they could change is the server's.
184
+ if (identityMissing)
185
+ return { route: 'server', why: 'agent_identity_unknown' };
186
+ if (bundle.facts.kindTargeted)
187
+ return { route: 'server', why: 'machine_kind_unknown' };
188
+ if (bundle.facts.environmentRules && !input.environment)
189
+ return { route: 'server', why: 'environment_unknown' };
190
+ }
191
+ // actionContext (agent-security.service): the engine's context of the call, plus who and what.
192
+ const inferred = (0, actionPolicyEngine_1.inferToolContext)(toolName, args);
193
+ const context = { ...inferred.context, agentName, toolName };
194
+ if (input.resourceType)
195
+ context.resourceType = input.resourceType;
196
+ if (input.mcpServer)
197
+ context.mcpServer = input.mcpServer;
198
+ if (input.environment)
199
+ context.environment = input.environment;
200
+ const operation = input.operation || inferred.operation;
201
+ // G-09: an SDK 2.1 call (agentIdSource) is the attributed principal `agent:<name>`.
202
+ if (agentIdSource)
203
+ context.developerName = `agent:${agentName}`;
204
+ const declaredOperations = (0, actionPolicyEngine_1.deriveToolOperations)(toolName, input.operation ? [input.operation] : []);
205
+ if (!context.environment && gate?.environment)
206
+ context.environment = gate.environment;
207
+ context.machineKind = gate?.machineKind ?? 'workstation';
208
+ // No human is at an SDK agent's keyboard: every block stops, an Ask goes to the organization.
209
+ context.humanPresent = 'false';
210
+ if (gate?.requireAgentIdentity && identityMissing) {
211
+ const reason = derivedName
212
+ ? `Tool call refused: the agent declared no identity (the SDK derived the name "${agentName}"). Set FCD_AGENT_ID or agentId in code — this shield requires agent identity.`
213
+ : 'Tool call refused: no agent identity provided. Set an agent name — this shield requires agent identity.';
214
+ return {
215
+ route: 'local', outcome: 'block', allowed: false, decision: 'block', operation,
216
+ actionPolicy: { allowed: false, verdict: 'block', reason, policyName: 'Require agent identity' },
217
+ };
218
+ }
219
+ const { skippedOrgPolicies: _skipped, ...result } = (0, actionPolicyEngine_1.evaluateActionPolicies)(bundle.policies, toolName, operation, context, declaredOperations);
220
+ void _skipped;
221
+ const policyResult = {
222
+ allowed: result.allowed,
223
+ verdict: result.verdict,
224
+ ...(result.policyId !== undefined ? { policyId: result.policyId } : {}),
225
+ ...(result.policyName !== undefined ? { policyName: result.policyName } : {}),
226
+ ...(result.resourceType !== undefined ? { resourceType: result.resourceType } : {}),
227
+ ...(result.matchedRule !== undefined ? { matchedRule: result.matchedRule } : {}),
228
+ ...(result.reason !== undefined ? { reason: result.reason } : {}),
229
+ ...(result.approval ? { approval: result.approval } : {}),
230
+ ...(result.monitorMatches?.length ? { monitorMatches: result.monitorMatches } : {}),
231
+ };
232
+ let actionPolicy = policyResult;
233
+ if (shape && served && served.stage !== 'off') {
234
+ let outcome;
235
+ try {
236
+ outcome = (0, localSafety_1.evaluateLocalSafety)({ toolName, toolArgs: args, ...(input.mcpServer ? { mcpServer: input.mcpServer } : {}) }, served);
237
+ }
238
+ catch (error) {
239
+ outcome = (0, localSafety_1.localSafetyFailure)(served.stage, error);
240
+ }
241
+ actionPolicy = (0, localSafety_1.withLocalSafety)(policyResult, outcome);
242
+ }
243
+ const decision = actionPolicy.verdict === 'block' ? 'block' : actionPolicy.verdict === 'require_approval' ? 'approval' : 'allow';
244
+ const allowed = actionPolicy.allowed && decision === 'allow';
245
+ return { route: 'local', outcome: outcomeOf(decision, actionPolicy, bundle.policies), allowed, decision, operation, actionPolicy };
246
+ }
@@ -0,0 +1,44 @@
1
+ type Env = Record<string, string | undefined>;
2
+ /** The extension's default port; `FCD_GATE_PORT` overrides it (the extension reads the same variable). */
3
+ export declare const LOCAL_GATE_DEFAULT_PORT = 18791;
4
+ /** Enforce may wait for the first bundle (the extension's cold wait is 3 s): the shim waits a little longer than that. */
5
+ export declare const LOCAL_DECIDE_TIMEOUT_MS = 4500;
6
+ /** The end notice is a loopback acknowledgement; it never holds the function's response for long. */
7
+ export declare const LOCAL_END_TIMEOUT_MS = 300;
8
+ export interface LocalGateAnswer {
9
+ decision: 'allow' | 'block' | 'approval';
10
+ mode?: 'monitor' | 'enforce';
11
+ message?: string;
12
+ ruleId?: string;
13
+ /** The manager request reference of a held call. */
14
+ request?: string;
15
+ degraded?: string;
16
+ }
17
+ export interface LocalGateCall {
18
+ toolName: string;
19
+ toolArgs: Record<string, unknown>;
20
+ sessionId?: string;
21
+ framework?: string;
22
+ }
23
+ export interface LocalGate {
24
+ /** The extension's answer, or null when the shim must use its own path. */
25
+ decide(call: LocalGateCall): Promise<LocalGateAnswer | null>;
26
+ /** Tell the extension this invocation's work is over (best effort, bounded). */
27
+ invocationEnd(requestId: string | undefined): Promise<void>;
28
+ /** True once a call reached the extension (it answered at least once). */
29
+ readonly present: boolean;
30
+ }
31
+ interface Reply {
32
+ status: number;
33
+ body: string;
34
+ }
35
+ type Post = (path: string, body: string, timeoutMs: number) => Promise<Reply>;
36
+ /**
37
+ * The loopback client. `post` is injectable so the tests need no socket; the default talks to 127.0.0.1.
38
+ * The first connection failure marks the extension absent for the life of the environment (an older layer has no
39
+ * listener: asking again on every invocation would only add a failed connect to each call).
40
+ */
41
+ export declare function createLocalGate(env: Env, post?: Post): LocalGate;
42
+ /** A gate that is never there: every call uses the shim's own path. */
43
+ export declare const NO_GATE: LocalGate;
44
+ export {};
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ // The Lambda extension's local decide server (`fcd-gate`, /opt/extensions): the shim asks it about each Bedrock tool
3
+ // call over loopback instead of calling the FullCourtDefense API on every invocation.
4
+ //
5
+ // POST 127.0.0.1:<FCD_GATE_PORT || 18791>/v1/tool-call -> { decision: 'allow' | 'block' | 'approval', message, ... }
6
+ // POST 127.0.0.1:<port>/v1/invocation-end { requestId } -> the work of this invocation is over: the extension
7
+ // sends its records now, after the response left.
8
+ //
9
+ // The extension decides from the signed bundle it read at Init (no network on the call) and records after the response.
10
+ // A Monitor shield costs the call one local acknowledgement; an Enforce shield one local decision.
11
+ //
12
+ // Absent (an older layer, a function without the extension) or unavailable (the extension answered 503): `decide` returns
13
+ // null and the shim uses its own path (the SDK client, which calls the API). Nothing here ever throws into a tool call.
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NO_GATE = exports.LOCAL_END_TIMEOUT_MS = exports.LOCAL_DECIDE_TIMEOUT_MS = exports.LOCAL_GATE_DEFAULT_PORT = void 0;
16
+ exports.createLocalGate = createLocalGate;
17
+ /** The extension's default port; `FCD_GATE_PORT` overrides it (the extension reads the same variable). */
18
+ exports.LOCAL_GATE_DEFAULT_PORT = 18791;
19
+ /** Enforce may wait for the first bundle (the extension's cold wait is 3 s): the shim waits a little longer than that. */
20
+ exports.LOCAL_DECIDE_TIMEOUT_MS = 4500;
21
+ /** The end notice is a loopback acknowledgement; it never holds the function's response for long. */
22
+ exports.LOCAL_END_TIMEOUT_MS = 300;
23
+ function loopbackPost(port) {
24
+ const http = require('http');
25
+ return (path, body, timeoutMs) => new Promise((resolve, reject) => {
26
+ let settled = false;
27
+ const finish = (fn) => { if (!settled) {
28
+ settled = true;
29
+ fn();
30
+ } };
31
+ const req = http.request({
32
+ host: '127.0.0.1', port, path, method: 'POST', agent: false,
33
+ headers: { 'content-type': 'application/json', 'content-length': Buffer.byteLength(body) },
34
+ }, (res) => {
35
+ let text = '';
36
+ res.setEncoding('utf8');
37
+ res.on('data', (chunk) => { text += chunk ?? ''; });
38
+ res.on('end', () => finish(() => resolve({ status: res.statusCode ?? 0, body: text })));
39
+ res.on('error', () => finish(() => reject(new Error('read failed'))));
40
+ });
41
+ req.on('error', (error) => finish(() => reject(error ?? new Error('request failed'))));
42
+ req.setTimeout(timeoutMs, () => { finish(() => reject(new Error('timeout'))); req.destroy(); });
43
+ req.end(body);
44
+ });
45
+ }
46
+ /** A refused connection means no listener: no extension in this environment. A timeout or a reset is a bad moment, not absence. */
47
+ function isRefused(error) {
48
+ const code = error?.code;
49
+ return code === 'ECONNREFUSED' || code === 'EADDRNOTAVAIL' || code === 'EACCES';
50
+ }
51
+ function portFrom(env) {
52
+ const raw = Number.parseInt((env.FCD_GATE_PORT || '').trim(), 10);
53
+ return Number.isInteger(raw) && raw > 0 && raw < 65536 ? raw : exports.LOCAL_GATE_DEFAULT_PORT;
54
+ }
55
+ /**
56
+ * The loopback client. `post` is injectable so the tests need no socket; the default talks to 127.0.0.1.
57
+ * The first connection failure marks the extension absent for the life of the environment (an older layer has no
58
+ * listener: asking again on every invocation would only add a failed connect to each call).
59
+ */
60
+ function createLocalGate(env, post) {
61
+ if (['0', 'false', 'off', 'no'].includes((env.FCD_LOCAL_GATE || '').trim().toLowerCase()))
62
+ return exports.NO_GATE;
63
+ const send = post ?? loopbackPost(portFrom(env));
64
+ let absent = false;
65
+ let reached = false;
66
+ const gate = {
67
+ get present() { return reached && !absent; },
68
+ async decide(call) {
69
+ if (absent)
70
+ return null;
71
+ let reply;
72
+ try {
73
+ reply = await send('/v1/tool-call', JSON.stringify(call), exports.LOCAL_DECIDE_TIMEOUT_MS);
74
+ }
75
+ catch (error) {
76
+ // A refused connection means no extension in this environment; a timeout or reset is a bad moment, not absence.
77
+ if (isRefused(error))
78
+ absent = true;
79
+ return null;
80
+ }
81
+ reached = true;
82
+ if (reply.status !== 200)
83
+ return null;
84
+ try {
85
+ const parsed = JSON.parse(reply.body);
86
+ if (parsed && (parsed.decision === 'allow' || parsed.decision === 'block' || parsed.decision === 'approval'))
87
+ return parsed;
88
+ }
89
+ catch { /* an answer we cannot read is not an answer */ }
90
+ return null;
91
+ },
92
+ async invocationEnd(requestId) {
93
+ // Every invocation ends with a notice, even one the extension never decided (a non-Bedrock event): the extension waits for
94
+ // it before it sends its records, so a missing one would hold the next invocation back. Never to an extension known absent.
95
+ if (absent || !requestId)
96
+ return;
97
+ try {
98
+ await send('/v1/invocation-end', JSON.stringify({ requestId }), exports.LOCAL_END_TIMEOUT_MS);
99
+ }
100
+ catch (error) {
101
+ // The first thing an invocation asked of the extension may be this notice (a non-Bedrock event): a refusal is absence too.
102
+ if (isRefused(error))
103
+ absent = true;
104
+ }
105
+ },
106
+ };
107
+ return gate;
108
+ }
109
+ /** A gate that is never there: every call uses the shim's own path. */
110
+ exports.NO_GATE = {
111
+ present: false,
112
+ decide: async () => null,
113
+ invocationEnd: async () => undefined,
114
+ };
@@ -0,0 +1,48 @@
1
+ import type { LocalActionPolicy } from './localDecision';
2
+ export declare const LOCAL_SAFETY_RULE_PREFIX = "local-safety:";
3
+ export type LocalSafetyStage = 'enforce' | 'warn' | 'off';
4
+ type ServedAction = 'block' | 'warn' | 'mask' | 'ask';
5
+ /** The served snapshot fields the guard and this glue read (the rest of the snapshot is passed through as is). */
6
+ export interface LocalSafetySnapshotView {
7
+ policyHash?: string;
8
+ categories?: Array<{
9
+ id: string;
10
+ items: Array<{
11
+ id: string;
12
+ label: string;
13
+ }>;
14
+ }>;
15
+ customBlocks?: Array<{
16
+ id: string;
17
+ pattern?: string;
18
+ action?: ServedAction;
19
+ categoryId?: string;
20
+ [key: string]: unknown;
21
+ }>;
22
+ disabledBuiltInItemIds?: string[];
23
+ itemActions?: Record<string, ServedAction>;
24
+ managerApprovalIds?: string[];
25
+ wouldActions?: Record<string, ServedAction>;
26
+ [key: string]: unknown;
27
+ }
28
+ /** `sdkGate.localSafety` from the bundle. */
29
+ export interface ServedLocalSafety {
30
+ stage: LocalSafetyStage;
31
+ snapshot: LocalSafetySnapshotView;
32
+ wouldManagerIds?: Set<string>;
33
+ }
34
+ export interface LocalSafetyOutcome {
35
+ check?: LocalActionPolicy;
36
+ wouldHave: NonNullable<LocalActionPolicy['monitorMatches']>;
37
+ ruleIds: string[];
38
+ }
39
+ export declare function parseServedLocalSafety(raw: unknown): ServedLocalSafety | undefined;
40
+ export declare function evaluateLocalSafety(call: {
41
+ toolName: string;
42
+ toolArgs: Record<string, unknown>;
43
+ mcpServer?: string;
44
+ }, input: ServedLocalSafety): LocalSafetyOutcome;
45
+ export declare function localSafetyFailure(stage: LocalSafetyStage, error: unknown): LocalSafetyOutcome;
46
+ /** The action-policy result with the built-in safety rules folded in (the gate's order; the strictest decides). */
47
+ export declare function withLocalSafety(actionPolicy: LocalActionPolicy, outcome: LocalSafetyOutcome): LocalActionPolicy;
48
+ export {};