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
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![npm version](https://img.shields.io/npm/v/fullcourtdefense.svg)](https://www.npmjs.com/package/fullcourtdefense)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
5
5
 
6
- **Actions-first runtime guard for AI agents.** Every tool call your agent makes is checked against your organisation's deterministic policy *before it runs*. Blocked calls never execute. Nothing is decided by an LLM.
6
+ **Tool-call control for AI agents.** Every tool call your agent makes (MCP, LangChain, the OpenAI Agents SDK, LlamaIndex, AutoGen, CrewAI, Semantic Kernel, Bedrock action groups, plain functions) is checked against your organisation's deterministic policy *before it runs*: allowed, blocked, held for a manager's approval, or recorded in Monitor mode. Blocked calls never execute. Nothing is decided by an LLM. No runtime dependencies.
7
7
 
8
8
  ---
9
9
 
@@ -19,8 +19,9 @@ npm install fullcourtdefense
19
19
  ```bash
20
20
  # .env — the SDK reads these; no code changes needed to rotate them
21
21
  FCD_SHIELD_ID=sh_your_shield_id
22
- FCD_SHIELD_KEY=shsk_your_shield_key # only for locked shields
23
- FCD_AGENT_ID=support-bot # stable name of this agent in your fleet
22
+ FCD_SHIELD_KEY=shsk_your_shield_key # for shields locked with a key
23
+ FCD_AGENT_ID=support-bot # this agent's name in the console (default: the service / script name)
24
+ FCD_FAIL_MODE=tiered # default (unset = tiered): a Blocking agent stops only its never-allowed rules if FullCourtDefense cannot be reached ('closed' stops everything, 'open' stops nothing)
24
25
  FCD_AGENT_INSTANCE_ID=$HOSTNAME # optional — pod / task / process id
25
26
  FCD_ENVIRONMENT=production # optional — falls back to NODE_ENV
26
27
  ```
@@ -30,8 +31,8 @@ import { FullCourtDefense } from 'fullcourtdefense';
30
31
 
31
32
  const fcd = new FullCourtDefense(); // config comes from the env vars above
32
33
 
33
- // Wrap any tool — a plain function or a LangChain / LlamaIndex / AutoGen /
34
- // CrewAI / Semantic Kernel tool (auto-detected). Same shape comes back.
34
+ // Wrap any tool — a plain function or an OpenAI Agents SDK / LangChain / LlamaIndex /
35
+ // AutoGen / CrewAI / Semantic Kernel tool (auto-detected). Same shape comes back.
35
36
  const issueRefund = fcd.protect(async ({ orderId, amount }) => stripe.refunds.create({ ... }), {
36
37
  operation: 'payment:refund',
37
38
  });
@@ -41,6 +42,22 @@ const safeSearch = fcd.protect(webSearchTool);
41
42
  await issueRefund({ orderId: 'o_1', amount: 25 });
42
43
  ```
43
44
 
45
+ ```typescript
46
+ // OpenAI Agents SDK: the protected tool is still a FunctionTool for new Agent({ tools }).
47
+ import { Agent, run, tool } from '@openai/agents';
48
+ import { z } from 'zod';
49
+
50
+ const lookupCustomer = tool({
51
+ name: 'lookup_customer', description: 'Look a customer up',
52
+ parameters: z.object({ customerId: z.string() }),
53
+ execute: async ({ customerId }) => crm.find(customerId),
54
+ });
55
+ const agent = new Agent({ name: 'support', tools: [fcd.protect(lookupCustomer)] });
56
+ await run(agent, 'Who is customer c-1?');
57
+ // Policy sees { customerId }, never the RunContext. A call that does not run returns its
58
+ // reason to the model as the tool output ({ blockedOutput: 'throw' } stops the run instead).
59
+ ```
60
+
44
61
  What happens on each call:
45
62
 
46
63
  ```
@@ -49,15 +66,20 @@ agent asks for tool -> protect() -> POST /runtime/check-tool-call -> allow
49
66
  -> approval: throw (or wait, see below)
50
67
  ```
51
68
 
69
+ - **Identity:** every call carries the agent's name. Without `FCD_AGENT_ID` it is the service the process runs as (`OTEL_SERVICE_NAME`, Cloud Run `K_SERVICE`, `AWS_LAMBDA_FUNCTION_NAME`, Azure Container Apps / App Service), then the npm package (`npm start`), then the main script — and the call says it was derived (`agentIdSource: 'default'`).
70
+ - **A wrong key, an unknown shield, a refused request (HTTP 401 / 403 / 404 / 400, and any other 4xx except 408 / 429) is not an outage:** on a Block shield the tool does not run and `FullCourtDefenseApiError` says what to fix. On a Monitor shield (the mode a live answer gave earlier, else `FCD_MODE_AT_PROTECT`) the tool runs and the call is still reported, so FullCourtDefense raises a "wrong or missing shield key" alert. With no known mode the shield is treated as Block. Only a real outage is answered by `FCD_FAIL_MODE` (below).
71
+ - **Arguments too deep or too large to check** (nested deeper than 32 levels, more than 20,000 values, or not encodable as JSON) are never sent: on Block the call is stopped ("too large to check safely"), in Monitor it runs and the record says what was not sent. Never an outage, and they cannot trip the circuit breaker.
72
+
52
73
  No text leaves your process by default. Text scanning (prompt injection in user input, poisoned tool output, RAG chunks) is a separate, opt-in capability — see [Text scanning (opt-in)](#text-scanning-opt-in).
53
74
 
54
75
  If you do not have a Shield ID yet, create one at https://fullcourtdefense.ai and copy it into `FCD_SHIELD_ID`.
55
76
 
56
77
  ### Zero code: one environment variable
57
78
 
58
- If your agent uses the MCP client (`@modelcontextprotocol/sdk`) or LangChain tools
59
- (`@langchain/core`), you do not have to touch the code at all. Preload the SDK and
60
- every tool call is gated exactly as if you had wrapped it with `protect()`:
79
+ If your agent uses the MCP client (`@modelcontextprotocol/sdk` or `@modelcontextprotocol/client`),
80
+ LangChain tools (`@langchain/core`) or the OpenAI Agents SDK (`@openai/agents`), you do not have
81
+ to touch the code at all. Preload the SDK and every tool call is gated exactly as if you had
82
+ wrapped it with `protect()`:
61
83
 
62
84
  ```bash
63
85
  npm install fullcourtdefense
@@ -74,21 +96,53 @@ What it does (the same technique OpenTelemetry uses for auto-instrumentation):
74
96
 
75
97
  | Library | Patched method | Blocked call |
76
98
  |---|---|---|
77
- | `@modelcontextprotocol/sdk` | `Client.prototype.callTool` | never reaches the server; returns an MCP error result (`isError: true`, JSON `{ blocked, reason, toolName }`) |
99
+ | `@modelcontextprotocol/sdk` (v1), `@modelcontextprotocol/client` (v2) | `Client.prototype.callTool` | never reaches the server; returns an MCP error result (`isError: true`, JSON `{ blocked, reason, toolName }`) |
78
100
  | `@langchain/core` | `StructuredTool.prototype.invoke` (all tools: `tool()`, `DynamicStructuredTool`, custom classes) | throws `FullCourtDefense blocked tool call "..."`, the tool never runs |
101
+ | `@openai/agents` (`@openai/agents-core`) | `Agent.prototype.getAllTools`: the Runner gets gated copies of the Agent's function tools, `agent.asTool()` tools, MCP-server tools and local `shellTool` / `applyPatchTool` | the tool never runs; the model gets the reason as the tool output (shell / patch: as the command's error). An MCP-server tool is checked once, not again in the MCP client |
79
102
 
80
103
  - Works for CommonJS apps and for native ESM apps on Node ≥ 22.12 (`require(esm)`); on older Node, ESM apps use `fcd.protect()`.
81
104
  - Libraries loaded later (lazy `require`, dynamic `import`) are patched the moment they load.
82
105
  - Shield mode is still the source of truth: a **monitor** shield records every call and blocks nothing.
83
- - Backend unreachable: fail-open by default, fail-**closed** for high-risk operations (`refund`, `delete`, `deploy`, ... — see `failClosedOperations`).
106
+ - Backend unreachable: Enforce is **tiered** by default (only your never-allowed rules stop a call, with a `ToolCallBlocked` whose `code` is `FCD_FAIL_CLOSED`; everything else runs and is reported once the API is back); `FCD_FAIL_MODE=closed` stops every call, `FCD_FAIL_MODE=open` stops none. Monitor never blocks.
84
107
  - No `FCD_SHIELD_ID` → one warning, app runs unprotected. `FCD_AUTO=off` → silent opt-out. `FCD_AUTO_DEBUG=1` → what got patched, to stderr.
85
108
  - Installed twice (env var + `require('fullcourtdefense/auto')` in code) → gates once.
86
109
  - Programmatic: `import { installAuto, currentAutoState } from 'fullcourtdefense'`.
87
110
 
88
111
  No text is scanned by the preload; text scanning stays opt-in.
89
112
 
113
+ ### Bedrock Agents: the action-group Lambda
114
+
115
+ A Bedrock Agent runs each tool by invoking its action group's Lambda. That function
116
+ is a plain handler, so the preload has nothing to patch; the Lambda entry gates the
117
+ call instead. With the FullCourtDefense layer attached (the AWS connector does all of
118
+ this when you Protect a Bedrock agent; Remove restores the original):
119
+
120
+ ```text
121
+ Handler /opt/nodejs/node_modules/fullcourtdefense/lambda.handler
122
+ FCD_LAMBDA_HANDLER index.handler # your function's own handler
123
+ FCD_SHIELD_ID / FCD_SHIELD_KEY / FCD_AGENT_ID / FCD_API_URL
124
+ FCD_FAIL_MODE tiered # our API unreachable in Block mode: see below
125
+ FCD_MODE_AT_PROTECT monitor # the shield's mode, rewritten when it changes
126
+ ```
127
+
128
+ - Every Bedrock call (function-details or OpenAPI action group) is checked BEFORE your handler runs. Policy sees the function name (or `METHOD /path`) and the typed parameters.
129
+ - Blocked: your handler never runs; Bedrock gets `REPROMPT` with the reason (OpenAPI groups: HTTP 403), so the agent can explain it.
130
+ - Monitor shield: runs at once and records the call; the record finishes (at most 1.5 s after your handler) before Lambda freezes.
131
+ - FullCourtDefense unreachable on a Block shield (`FCD_FAIL_MODE=tiered`): only your never-allowed rules are stopped, everything else runs (high-risk names such as `refund`, `delete`, `transfer` no longer stop a call: when our part fails we never block you); each call decided without a check is reported once the API answers again and raises a security alert. A cold start while the API is down uses `FCD_MODE_AT_PROTECT` (FullCourtDefense rewrites it whenever the shield's mode changes, and an hourly check corrects any drift), so a Monitor agent never blocks; its calls are still reported once the API answers, and you get an alert if the shield was in Block by then. With no recorded mode the tiered rule applies. Republish the layer with this SDK before relying on it: an older layer ignores both settings.
132
+ - Any other event passes straight through. CommonJS, ES module (`.mjs` / `"type": "module"`), nested exports and callback handlers load the same way the Node.js runtime loads them.
133
+
90
134
  ---
91
135
 
136
+ ## Upgrading to 2.1
137
+
138
+ | 2.0 | 2.1 |
139
+ |---|---|
140
+ | The package also installed the 1.x CLI (`fullcourtdefense` / `botguard` commands) and depended on `agentguard: file:../..` | **SDK only, no runtime dependencies.** The CLI is its own package: `npm install -g fullcourtdefense-cli`. **Breaking for CLI users:** the `fullcourtdefense` / `botguard` commands of this package no longer run the CLI; they print where it moved and exit with code 1 (nothing runs). Scripts that call `npx fullcourtdefense <command>` must change to `npx -p fullcourtdefense-cli fullcourtdefense <command>`. |
141
+ | A wrong key (401), an unknown shield (404) or a refused request (400) was treated as an outage: the call ran unchecked (or failed closed) with nothing to say why | **`FullCourtDefenseApiError`** (`status`, `code`: `FCD_UNAUTHORIZED` / `FCD_FORBIDDEN` / `FCD_SHIELD_NOT_FOUND` / `FCD_BAD_REQUEST`). The tool does not run, nothing is degraded, spooled or alerted as "ran without a check"; the message says what to change. `checkToolCall` returns `{ success: false, status, code }`. |
142
+ | No `FCD_AGENT_ID` -> every agent was `unknown-agent` | A default from the service / script name, sent with `agentIdSource: 'default'` (`'config'` / `'env'` when declared). A name passed in code (`agentName` / `agentId` on the call, or `protect(tool, { agentName })`) is declared: `'config'`. `FCD_AGENT_NAME` and `FCD_WORKLOAD_NAME` are read too. |
143
+ | OpenAI Agents SDK tools: policy saw `{ args: [RunContext, json] }` | `protect(tool)` / `protectOpenAIAgentsTool` show the parsed arguments; the preload covers `@openai/agents`. |
144
+ | LangChain via `protect()`: a ToolCall envelope or the RunnableConfig could reach policy | Policy sees the ToolCall's `args`; the config is never sent. |
145
+
92
146
  ## Upgrading from 1.x
93
147
 
94
148
  2.0 is **actions-first**. Three things changed:
@@ -105,9 +159,9 @@ To keep 1.x behaviour exactly: `new FullCourtDefense({ features: { textScan: tru
105
159
 
106
160
  ---
107
161
 
108
- ## What is Full Court Defense?
162
+ ## Text scanning (chatbots, MCP output, RAG)
109
163
 
110
- Full Court Defense is a **real-time AI firewall** that protects chatbots, AI agents, MCP servers, and RAG pipelines from prompt injection and other LLM attacks.
164
+ Besides tool-call control, Full Court Defense scans **text** for chatbots, MCP servers and RAG pipelines: prompt injection and other LLM attacks in user input, AI output, tool responses and retrieved documents. For agents this is opt-in (`features: { textScan: true }` / `FCD_TEXT_SCAN=true`); the use cases below that call `scan*()` need it.
111
165
 
112
166
  It sits between your users and your bot — every message is scanned **before** it reaches your system. Attacks are blocked. Safe messages pass through.
113
167
 
@@ -176,31 +230,21 @@ yarn add fullcourtdefense
176
230
 
177
231
  ---
178
232
 
179
- ## CLI Scanner
233
+ ## The CLI is a separate package
180
234
 
181
- The same npm package also installs the Full Court Defense CLI:
235
+ Since 2.1 this package is the SDK only. The Full Court Defense CLI (machine protection for
236
+ AI coding tools, scans, `doctor`) is `fullcourtdefense-cli`:
182
237
 
183
238
  ```bash
184
- npm install -g fullcourtdefense
239
+ npm install -g fullcourtdefense-cli
185
240
  fullcourtdefense doctor
186
- fullcourtdefense configure
187
- fullcourtdefense scan --local
188
- ```
189
-
190
- The CLI can scan hosted agents, private HTTP APIs, MCP servers, local RAG corpora, and live RAG services:
191
-
192
- ```bash
193
- # Live RAG service
194
- fullcourtdefense scan --local --type rag --rag-url "http://127.0.0.1:5065/chat" --method POST --request-format custom --input-field message --output-field answer --mode full --format report
195
-
196
- # HTTP MCP server
197
- fullcourtdefense scan --local --type mcp --mcp-url "http://127.0.0.1:5066/mcp" --mcp-tool all --mode full --format report
198
-
199
- # Internal API endpoint
200
- fullcourtdefense scan --local --type endpoint --endpoint "http://127.0.0.1:3000/chat" --method POST --request-format custom --input-field message --output-field response --mode quick --format report
241
+ # or, without installing:
242
+ npx -p fullcourtdefense-cli fullcourtdefense doctor
201
243
  ```
202
244
 
203
- Local scans run from your machine or VPN, then send captured content outbound to your Shield for verdicts and saved web reports.
245
+ 2.0 of this package also ran the CLI as `fullcourtdefense` / `botguard`. In 2.1 those two commands
246
+ only print where the CLI moved and exit with code 1; they run nothing. If you installed this package
247
+ globally for the CLI, replace it: `npm uninstall -g fullcourtdefense && npm install -g fullcourtdefense-cli`.
204
248
 
205
249
  ---
206
250
 
@@ -374,6 +418,7 @@ const fcd = new FullCourtDefense({ agentId: 'support-agent' }); // shieldId/shie
374
418
  const safeRefund = fcd.protect(issueRefund, { operation: 'payment:refund' });
375
419
 
376
420
  // Framework tools — framework auto-detected, toolName from tool.name / metadata.name
421
+ const safeAgentsTool = fcd.protect(lookupCustomerTool); // OpenAI Agents SDK: invoke(runContext, json)
377
422
  const safeLangChainTool = fcd.protect(webSearchTool); // LangChain: invoke()/call()
378
423
  const safeLlamaIndexTool = fcd.protect(documentLookupTool); // LlamaIndex: call()
379
424
  const safeAutoGenTool = fcd.protect(autoGenTool); // AutoGen: execute()/run()
@@ -389,42 +434,81 @@ Options:
389
434
  |---|---|
390
435
  | `toolName`, `operation`, `resourceType` | What policy matches on. `toolName` is inferred when omitted. |
391
436
  | `sessionId` | Conversation / run / request id recorded on every action. |
392
- | `toolArgs` | Static record or `(args) => record` mapper. Default: first argument if it is a plain object. |
437
+ | `toolArgs` | Static record or `(args) => record` mapper. Default: the first argument if it is a plain object (LangChain: a ToolCall's `args`; OpenAI Agents: the parsed JSON input). |
438
+ | `blockedOutput` | OpenAI Agents tools: `'message'` (default) returns the reason to the model; `'throw'` stops the run. |
393
439
  | `approvalMode` | `'block'` (default) throws when a human approval is required; `'wait'` polls until approved / rejected (`approvalTimeoutMs`, default 15 min). |
394
440
  | `failClosed` | Override the risk-tiered fail direction when the backend is unreachable. |
395
441
  | `onBlocked` | `(reason) => Error` — throw your own error type. |
396
442
  | `framework` | Force the recorded framework instead of auto-detecting. |
397
443
  | `maxResponseChars`, `resultToText`, `metadata` | Only used by the opt-in output text scan. |
398
444
 
399
- The named adapters `protectLangChainTool`, `protectLlamaIndexTool`, `protectAutoGenTool`, `protectCrewAITool`, `protectSemanticKernelFunction` still exist and are thin aliases over `protect()` with the framework fixed. Everything is dependency-free — your frameworks stay peer code.
445
+ The named adapters `protectOpenAIAgentsTool`, `protectLangChainTool`, `protectLlamaIndexTool`, `protectAutoGenTool`, `protectCrewAITool`, `protectSemanticKernelFunction` are thin aliases over `protect()` with the framework fixed. Everything is dependency-free — your frameworks stay peer code.
400
446
 
401
447
  ---
402
448
 
403
- ## Use Case 8 — Protect an OpenAI Agent
449
+ ## Use Case 8 — Protect an OpenAI Agents SDK agent
404
450
 
405
451
  ```typescript
452
+ import { Agent, run, tool, shellTool } from '@openai/agents';
453
+ import { z } from 'zod';
406
454
  import { FullCourtDefense } from 'fullcourtdefense';
407
455
 
408
- const fcd = new FullCourtDefense({
409
- shieldId: 'sh_your_shield_id',
410
- apiKey: 'sk-your-openai-key',
456
+ const fcd = new FullCourtDefense(); // FCD_SHIELD_ID / FCD_SHIELD_KEY / FCD_AGENT_ID
457
+
458
+ const issueRefund = tool({
459
+ name: 'issue_refund',
460
+ description: 'Refund an order',
461
+ parameters: z.object({ orderId: z.string(), amount: z.number() }),
462
+ execute: async ({ orderId, amount }) => payments.refund(orderId, amount),
411
463
  });
412
464
 
413
- const result = await fcd.chat.completions.create({
414
- model: 'gpt-4o',
415
- messages: [{ role: 'user', content: userMessage }],
465
+ const agent = new Agent({
466
+ name: 'support',
467
+ instructions: 'Help customers with their orders.',
468
+ tools: [
469
+ fcd.protect(issueRefund, { operation: 'payment:refund', approvalMode: 'wait' }),
470
+ fcd.protect(shellTool({ shell: myLocalShell })), // each command list is checked before shell.run
471
+ ],
416
472
  });
473
+ const result = await run(agent, userMessage);
474
+ ```
417
475
 
418
- if (result.blocked) {
419
- console.log('Attack blocked:', result.shield.reason);
420
- } else {
421
- console.log(result.content);
422
- }
476
+ - The Runner calls the protected tool exactly as before (`invoke(runContext, inputJson)`); the check happens first. Policy sees `{ orderId, amount }`, never the RunContext.
477
+ - Blocked: the tool never runs and the model gets `FullCourtDefense blocked tool call "issue_refund": <reason>` as the tool output. `{ blockedOutput: 'throw' }` stops the run instead.
478
+ - Local `shellTool` / `applyPatchTool`: the commands (or the file path and kind of edit, never the diff) are checked before your shell / editor runs them.
479
+ - Zero code: `NODE_OPTIONS="--require fullcourtdefense/auto"` does the same for every Agent (see above).
480
+ - The chat gateway (`fcd.chat.completions.create`, Use Case 12) is a different product: it scans chat text, not tool calls.
481
+
482
+ ---
483
+
484
+ ## LangChain.js / LangGraph and the Anthropic SDK (tool use)
485
+
486
+ ```typescript
487
+ // LangChain.js / LangGraph: the protected tool is still a LangChain tool (ToolNode, createAgent, ...).
488
+ import { tool } from '@langchain/core/tools';
489
+ import { z } from 'zod';
490
+
491
+ const sqlQuery = tool(async ({ sql }) => db.run(sql), { name: 'sql_query', description: 'Run a read-only query', schema: z.object({ sql: z.string() }) });
492
+ const agentTools = [fcd.protect(sqlQuery)]; // blocked: the tool throws, a ToolNode answers with an error ToolMessage
493
+ ```
494
+
495
+ ```typescript
496
+ // Anthropic SDK, your own loop: the model answers with tool_use blocks, you answer with tool_result blocks.
497
+ const response = await anthropic.messages.create({ model, max_tokens: 1024, tools, messages });
498
+ const results = await fcd.anthropicToolResults(response.content, { read_customer, send_email });
499
+ messages.push({ role: 'assistant', content: response.content }, { role: 'user', content: results });
500
+ // A stopped call never runs; its tool_result is { is_error: true, content: 'FullCourtDefense blocked tool call ...' }
501
+ // so the model can tell the user. In Monitor every tool runs and is recorded.
502
+
503
+ // Anthropic tool runner (betaZodTool): protect each tool, the runner sends the reason back as an error result.
504
+ const runnerTools = [fcd.protect(betaZodTool({ name: 'read_customer', description: '...', inputSchema, run }))];
423
505
  ```
424
506
 
507
+ Same guard path as every other integration: Needs-manager / Ask / Never-allowed stop the tool, Warn and Allow run it, Monitor never blocks or waits, every call carries the agent identity (`FCD_AGENT_ID`).
508
+
425
509
  ---
426
510
 
427
- ## Use Case 9 — Protect a Claude Agent
511
+ ## Use Case 9 — Protect a Claude Agent (text gateway; for tool use see above)
428
512
 
429
513
  ```typescript
430
514
  import { FullCourtDefense } from 'fullcourtdefense';
@@ -613,10 +697,13 @@ const fcd = new FullCourtDefense({
613
697
  timeout: 120000, // Optional — ms for gateway chat / approval polling (default: 120000)
614
698
  monitorMode: 'auto', // Optional — 'auto' (default) | 'off'. See below.
615
699
  failOpen: true, // Optional — default true. Backend down = allow, never throw.
700
+ failMode: 'tiered', // FCD_FAIL_MODE — 'tiered' (default) | 'closed' | 'open'. See below.
701
+ modeAtProtect: 'monitor', // FCD_MODE_AT_PROTECT — mode to use until a mode lookup succeeds
616
702
  scanTimeoutMs: 5000, // Optional — bounded timeout for sync verdict calls (default: 5000)
617
703
 
618
704
  // Identity (2.x) — recorded on every action; all have env-var equivalents
619
- agentId: 'support-bot', // FCD_AGENT_ID — stable logical agent; default agentName
705
+ agentId: 'support-bot', // FCD_AGENT_ID (or FCD_AGENT_NAME / FCD_WORKLOAD_NAME) — default agentName;
706
+ // unset: the service / npm package / script name (agentIdSource 'default')
620
707
  agentInstanceId: 'pod-7', // FCD_AGENT_INSTANCE_ID — default: random UUID per process
621
708
  environment: 'production', // FCD_ENVIRONMENT, then NODE_ENV
622
709
 
@@ -661,12 +748,84 @@ the console:
661
748
  The mode is cached for 60s, so flipping monitor → block in the console takes
662
749
  effect within a minute without redeploying your agent.
663
750
 
664
- ### Fail-open guarantee
665
-
666
- With `failOpen: true` (the default), FullCourtDefense being unreachable, slow, or
667
- erroring can NEVER block or break your agent: scan/check calls return an allowed
668
- result with `degraded: true` instead of throwing. No connection = no blocking.
669
- Set `failOpen: false` to restore strict throwing.
751
+ ### Local decisions (default): no request per tool call
752
+
753
+ With `decisionMode: 'local'` (the default; env `FCD_DECISION_MODE`) a Block-mode tool call is decided **in your process**
754
+ from the shield's policies, with the same policy engine and the same answer the API gives. The SDK fetches the policies
755
+ when the client is built and refreshes them every 60 s in the background; a tool call never waits for that.
756
+
757
+ - The call's record (what was decided, which rule, how the tool ended, the provider's tool-call id) is sent afterwards,
758
+ in background batches. If FullCourtDefense is down the records wait in memory (bounded) and are sent once it is back;
759
+ at exit they are flushed briefly or kept in the local spool for the next run.
760
+ - The built-in safety rules (command, file and web tools) are decided locally too, with the rules FullCourtDefense
761
+ serves in the same bundle. Only a call that needs a **manager's approval** goes to FullCourtDefense while it runs, plus
762
+ the rare call the bundle cannot decide: a policy that reads the agent's recorded history, a suspended shield.
763
+ - Cold start: a Block-mode call made in the first 1.5 s after the client was built waits for the first policies
764
+ (`coldStartWaitMs`, env `FCD_COLD_START_WAIT_MS`; `0` = never wait), so a short-lived agent's first call is checked.
765
+ After that, or if FullCourtDefense cannot be reached, a call with no policies runs, is recorded, and one warning says
766
+ so: the agent is never stalled. `await fcd.ready()` waits for the policies once at start-up instead.
767
+ - `decisionMode: 'server'` (or `FCD_DECISION_MODE=server`) restores a check request per call. FullCourtDefense can also
768
+ switch local decisions off for every agent from the server.
769
+ - Pass the model's tool-call id as `toolCallId` (`protect()` and `anthropicToolResults()` do it for Vercel AI, LangChain
770
+ and Anthropic): when a local AI gateway also sees the same call, one action stays one record.
771
+
772
+ ### Tiered by default in Enforce, never blocking in Monitor
773
+
774
+ A tool call is answered quickly in every case: allow, or a typed refusal. Nothing waits for a manager inside the call
775
+ (`approvalMode: 'block'` is the default: a call that needs approval is refused at once with the approval id; the next
776
+ identical call after the approval runs once). Every network wait is bounded (the check: 1.5 s, `toolCheckTimeoutMs`, then the fail mode answers; records and approval requests: 3 s).
777
+
778
+ Monitor mode never blocks and never waits: the shield mode is cached for 60 s and refreshed in the background, so after the
779
+ first lookup of a process no tool call waits for FullCourtDefense. The first lookup starts when the client is built, and when the mode recorded on the agent
780
+ (`FCD_MODE_AT_PROTECT`, which Protect writes) says Monitor the first call does not wait for it either: it runs at once and its record follows the answer. A mode nobody could read (the API was down since the
781
+ process started, no `FCD_MODE_AT_PROTECT`) is treated as Monitor: the call runs and is reported as unconfirmed once the API
782
+ answers. Only a refused key or shield (HTTP 401 / 403 / 404) keeps Block, with the error saying what to fix.
783
+ Set `FCD_MODE_AT_PROTECT` to avoid the one-time mode lookup on the first call (the cloud Protect and the init wizard already set it); without it the first call of a process waits for that lookup (at most 1.5 s), so an Enforce shield's first call is checked.
784
+ When FullCourtDefense hangs or cannot be reached, at most one call waits up to 1.5 s; after that, calls answer instantly (from the fail mode) until we're back. A hang or a network error opens the circuit breaker at once; while it is open one background probe runs every 10 s (calls never wait on it) and a successful probe restores live checks. HTTP answers (4xx / 5xx with a body) are handled as before.
785
+ The text scans (`scan`, `scanChunks`, ...) keep `failOpen: true`: they never throw on an outage.
786
+
787
+ ### When FullCourtDefense is unreachable in Block mode (`failMode` / `FCD_FAIL_MODE`)
788
+
789
+ | Setting | Never-allowed rules | A rule that needs a manager | Everything else (high-risk names included) | Alert |
790
+ |---|---|---|---|---|
791
+ | `tiered` (default; what Protect sets on hosted agents) | stopped | runs (an unattended agent cannot ask), reported with `wouldHaveNeeded: 'manager'` | runs | yes, once the API answers again |
792
+ | `closed` (explicit opt-in) | stopped | stopped | stopped | yes, once the API answers again |
793
+ | `open` (explicit opt-out) | runs | runs | runs | yes, once the API answers again |
794
+
795
+ Every call that ran during the outage is reported with `ranDuringOutage: true` (with `failsafe: 'allow'`, `failsafeOutcome`,
796
+ `failsafeRuleId` / `failsafeRuleName` when a rule applied). When the API is up and answers "pending" (a manager has to
797
+ decide), the call does not run and returns at once: a manager who does not answer is not our failure.
798
+
799
+ Records survive a short-lived process: sends are tracked, the end of the process waits at most 1.5 s for them, and what is
800
+ still unsent (or failed) is kept in a small file in the user cache directory (`~/.cache/fullcourtdefense/sdk-spool`, or
801
+ `%LOCALAPPDATA%` / `~/Library/Caches`) that the next start with the same shield sends. `FCD_SDK_SPOOL=off` disables it,
802
+ `FCD_SDK_SPOOL_DIR` moves it.
803
+
804
+ The error your code receives is `ToolCallBlocked` (`error.code`: `FCD_BLOCKED`, `FCD_APPROVAL_REQUIRED`, `FCD_FAIL_CLOSED`,
805
+ `FCD_ARGS_TOO_LARGE`; also `outcome`, `reason`, `rule`, `approvalActionId`, `degraded`); a refused key is a
806
+ `FullCourtDefenseApiError`, which is a `ToolCallBlocked` too.
807
+
808
+ Machine-scoped rules: an SDK call has no machine (the backend treats it as an agent, `agent:<name>`), so rules scoped to a
809
+ computer do not apply to it. Scope SDK rules to "everyone" or by agent name. Sending the local machine identity of a computer
810
+ enrolled with the Full Court Defense CLI is not done yet: the backend classifies a call that names a machine as a machine call.
811
+
812
+ The never-allowed rules are the shield's Action Policies that block a named tool
813
+ outright (any operation, only tool / agent name conditions). They arrive with the
814
+ shield's mode (every 60 s) and are kept through an outage; before the first
815
+ successful lookup, and with `monitorMode: 'off'`, no rule is known, so every call runs.
816
+ Monitor mode never blocks, whatever this says: until a mode lookup of the process
817
+ succeeds, `modeAtProtect` / `FCD_MODE_AT_PROTECT` decides the mode (else Block, and
818
+ the table above applies). That mode is unconfirmed, so it is never silent: each
819
+ Monitor call made on it is reported once the API answers (`failsafeOutcome:
820
+ 'unconfirmed_monitor'`), and FullCourtDefense raises an alert if the shield was in
821
+ Block by then. On hosted agents FullCourtDefense rewrites `FCD_MODE_AT_PROTECT`
822
+ whenever the shield's mode changes.
823
+
824
+ Every runtime call sends `x-fcd-fail-mode` when `failMode` is set, so the console
825
+ says what a Blocking agent does during an outage only when the agent's code
826
+ reports it. In `approvalMode: 'wait'`, each wait polls with its own id: when two
827
+ identical calls share one approval request, only the one that receives the
828
+ approval runs; the other is told the approval expired.
670
829
 
671
830
  ### Method reference
672
831
 
@@ -703,8 +862,29 @@ new FullCourtDefense({ shieldId: 'bad' });
703
862
  // Shield not found
704
863
  await fcd.scan('test');
705
864
  // → Error: FullCourtDefense: Shield not found (sh_...).
865
+
866
+ // Tool calls: a wrong key / refused or unknown shield / refused request is not an outage
867
+ import { FullCourtDefenseApiError } from 'fullcourtdefense';
868
+ try {
869
+ await safeRefund({ orderId: 'o_1', amount: 25 });
870
+ } catch (error) {
871
+ if (error instanceof FullCourtDefenseApiError) {
872
+ error.status; // 401 / 403 / 404 / 400 — the tool did not run
873
+ error.code; // 'FCD_UNAUTHORIZED' | 'FCD_FORBIDDEN' | 'FCD_SHIELD_NOT_FOUND' | 'FCD_BAD_REQUEST'
874
+ error.message; // what to change, e.g. "Set FCD_SHIELD_KEY (or shieldKey) to the key on the shield's Access tab"
875
+ }
876
+ }
706
877
  ```
707
878
 
879
+ | Answer from FullCourtDefense | Tool | Reported later as "ran without a check" | Thrown |
880
+ |---|---|---|---|
881
+ | allow | runs, recorded | - | - |
882
+ | block / approval (default) | does not run | - | `FullCourtDefense blocked tool call ...` |
883
+ | 401 / 403 / 404 / 400 / other 4xx (Block, or no known mode) | does not run | no | `FullCourtDefenseApiError` (also printed once on stderr) |
884
+ | 401 / 403 / 404 on a Monitor shield (owner decision O4) | runs; the call is reported and FullCourtDefense raises a key alert | no | - (`onDegrade` gets `outcome: 'monitor_config_error'`) |
885
+ | arguments nested deeper than 32 levels / more than 20,000 values / not JSON | Block: does not run; Monitor: runs | no | `FullCourtDefense blocked tool call ...: Stopped: the tool call's arguments are ...` |
886
+ | no answer, 5xx, 408, 429 (an outage, Block mode) | `failMode` / `FCD_FAIL_MODE` decides (table above; default `tiered`) | yes, with `tiered` / `closed` | for a stopped call |
887
+
708
888
  ---
709
889
 
710
890
  ## Enterprise Evaluation & Pricing
@@ -16,6 +16,8 @@ export interface FrameworkToolGuardOptions {
16
16
  maxResponseChars?: number;
17
17
  resultToText?: (result: unknown) => string;
18
18
  onBlocked?: (reason: string) => Error;
19
+ /** OpenAI Agents tools only: `'message'` (default) returns the reason to the model; `'throw'` stops the run. */
20
+ blockedOutput?: 'message' | 'throw';
19
21
  }
20
22
  /** Wrap a LangChain.js Tool / StructuredTool / Runnable-like tool. */
21
23
  export declare function protectLangChainTool<T extends UnknownRecord>(tool: T, options: FrameworkToolGuardOptions): T;
@@ -25,6 +27,15 @@ export declare function protectLlamaIndexTool<T extends UnknownRecord>(tool: T,
25
27
  export declare function protectAutoGenTool<T extends UnknownRecord>(tool: T, options: FrameworkToolGuardOptions): T;
26
28
  /** Wrap a CrewAI-style tool (invoke / run / call). */
27
29
  export declare function protectCrewAITool<T extends UnknownRecord>(tool: T, options: FrameworkToolGuardOptions): T;
30
+ /**
31
+ * Wrap an OpenAI Agents SDK function tool (`tool({ name, parameters, execute })` from
32
+ * `@openai/agents`). Returns a FunctionTool for `new Agent({ tools: [...] })`: the Runner's
33
+ * `invoke(runContext, inputJson)` is checked first, policy sees the parsed arguments (never
34
+ * the RunContext), and a call that does not run returns its reason to the model. A local
35
+ * `shellTool({ shell })` or `applyPatchTool({ editor })` is accepted too: its commands / file
36
+ * edits are checked before they run.
37
+ */
38
+ export declare function protectOpenAIAgentsTool<T extends UnknownRecord>(tool: T, options: FrameworkToolGuardOptions): T;
28
39
  /** Wrap a Semantic Kernel function / plugin method (invoke / run / call). */
29
40
  export declare function protectSemanticKernelFunction<T extends UnknownRecord>(kernelFunction: T, options: FrameworkToolGuardOptions): T;
30
41
  export {};
package/dist/adapters.js CHANGED
@@ -10,7 +10,9 @@ exports.protectLangChainTool = protectLangChainTool;
10
10
  exports.protectLlamaIndexTool = protectLlamaIndexTool;
11
11
  exports.protectAutoGenTool = protectAutoGenTool;
12
12
  exports.protectCrewAITool = protectCrewAITool;
13
+ exports.protectOpenAIAgentsTool = protectOpenAIAgentsTool;
13
14
  exports.protectSemanticKernelFunction = protectSemanticKernelFunction;
15
+ const protect_1 = require("./protect");
14
16
  function toProtectOptions(options, framework) {
15
17
  const { fcd: _fcd, ...rest } = options;
16
18
  return { ...rest, framework };
@@ -40,6 +42,20 @@ function protectCrewAITool(tool, options) {
40
42
  requireEntry(tool, ['invoke', 'run', 'call'], 'CrewAI');
41
43
  return options.fcd.protect(tool, toProtectOptions(options, 'crewai'));
42
44
  }
45
+ /**
46
+ * Wrap an OpenAI Agents SDK function tool (`tool({ name, parameters, execute })` from
47
+ * `@openai/agents`). Returns a FunctionTool for `new Agent({ tools: [...] })`: the Runner's
48
+ * `invoke(runContext, inputJson)` is checked first, policy sees the parsed arguments (never
49
+ * the RunContext), and a call that does not run returns its reason to the model. A local
50
+ * `shellTool({ shell })` or `applyPatchTool({ editor })` is accepted too: its commands / file
51
+ * edits are checked before they run.
52
+ */
53
+ function protectOpenAIAgentsTool(tool, options) {
54
+ if (!(0, protect_1.isOpenAIAgentsFunctionTool)(tool) && !(0, protect_1.openAIAgentsLocalToolKind)(tool)) {
55
+ throw new Error('FullCourtDefense: expected an OpenAI Agents function tool (type "function", a name, parameters and invoke()) or a local shellTool / applyPatchTool.');
56
+ }
57
+ return options.fcd.protect(tool, toProtectOptions(options, 'openai-agents'));
58
+ }
43
59
  /** Wrap a Semantic Kernel function / plugin method (invoke / run / call). */
44
60
  function protectSemanticKernelFunction(kernelFunction, options) {
45
61
  requireEntry(kernelFunction, ['invoke', 'run', 'call'], 'Semantic Kernel');
@@ -0,0 +1,32 @@
1
+ import type { FullCourtDefense } from './client';
2
+ export interface AnthropicToolUseBlock {
3
+ type: 'tool_use';
4
+ id: string;
5
+ name: string;
6
+ input?: unknown;
7
+ }
8
+ export interface AnthropicToolResultBlock {
9
+ type: 'tool_result';
10
+ tool_use_id: string;
11
+ content: string;
12
+ /** True when the tool did not run (stopped by policy, unknown tool) or raised. */
13
+ is_error?: boolean;
14
+ }
15
+ export type AnthropicToolHandler = (input: any) => unknown | Promise<unknown>;
16
+ export interface AnthropicToolOptions {
17
+ /** Overrides the client-level `agentId` as the agent name on every call. */
18
+ agentName?: string;
19
+ sessionId?: string;
20
+ operation?: string;
21
+ resourceType?: string;
22
+ /** `'block'` (default) answers a call that needs approval with an error block; `'wait'` holds it until a person decides. */
23
+ approvalMode?: 'block' | 'wait';
24
+ approvalTimeoutMs?: number;
25
+ /** Run the tools of one assistant turn one after the other instead of together (default: together). */
26
+ sequential?: boolean;
27
+ }
28
+ /**
29
+ * Run the `tool_use` blocks of one assistant message through the gate and return the `tool_result` blocks to send back
30
+ * (same order as the blocks). `content` is `message.content` or the whole message.
31
+ */
32
+ export declare function anthropicToolResults(fcd: FullCourtDefense, content: unknown, handlers: Record<string, AnthropicToolHandler>, options?: AnthropicToolOptions): Promise<AnthropicToolResultBlock[]>;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ // Anthropic SDK tool use (`@anthropic-ai/sdk`): the model answers with `tool_use` content blocks, the application runs the
3
+ // tools and sends `tool_result` blocks back. `anthropicToolResults` is that middle step with the action gate in front of
4
+ // every tool: a stopped call never runs and its `tool_result` is an error block carrying the reason, so the model can tell
5
+ // the user. Nothing here talks to Anthropic and no key is needed: it only reads the blocks the model produced.
6
+ //
7
+ // Tool-runner tools (`betaZodTool`, `betaTool`: `{ name, input_schema, run }`) go through `fcd.protect(tool)` instead.
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.anthropicToolResults = anthropicToolResults;
10
+ function isPlainObject(value) {
11
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
12
+ }
13
+ function isToolUse(block) {
14
+ return isPlainObject(block) && block.type === 'tool_use' && typeof block.name === 'string' && typeof block.id === 'string';
15
+ }
16
+ function asText(value) {
17
+ if (typeof value === 'string')
18
+ return value;
19
+ try {
20
+ return JSON.stringify(value) ?? String(value);
21
+ }
22
+ catch {
23
+ return String(value);
24
+ }
25
+ }
26
+ /**
27
+ * Run the `tool_use` blocks of one assistant message through the gate and return the `tool_result` blocks to send back
28
+ * (same order as the blocks). `content` is `message.content` or the whole message.
29
+ */
30
+ async function anthropicToolResults(fcd, content, handlers, options = {}) {
31
+ const blocks = Array.isArray(content) ? content : (isPlainObject(content) && Array.isArray(content.content) ? content.content : []);
32
+ const uses = blocks.filter(isToolUse);
33
+ const runOne = async (block) => {
34
+ const handler = handlers[block.name];
35
+ if (typeof handler !== 'function') {
36
+ return { type: 'tool_result', tool_use_id: block.id, is_error: true, content: `Unknown tool "${block.name}".` };
37
+ }
38
+ const input = isPlainObject(block.input) ? block.input : {};
39
+ let ran = false;
40
+ try {
41
+ const result = await fcd.guardToolCall({
42
+ toolName: block.name,
43
+ toolArgs: input,
44
+ framework: 'anthropic',
45
+ // The tool_use id: one action = one record when a local AI gateway also saw this call.
46
+ ...(typeof block.id === 'string' && block.id ? { toolCallId: block.id } : {}),
47
+ agentName: options.agentName,
48
+ sessionId: options.sessionId,
49
+ operation: options.operation,
50
+ resourceType: options.resourceType,
51
+ }, async () => { ran = true; return handler(input); }, { approvalMode: options.approvalMode, timeoutMs: options.approvalTimeoutMs });
52
+ return { type: 'tool_result', tool_use_id: block.id, content: asText(result) };
53
+ }
54
+ catch (error) {
55
+ const message = error instanceof Error ? error.message : String(error);
56
+ // Stopped before the tool ran (policy, approval, refused configuration) or the tool itself raised: either way the model is told.
57
+ return { type: 'tool_result', tool_use_id: block.id, is_error: true, content: ran ? `Tool "${block.name}" failed: ${message}` : message };
58
+ }
59
+ };
60
+ if (options.sequential) {
61
+ const results = [];
62
+ for (const block of uses)
63
+ results.push(await runOne(block));
64
+ return results;
65
+ }
66
+ return Promise.all(uses.map(runOne));
67
+ }
@@ -0,0 +1,38 @@
1
+ /** Deepest nesting of objects and arrays the server analyses (the top-level object is depth 1). */
2
+ export declare const TOOL_ARGS_MAX_DEPTH = 32;
3
+ /** Most values (objects, arrays, strings, numbers, booleans, nulls) the server analyses. */
4
+ export declare const TOOL_ARGS_MAX_NODES = 20000;
5
+ export type ToolArgsProblem = {
6
+ kind: 'depth';
7
+ limit: number;
8
+ } | {
9
+ kind: 'nodes';
10
+ limit: number;
11
+ } | {
12
+ kind: 'unencodable';
13
+ errorType: string;
14
+ };
15
+ /** The first bound the value breaks, or undefined. Iterative: any depth is measured without recursion. */
16
+ export declare function toolArgsBeyondBounds(value: unknown): ToolArgsProblem | undefined;
17
+ /** The first of `toolArgs` / `argsSummary` that breaks a bound. */
18
+ export declare function toolCallArgsProblem(input: {
19
+ toolArgs?: unknown;
20
+ argsSummary?: unknown;
21
+ }): ToolArgsProblem | undefined;
22
+ /** Plain words: "nested deeper than 32 levels". */
23
+ export declare function toolArgsProblemWords(problem: ToolArgsProblem): string;
24
+ /** What is sent instead of the arguments: a fact, never the arguments. */
25
+ export declare function toolArgsProblemSummary(problem: ToolArgsProblem): Record<string, string>;
26
+ /** The rule id the server uses for the same answer. */
27
+ export declare const TOOL_ARGS_BOUNDS_RULE_ID = "args_beyond_bounds";
28
+ /**
29
+ * JSON-encode a request body, or say why it cannot be: a failure here is the call's own input, never an
30
+ * outage (the caller answers it definitely and never counts it on the circuit breaker).
31
+ */
32
+ export declare function encodeBody(body: unknown): {
33
+ ok: true;
34
+ json: string;
35
+ } | {
36
+ ok: false;
37
+ errorType: string;
38
+ };