capfence 0.6.2__tar.gz

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 (182) hide show
  1. capfence-0.6.2/.gitignore +84 -0
  2. capfence-0.6.2/CHANGELOG.md +160 -0
  3. capfence-0.6.2/LICENSE +21 -0
  4. capfence-0.6.2/PKG-INFO +267 -0
  5. capfence-0.6.2/README.md +228 -0
  6. capfence-0.6.2/benchmarks/README.md +36 -0
  7. capfence-0.6.2/benchmarks/scorer_benchmark.py +314 -0
  8. capfence-0.6.2/capfence/__init__.py +109 -0
  9. capfence-0.6.2/capfence/assessment/__init__.py +17 -0
  10. capfence-0.6.2/capfence/assessment/builder.py +301 -0
  11. capfence-0.6.2/capfence/assessment/eu_ai_act.py +241 -0
  12. capfence-0.6.2/capfence/assessment/owasp.py +153 -0
  13. capfence-0.6.2/capfence/assessment/reporter.py +114 -0
  14. capfence-0.6.2/capfence/assessment/scanner.py +337 -0
  15. capfence-0.6.2/capfence/assessment/simulator.py +245 -0
  16. capfence-0.6.2/capfence/assessment/templates/report.html +637 -0
  17. capfence-0.6.2/capfence/assessment/templates/report_compliance.html +682 -0
  18. capfence-0.6.2/capfence/assessment/templates/report_eu_ai_act.html +139 -0
  19. capfence-0.6.2/capfence/assessment/templates/report_owasp.html +92 -0
  20. capfence-0.6.2/capfence/check.py +401 -0
  21. capfence-0.6.2/capfence/cli.py +655 -0
  22. capfence-0.6.2/capfence/cloud/__init__.py +10 -0
  23. capfence-0.6.2/capfence/cloud/client.py +149 -0
  24. capfence-0.6.2/capfence/cloud/evaluator.py +85 -0
  25. capfence-0.6.2/capfence/core/approvals.py +224 -0
  26. capfence-0.6.2/capfence/core/audit.py +249 -0
  27. capfence-0.6.2/capfence/core/capabilities.py +83 -0
  28. capfence-0.6.2/capfence/core/chain.py +140 -0
  29. capfence-0.6.2/capfence/core/fsm.py +55 -0
  30. capfence-0.6.2/capfence/core/gate.py +397 -0
  31. capfence-0.6.2/capfence/core/hash.py +26 -0
  32. capfence-0.6.2/capfence/core/keys.py +208 -0
  33. capfence-0.6.2/capfence/core/plugins.py +55 -0
  34. capfence-0.6.2/capfence/core/policy.py +369 -0
  35. capfence-0.6.2/capfence/core/scorer.py +231 -0
  36. capfence-0.6.2/capfence/core/state.py +203 -0
  37. capfence-0.6.2/capfence/core/taxonomy.py +194 -0
  38. capfence-0.6.2/capfence/errors.py +69 -0
  39. capfence-0.6.2/capfence/flow/__init__.py +9 -0
  40. capfence-0.6.2/capfence/flow/tracer.py +317 -0
  41. capfence-0.6.2/capfence/framework/_base.py +62 -0
  42. capfence-0.6.2/capfence/framework/_risk.py +23 -0
  43. capfence-0.6.2/capfence/framework/autogen.py +53 -0
  44. capfence-0.6.2/capfence/framework/autogpt.py +21 -0
  45. capfence-0.6.2/capfence/framework/babyagi.py +21 -0
  46. capfence-0.6.2/capfence/framework/crewai.py +78 -0
  47. capfence-0.6.2/capfence/framework/langchain.py +118 -0
  48. capfence-0.6.2/capfence/framework/langgraph.py +140 -0
  49. capfence-0.6.2/capfence/framework/llamaindex.py +57 -0
  50. capfence-0.6.2/capfence/framework/openai_agents.py +94 -0
  51. capfence-0.6.2/capfence/framework/pydanticai.py +59 -0
  52. capfence-0.6.2/capfence/framework/swarm.py +21 -0
  53. capfence-0.6.2/capfence/mcp/__init__.py +10 -0
  54. capfence-0.6.2/capfence/mcp/adapter.py +79 -0
  55. capfence-0.6.2/capfence/mcp/gateway.py +263 -0
  56. capfence-0.6.2/capfence/py.typed +0 -0
  57. capfence-0.6.2/capfence/taxonomies/financial.json +396 -0
  58. capfence-0.6.2/capfence/taxonomies/financial_crypto.json +97 -0
  59. capfence-0.6.2/capfence/taxonomies/financial_plaid.json +123 -0
  60. capfence-0.6.2/capfence/taxonomies/general.json +112 -0
  61. capfence-0.6.2/capfence/taxonomies/healthcare.json +92 -0
  62. capfence-0.6.2/capfence/taxonomies/legal.json +47 -0
  63. capfence-0.6.2/capfence/telemetry/__init__.py +10 -0
  64. capfence-0.6.2/capfence/telemetry/client.py +178 -0
  65. capfence-0.6.2/capfence/types.py +19 -0
  66. capfence-0.6.2/capfence-demo/README.md +64 -0
  67. capfence-0.6.2/capfence-demo/pyproject.toml +19 -0
  68. capfence-0.6.2/capfence-demo/tests/test_capfence_check.py +77 -0
  69. capfence-0.6.2/docs/architecture/audit-chain-design.md +45 -0
  70. capfence-0.6.2/docs/architecture/enforcement-flow.md +35 -0
  71. capfence-0.6.2/docs/architecture/internal-components.md +44 -0
  72. capfence-0.6.2/docs/architecture/threat-model.md +36 -0
  73. capfence-0.6.2/docs/assets/demo.gif +0 -0
  74. capfence-0.6.2/docs/compliance/eu-ai-act.md +28 -0
  75. capfence-0.6.2/docs/compliance/governance-reporting.md +26 -0
  76. capfence-0.6.2/docs/compliance/owasp-agentic-top-10.md +25 -0
  77. capfence-0.6.2/docs/concepts/audit-chain.md +81 -0
  78. capfence-0.6.2/docs/concepts/fail-closed-enforcement.md +63 -0
  79. capfence-0.6.2/docs/concepts/policy-model.md +102 -0
  80. capfence-0.6.2/docs/concepts/replayability.md +65 -0
  81. capfence-0.6.2/docs/concepts/runtime-authorization.md +48 -0
  82. capfence-0.6.2/docs/concepts/trust-propagation.md +60 -0
  83. capfence-0.6.2/docs/examples/approval-workflows.md +58 -0
  84. capfence-0.6.2/docs/examples/database-write-gating.md +62 -0
  85. capfence-0.6.2/docs/examples/demo-cast.md +22 -0
  86. capfence-0.6.2/docs/examples/demo-walkthrough.md +71 -0
  87. capfence-0.6.2/docs/examples/demo.cast +29 -0
  88. capfence-0.6.2/docs/examples/fintech-agent.md +117 -0
  89. capfence-0.6.2/docs/examples/mcp-governance.md +55 -0
  90. capfence-0.6.2/docs/examples/replay-demo.md +41 -0
  91. capfence-0.6.2/docs/getting-started/first-blocked-action.md +97 -0
  92. capfence-0.6.2/docs/getting-started/first-policy.md +134 -0
  93. capfence-0.6.2/docs/getting-started/installation.md +47 -0
  94. capfence-0.6.2/docs/getting-started/quickstart.md +94 -0
  95. capfence-0.6.2/docs/guides/air-gapped-deployments.md +75 -0
  96. capfence-0.6.2/docs/guides/ci-cd-enforcement.md +103 -0
  97. capfence-0.6.2/docs/guides/observe-mode-rollout.md +82 -0
  98. capfence-0.6.2/docs/guides/protect-payment-agents.md +101 -0
  99. capfence-0.6.2/docs/guides/protect-shell-tools.md +102 -0
  100. capfence-0.6.2/docs/guides/replay-an-incident.md +82 -0
  101. capfence-0.6.2/docs/guides/require-human-approval.md +104 -0
  102. capfence-0.6.2/docs/guides/secure-mcp-servers.md +91 -0
  103. capfence-0.6.2/docs/index.md +113 -0
  104. capfence-0.6.2/docs/integrations/autogen.md +31 -0
  105. capfence-0.6.2/docs/integrations/compatibility.md +20 -0
  106. capfence-0.6.2/docs/integrations/crewai.md +90 -0
  107. capfence-0.6.2/docs/integrations/custom-frameworks.md +87 -0
  108. capfence-0.6.2/docs/integrations/langchain.md +102 -0
  109. capfence-0.6.2/docs/integrations/langgraph.md +79 -0
  110. capfence-0.6.2/docs/integrations/llamaindex.md +35 -0
  111. capfence-0.6.2/docs/integrations/mcp.md +85 -0
  112. capfence-0.6.2/docs/integrations/openai-agents-sdk.md +81 -0
  113. capfence-0.6.2/docs/integrations/pydanticai.md +35 -0
  114. capfence-0.6.2/docs/recipes/index.md +9 -0
  115. capfence-0.6.2/docs/recipes/mcp-filesystem-allowlist.md +38 -0
  116. capfence-0.6.2/docs/recipes/payments-thresholds.md +40 -0
  117. capfence-0.6.2/docs/recipes/production-db-writes.md +40 -0
  118. capfence-0.6.2/docs/recipes/saas-admin-approval.md +38 -0
  119. capfence-0.6.2/docs/recipes/shell-tools.md +31 -0
  120. capfence-0.6.2/docs/reference/audit-log-format.md +75 -0
  121. capfence-0.6.2/docs/reference/cli.md +250 -0
  122. capfence-0.6.2/docs/reference/configuration.md +89 -0
  123. capfence-0.6.2/docs/reference/flowtracer-api.md +71 -0
  124. capfence-0.6.2/docs/reference/gate-api.md +117 -0
  125. capfence-0.6.2/docs/reference/policy-schema.md +133 -0
  126. capfence-0.6.2/examples/autogen/autogen_demo.py +23 -0
  127. capfence-0.6.2/examples/core_concepts/ed25519_signing_demo.py +64 -0
  128. capfence-0.6.2/examples/core_concepts/eu_ai_act_demo.py +53 -0
  129. capfence-0.6.2/examples/core_concepts/fintech_payment_agent.py +511 -0
  130. capfence-0.6.2/examples/core_concepts/hash_chain_demo.py +65 -0
  131. capfence-0.6.2/examples/core_concepts/langchain_agent.py +85 -0
  132. capfence-0.6.2/examples/core_concepts/langchain_realistic.py +98 -0
  133. capfence-0.6.2/examples/core_concepts/langgraph_demo.py +74 -0
  134. capfence-0.6.2/examples/core_concepts/local_only.py +79 -0
  135. capfence-0.6.2/examples/core_concepts/owasp_report_demo.py +52 -0
  136. capfence-0.6.2/examples/core_concepts/plaid_taxonomy_demo.py +43 -0
  137. capfence-0.6.2/examples/core_concepts/run_all_examples.py +81 -0
  138. capfence-0.6.2/examples/core_concepts/tamper_demo.py +164 -0
  139. capfence-0.6.2/examples/core_concepts/telemetry_demo.py +46 -0
  140. capfence-0.6.2/examples/crewai/crewai_demo.py +22 -0
  141. capfence-0.6.2/examples/langchain/langchain_demo.py +25 -0
  142. capfence-0.6.2/examples/mcp/mcp_gateway_demo.py +14 -0
  143. capfence-0.6.2/examples/openai_agents/openai_demo.py +27 -0
  144. capfence-0.6.2/pyproject.toml +105 -0
  145. capfence-0.6.2/tests/corpus/README.md +63 -0
  146. capfence-0.6.2/tests/corpus/benign_traces.jsonl +50 -0
  147. capfence-0.6.2/tests/corpus/edge_cases.jsonl +30 -0
  148. capfence-0.6.2/tests/corpus/evaluate.py +154 -0
  149. capfence-0.6.2/tests/corpus/risky_traces.jsonl +50 -0
  150. capfence-0.6.2/tests/fixtures/traces/adversarial_agent_trace.jsonl +8 -0
  151. capfence-0.6.2/tests/fixtures/traces/financial_agent_trace.jsonl +10 -0
  152. capfence-0.6.2/tests/fixtures/traces/safe_agent_trace.jsonl +5 -0
  153. capfence-0.6.2/tests/test_assessment.py +205 -0
  154. capfence-0.6.2/tests/test_async_gate.py +83 -0
  155. capfence-0.6.2/tests/test_builder.py +67 -0
  156. capfence-0.6.2/tests/test_check.py +282 -0
  157. capfence-0.6.2/tests/test_cloud_client.py +62 -0
  158. capfence-0.6.2/tests/test_core_chain.py +299 -0
  159. capfence-0.6.2/tests/test_core_fsm.py +54 -0
  160. capfence-0.6.2/tests/test_core_gate.py +133 -0
  161. capfence-0.6.2/tests/test_core_hash.py +27 -0
  162. capfence-0.6.2/tests/test_core_keys.py +73 -0
  163. capfence-0.6.2/tests/test_core_scorer.py +85 -0
  164. capfence-0.6.2/tests/test_core_state.py +57 -0
  165. capfence-0.6.2/tests/test_core_taxonomy.py +48 -0
  166. capfence-0.6.2/tests/test_errors.py +65 -0
  167. capfence-0.6.2/tests/test_eu_ai_act.py +47 -0
  168. capfence-0.6.2/tests/test_flow_tracer.py +98 -0
  169. capfence-0.6.2/tests/test_framework_adapters.py +155 -0
  170. capfence-0.6.2/tests/test_framework_crewai.py +66 -0
  171. capfence-0.6.2/tests/test_framework_langchain.py +77 -0
  172. capfence-0.6.2/tests/test_framework_langgraph.py +171 -0
  173. capfence-0.6.2/tests/test_framework_openai_agents.py +140 -0
  174. capfence-0.6.2/tests/test_gate_modes.py +97 -0
  175. capfence-0.6.2/tests/test_mcp.py +169 -0
  176. capfence-0.6.2/tests/test_owasp.py +33 -0
  177. capfence-0.6.2/tests/test_policy_engine.py +246 -0
  178. capfence-0.6.2/tests/test_simulator.py +77 -0
  179. capfence-0.6.2/tests/test_taxonomy_plaid.py +23 -0
  180. capfence-0.6.2/tests/test_taxonomy_starters.py +68 -0
  181. capfence-0.6.2/tests/test_telemetry_client.py +42 -0
  182. capfence-0.6.2/tests/test_thread_safety.py +103 -0
@@ -0,0 +1,84 @@
1
+ # Strategy docs, build plans, PR descriptions — keep out of public repo
2
+ # README.md is explicitly allowed (needed for PyPI/GitHub)
3
+ *.md
4
+ !README.md
5
+ !CHANGELOG.md
6
+ !CONTRIBUTING.md
7
+ !CODE_OF_CONDUCT.md
8
+ !SECURITY.md
9
+ !docs/*.md
10
+ !docs/**/*.md
11
+ !docs-dev/*.md
12
+ !docs-dev/**/*.md
13
+
14
+ # Internal review artifacts (do not commit)
15
+ docs/CODE_REVIEW_*.md
16
+ docs/REVIEW_*.md
17
+ docs/*_REVIEW.md
18
+ docs/INTERNAL_*.md
19
+ BUILDPLAN.md
20
+ TRADE_SECRET*.md
21
+ CHANGES_TO_APPLY_MANUALLY.md
22
+
23
+ # Private Cloud repo — decoupled from OSS
24
+ capfence-cloud/
25
+
26
+ # Python
27
+ __pycache__/
28
+ *.py[cod]
29
+ *$py.class
30
+ *.so
31
+ .Python
32
+ *.egg-info/
33
+ dist/
34
+ build/
35
+ .eggs/
36
+ *.egg
37
+
38
+ # Tool caches
39
+ .mypy_cache/
40
+ .pytest_cache/
41
+ .ruff_cache/
42
+
43
+ # Virtual environments
44
+ venv/
45
+ .venv/
46
+ env/
47
+ ENV/
48
+
49
+ # IDE
50
+ .vscode/
51
+ .idea/
52
+ *.swp
53
+ *.swo
54
+
55
+ # Environment secrets
56
+ .env
57
+ .env.local
58
+ .env.production
59
+
60
+ # Encrypted files
61
+ *.age
62
+ key.txt
63
+
64
+ # Trade secrets (NEVER commit to git)
65
+ TRADE_SECRET.md
66
+ TRADE_SECRET*
67
+
68
+ # Patent documents (NEVER commit)
69
+ *patent*
70
+ *Patent*
71
+ *PROVISIONAL*
72
+
73
+ # Init docs (patent documents, strategy HTMLs)
74
+ .initdocs/
75
+
76
+ # Archive (old build plans, deprecated docs, superseded specs)
77
+ archive/
78
+
79
+ # OS
80
+ .DS_Store
81
+ Thumbs.db
82
+ site/
83
+ capfence-demo/capfence-assessment-report.html
84
+ capfence-demo/audit.db
@@ -0,0 +1,160 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [0.6.2] - 2026-05-15
11
+
12
+ ### Added
13
+ - `capfence check-policy` command for validating YAML policy files.
14
+ - Policy support for `contains`, `amount_gte`, `amount_lt`, `amount_lte`, `path_prefix`, caller-depth comparisons, and legacy `rules` starter-policy schemas.
15
+ - Demo walkthrough, demo cast, and demo script covering scan, assess, gate enforcement, simulate, and verify workflows.
16
+ - Recipes section with copy-paste policy patterns and integrations for PydanticAI, LlamaIndex, and AutoGen.
17
+ - Compatibility matrix for supported framework adapters.
18
+
19
+ ### Changed
20
+ - README and docs homepage now position CapFence around deterministic runtime authorization, rollout, limitations, and proof-oriented workflows.
21
+ - Repository URLs now point to the `capfencelabs/capfence-python` namespace.
22
+ - Local package metadata now matches the PyPI `0.6.2` release line.
23
+
24
+ ### Fixed
25
+ - Policy load and validation failures now fail closed during gate evaluation.
26
+ - Audit write failures now fail closed in enforce mode.
27
+ - Policy schema documentation now matches implemented behavior.
28
+
29
+ ## [0.5.0] - 2026-05-11
30
+
31
+ ### Added
32
+ - **Multi-agent flow tracer** (`capfence.flow.FlowTracer`). Records data flows between agents and propagates trust downward — UNTRUSTED data feeding a SYSTEM-trust agent contaminates that agent's effective trust. Reverse index keeps `annotate()` O(1) per source agent. Thread-safe via internal `RLock`. Configurable `max_edges` with FIFO eviction.
33
+ - **Gate observe mode** (`Gate(mode="observe")`). Logs every decision without blocking. `result.metadata["would_have_blocked"]` reports what enforce mode would have done. Use for staged rollout before turning enforcement on.
34
+ - **Gate bypass context manager** (`gate.bypass(agent_id, reason="...")`). Per-agent stack-based override with mandatory non-empty audit-trail reason. Thread-safe; reason is stored in the audit log.
35
+ - **`capfence tune` CLI command**. Reads recent gate decisions, groups by risk category, and suggests RAISE / LOWER / OK threshold adjustments based on block rate vs. average score.
36
+ - **`evaluate_async()` on `Gate`**. Async wrapper that runs the synchronous scoring + SQLite I/O on the default thread-pool executor so an event loop is never blocked.
37
+ - **`arun()` / `ainvoke()` on framework adapters**. `CapFenceTool` (LangChain), `CapFenceCrewAITool`, `CapFenceToolNode` (LangGraph) gained async variants that use `evaluate_async` and forward to the wrapped tool's async method when present. OpenAI Agents SDK and MCP adapters now use `evaluate_async` internally so the gate no longer blocks the event loop.
38
+ - **Unified exception hierarchy** in `capfence.errors`. `CapFenceError` base class with `AgentActionBlocked`, `ConfigurationError`, `AuditError`, `TaxonomyError`, `GatewayError` subclasses. `AgentActionBlocked` is now a single class re-exported by every framework module, so `except capfence.AgentActionBlocked` catches blocks from any adapter.
39
+ - **Expanded taxonomies**: `financial.json` grew from 14 to 32 categories (loan_origination, KYC, AML, sanctions, FX, card_control, open_banking_consent, etc.). New `financial_crypto.json` (18 categories) and `healthcare.json` (17 categories).
40
+ - **Tamper-evidence demo** (`examples/tamper_demo.py`). Records 6 gate decisions, corrupts a row directly in SQLite, verifies the chain breaks, restores and re-verifies.
41
+ - **Production-style fintech agent** (`examples/fintech_payment_agent.py`). 4 payment tools wrapped with the Gate; demonstrates idempotency keys, exponential backoff, and gate-driven early returns.
42
+ - **Labelled test corpus** (`tests/corpus/`). 130 traces (50 benign / 50 risky / 30 edge cases) in JSONL with `evaluate.py` runner.
43
+ - **Scorer benchmark** (`benchmarks/scorer_benchmark.py`). Compares KeywordScorer, RegexASTScorer, AdaptiveScorer on 10K synthetic traces with TPR/FPR/F1/latency. `benchmarks/README.md` documents how to read the results honestly.
44
+ - **Threat model doc** (`docs/THREAT_MODEL.md`). Attack surface diagram, what CapFence catches, what it misses (G1–G9), recommended additional layers, false-positive runbook.
45
+ - **Top-level `__version__`** exposed via `capfence.__version__`.
46
+ - **`py.typed` marker**. Package now ships type information for mypy / pyright consumers.
47
+
48
+ ### Changed
49
+ - **Package classifier bumped to `Development Status :: 4 - Beta`**; added `Topic :: Security` and `Typing :: Typed` classifiers.
50
+ - **`Gate._bypass_stack` is now thread-safe** via an internal `threading.RLock`; concurrent agents can share one `Gate` instance.
51
+ - **`FlowTracer` is now thread-safe**. Previous docstring claim "use one instance per thread" removed.
52
+ - **`Gate.__init__` and `Gate.bypass`** now raise `ConfigurationError` instead of bare `ValueError` (subclass of `ValueError` for backward compatibility).
53
+ - **MCP gateway** now raises `GatewayError` instead of bare `RuntimeError` (subclass of `RuntimeError` for backward compatibility).
54
+ - README rewritten with new features section (observe mode, FlowTracer, expanded taxonomies, threat model link); test badge updated to 226 passing.
55
+ - Tests: 205 → 226 passing.
56
+
57
+ ### Fixed
58
+ - Deduplicated `would_have_blocked` metadata assignment in `Gate.evaluate()`.
59
+ - Removed dead `payload` parameter from `FlowTracer.annotate()` signature.
60
+ - Replaced custom `_hash_data()` in FlowTracer with `compute_payload_hash` for consistency.
61
+ - Hoisted `import statistics` / `from collections import defaultdict` in `cli.py` from inside `tune()` to module level.
62
+
63
+ ## [0.4.1] - 2026-05-10
64
+
65
+ ### Changed
66
+ - README overhaul: hero section with three AGT differentiators, collapsed feature list into 6 categories, honest positioning docs.
67
+ - Added CHANGELOG.md, CONTRIBUTING.md, CODE_OF_CONDUCT.md, SECURITY.md, docs/CLI.md, docs/FEATURES.md, docs/POSITIONING.md.
68
+ - Added GitHub issue templates and pull request template.
69
+
70
+ ### Fixed
71
+ - Removed unused `pytest` import in `tests/test_mcp.py` (CI ruff failure).
72
+ - Added `mypy` `ignore_missing_imports` for `cryptography` and `capfence._native` (CI mypy failure).
73
+ - Fixed README Python API example to match real `Gate.evaluate()` signature.
74
+ - Fixed ASCII architecture diagram alignment.
75
+
76
+ ## [0.4.0] - 2026-05-08
77
+
78
+ ### Added
79
+ - **Hash-chained, tamper-evident audit log** (`capfence/core/chain.py`). Every audit entry links to the previous via SHA-256. Modifying any row invalidates the chain. Verified via `capfence verify`.
80
+ - **Optional Ed25519 signing of audit entries** (`capfence/core/keys.py`). Generate keypairs, sign each entry, and verify authenticity cryptographically. Falls back to HMAC-SHA256 when `cryptography` is not installed.
81
+ - **Hardened Regex+AST scorer** (`capfence/core/scorer.py`). `RegexASTScorer` adds whole-word regex matching and Python AST analysis for dangerous constructs (`os.system`, `subprocess.call`, `eval`, `exec`).
82
+ - **OWASP Agentic Top 10 coverage matrix** (`capfence/assessment/owasp.py`). Static mapping of CapFence controls to OWASP Agentic AI Top 10 risks. Generate HTML reports via `capfence owasp`.
83
+ - **MCP gateway server** (`capfence/mcp/gateway.py`). Stdio proxy that intercepts MCP tool calls through the CapFence Gate. JSON-RPC parsing with Content-Length protocol.
84
+ - **MCP in-process adapter** (`capfence/mcp/adapter.py`). `CapFenceMCPSession` wraps an existing MCP client session with CapFence gating for async tool calls.
85
+ - **LangGraph integration** (`capfence/framework/langgraph.py`). `CapFenceToolNode` replaces LangGraph `ToolNode` with automatic gate enforcement on every tool invocation.
86
+ - **OpenAI Agents SDK integration** (`capfence/framework/openai_agents.py`). `CapFenceOpenAITool` wraps OpenAI Agents SDK tools with deterministic gate evaluation.
87
+ - **EU AI Act Annex IV evidence pack generator** (`capfence/assessment/eu_ai_act.py`). Generates structured JSON + HTML evidence packs for regulatory submission. Covers risk management, cybersecurity, data governance, and technical documentation.
88
+ - **Plaid taxonomy pack** (`capfence/taxonomies/financial_plaid.json`). 10 Plaid-specific risk categories: auth, balance, transactions, identity, income, transfer, link token, item management, liabilities, investments.
89
+ - **Opt-in telemetry client** (`capfence/telemetry/client.py`). Async fire-and-forget exporter for hashed metadata only. Disabled by default; enable via `CAPFENCE_TELEMETRY=1`.
90
+ - **CLI commands**: `capfence verify` (audit log integrity), `capfence owasp` (coverage matrix), `capfence eu-ai-act` (evidence pack generation).
91
+ - **9 new runnable examples** in `examples/` covering all v0.4.0 features, plus `examples/run_all_examples.py` test runner.
92
+ - **11 new test files** bringing total to 205 tests (1 skipped for optional `pytest-asyncio`).
93
+ - **Demo project** (`capfence-demo/`) — realistic fintech agent with 8 tools, 2 intentionally ungated, for end-to-end scanner validation.
94
+
95
+ ### Changed
96
+ - **README overhaul**: collapsed 14-item feature list into 6 grouped categories; added Testing section; updated Examples table with all 12 examples.
97
+ - **Architecture diagram**: updated audit-log box to "Hash-chained + Ed25519".
98
+ - **Project Status**: trimmed from 14 bullets to 6 grouped categories.
99
+ - **Cross-file wrapper detection**: two-pass scanner (`_collect_all_wrappers` then `scan_file`) correctly detects tools wrapped in a different file from their definition.
100
+ - **Taxonomy cache safety**: `TaxonomyLoader.load()` now returns `copy.deepcopy(data)` to prevent shared mutable state poisoning.
101
+ - **Scorer performance**: added `@functools.lru_cache` for regex pattern compilation in `RegexASTScorer`.
102
+
103
+ ### Fixed
104
+ - **Timing attack vulnerability** in fallback signature verification: replaced `==` with `hmac.compare_digest` in `capfence/core/keys.py`.
105
+ - **Private key race condition**: `generate_keypair()` now uses atomic `os.open()` with mode `0o600` instead of `write_text()` + `os.chmod()`.
106
+ - **Taxonomy cache poisoning**: `Gate.evaluate()` now deep-copies taxonomy entries before mutation.
107
+ - **MCP unbounded Content-Length**: enforced `MAX_MESSAGE_SIZE` (10MB) to prevent memory exhaustion.
108
+ - **MCP stderr thread race**: `_drain_stderr` now acquires `self._lock` when accessing `self._proc`.
109
+ - **Telemetry worker race**: `TelemetryClient.start()` now guarded by `asyncio.Lock` to prevent duplicate worker tasks.
110
+ - **EU AI Act path traversal**: `write_html()` and `write_json()` now reject paths containing `..` components.
111
+ - **CLI version consistency**: extracted `__version__` constant; fixed hardcoded `0.3.0` in assessment context.
112
+ - **Hash chain missing-key validation**: `verify_chain_from_rows()` now gracefully handles malformed DB rows instead of raising `KeyError`.
113
+
114
+ ### Security
115
+ - See Fixed section above for security-related fixes.
116
+
117
+ ## [0.3.3] - 2026-05-07
118
+
119
+ ### Added
120
+ - `default="."` on `capfence check` path argument so `capfence check` works without explicit path.
121
+
122
+ ### Fixed
123
+ - Cross-file wrapper detection: tools defined in one file and wrapped in another are now correctly detected as gated (two-pass scanning).
124
+
125
+ ## [0.3.2] - 2026-05-07
126
+
127
+ ### Fixed
128
+ - README version badge and PyPI description sync.
129
+ - CI workflow with release assets.
130
+
131
+ ## [0.3.1] - 2026-05-07
132
+
133
+ ### Added
134
+ - `capfence check --output report.html` for HTML report generation from static scan.
135
+ - `--fail-on-ungated` flag for CI/CD integration.
136
+
137
+ ### Fixed
138
+ - Scanner false positives on non-tool classes.
139
+
140
+ ## [0.3.0] - 2026-05-07
141
+
142
+ ### Added
143
+ - Initial PyPI release.
144
+ - Core Gate with keyword-based scoring and configurable thresholds.
145
+ - SQLite-backed audit log (append-only).
146
+ - LangChain and CrewAI adapters.
147
+ - Static scanner (`capfence check`) for detecting ungated tool classes.
148
+ - Assessment reporter with Jinja2 HTML reports.
149
+ - Trace simulator (`capfence simulate`) for replaying agent execution traces.
150
+ - Interactive taxonomy builder (`capfence build-taxonomy`).
151
+ - Three starter taxonomies: general, financial, legal.
152
+ - Cloud client hook (legacy, not used in OSS path).
153
+
154
+ [Unreleased]: https://github.com/capfencelabs/capfence-python/compare/v0.6.2...HEAD
155
+ [0.6.2]: https://github.com/capfencelabs/capfence-python/compare/v0.5.0...v0.6.2
156
+ [0.4.0]: https://github.com/capfencelabs/capfence-python/compare/v0.3.3...v0.4.0
157
+ [0.3.3]: https://github.com/capfencelabs/capfence-python/compare/v0.3.2...v0.3.3
158
+ [0.3.2]: https://github.com/capfencelabs/capfence-python/compare/v0.3.1...v0.3.2
159
+ [0.3.1]: https://github.com/capfencelabs/capfence-python/compare/v0.3.0...v0.3.1
160
+ [0.3.0]: https://github.com/capfencelabs/capfence-python/releases/tag/v0.3.0
capfence-0.6.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Anshuman Kumar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,267 @@
1
+ Metadata-Version: 2.4
2
+ Name: capfence
3
+ Version: 0.6.2
4
+ Summary: Runtime governance for AI agents — deterministic fail-closed enforcement. Wraps any agent tool and blocks dangerous calls before execution. Zero LLM calls, zero cloud dependencies, works offline.
5
+ Project-URL: Homepage, https://capfence.dev/
6
+ Project-URL: Repository, https://github.com/capfencelabs/capfence-python
7
+ Project-URL: Issues, https://github.com/capfencelabs/capfence-python/issues
8
+ Author: Anshuman Kumar
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,ai,audit,compliance,crewai,enforcement,governance,guardrails,langchain,llm,runtime,safety,security,tool-calling
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Information Technology
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: Implementation :: CPython
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Security
24
+ Classifier: Typing :: Typed
25
+ Requires-Python: >=3.10
26
+ Requires-Dist: click>=8.0
27
+ Requires-Dist: jinja2>=3.1
28
+ Requires-Dist: pyyaml>=6.0
29
+ Provides-Extra: crewai
30
+ Requires-Dist: crewai>=0.30; extra == 'crewai'
31
+ Provides-Extra: dev
32
+ Requires-Dist: mypy>=1.8; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=4.0; extra == 'dev'
34
+ Requires-Dist: pytest>=8.0; extra == 'dev'
35
+ Requires-Dist: ruff>=0.3; extra == 'dev'
36
+ Provides-Extra: langchain
37
+ Requires-Dist: langchain-core>=0.1; extra == 'langchain'
38
+ Description-Content-Type: text/markdown
39
+
40
+ # CapFence
41
+
42
+ <p align="center">
43
+ <strong>Deterministic runtime authorization for AI agent tool calls.</strong>
44
+ </p>
45
+
46
+ <p align="center">
47
+ <a href="https://pypi.org/project/capfence/"><img src="https://img.shields.io/pypi/v/capfence?color=blue" alt="PyPI version"></a>
48
+ <a href="https://pypi.org/project/capfence/"><img src="https://img.shields.io/pypi/pyversions/capfence" alt="Python versions"></a>
49
+ <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="License: MIT"></a>
50
+ <img src="https://img.shields.io/badge/tests-passing-brightgreen" alt="Tests: passing">
51
+ </p>
52
+
53
+ CapFence sits between AI agents and their tools. It evaluates every tool call against deterministic policy before execution, then allows it, blocks it, or requires approval.
54
+
55
+ It is closer to IAM, Open Policy Agent, API gateways, and admission controllers than prompt guardrails or moderation.
56
+
57
+ ```text
58
+ Agent -> CapFence -> Tool
59
+ |
60
+ +-- allow
61
+ +-- deny
62
+ +-- require approval
63
+ ```
64
+
65
+ <p align="center">
66
+ <img src="docs/assets/demo.gif" alt="CapFence terminal demo" width="720">
67
+ </p>
68
+
69
+ ## Why This Exists
70
+
71
+ Agents increasingly call tools that can move money, edit databases, run shell commands, read files, modify permissions, and operate SaaS admin APIs.
72
+
73
+ Prompt instructions are not an execution boundary. CapFence gives those tool calls an explicit runtime authorization layer:
74
+
75
+ - No LLM call in the gate path.
76
+ - Policy-as-code decisions.
77
+ - Default-deny behavior when policy does not match.
78
+ - Fail-closed handling for policy and audit failures.
79
+ - Local audit logs with hash-chain verification.
80
+ - Observe mode for safe rollout before enforcement.
81
+
82
+ ## Install
83
+
84
+ ```bash
85
+ pip install capfence
86
+ ```
87
+
88
+ ## 60-Second Example
89
+
90
+ Create a policy:
91
+
92
+ ```yaml
93
+ deny:
94
+ - capability: shell.execute
95
+ contains: "rm -rf"
96
+
97
+ require_approval:
98
+ - capability: payments.transfer
99
+ amount_gt: 1000
100
+
101
+ allow:
102
+ - capability: shell.execute
103
+ - capability: payments.transfer
104
+ amount_lte: 1000
105
+ ```
106
+
107
+ Evaluate a tool call before execution:
108
+
109
+ ```python
110
+ from capfence.core.gate import Gate
111
+
112
+ gate = Gate()
113
+
114
+ result = gate.evaluate(
115
+ agent_id="ops-agent",
116
+ task_context="shell",
117
+ risk_category="shell_execution",
118
+ capability="shell.execute",
119
+ policy_path="policies/shell_agent.yaml",
120
+ payload={"command": "rm -rf /var/lib/postgresql"},
121
+ )
122
+
123
+ if not result.passed:
124
+ raise PermissionError(f"Blocked: {result.reason}")
125
+ ```
126
+
127
+ The dangerous command never reaches the tool.
128
+
129
+ ## Framework Integrations
130
+
131
+ CapFence can wrap tools in:
132
+
133
+ - LangChain
134
+ - LangGraph
135
+ - CrewAI
136
+ - OpenAI Agents SDK
137
+ - MCP
138
+ - PydanticAI
139
+ - LlamaIndex
140
+ - AutoGen
141
+ - Direct Python runtimes
142
+
143
+ LangChain example:
144
+
145
+ ```python
146
+ from capfence import CapFenceTool
147
+ from langchain.tools import ShellTool
148
+
149
+ safe_shell = CapFenceTool(
150
+ tool=ShellTool(),
151
+ agent_id="ops-agent",
152
+ capability="shell.execute",
153
+ policy_path="policies/shell_agent.yaml",
154
+ )
155
+ ```
156
+
157
+ ## CLI Workflows
158
+
159
+ Scan for ungated tools:
160
+
161
+ ```bash
162
+ capfence check ./src --fail-on-ungated
163
+ ```
164
+
165
+ Validate a policy:
166
+
167
+ ```bash
168
+ capfence check-policy policies/shell_agent.yaml
169
+ ```
170
+
171
+ Replay a trace through policy:
172
+
173
+ ```bash
174
+ capfence simulate --trace-file traces/agent_trace.jsonl --compare
175
+ ```
176
+
177
+ Verify audit-log integrity:
178
+
179
+ ```bash
180
+ capfence verify --audit-log audit.db
181
+ ```
182
+
183
+ ## Rollout Path
184
+
185
+ 1. Start in observe mode and log decisions without blocking.
186
+ 2. Review audit logs and tune policies.
187
+ 3. Enforce policy for high-risk tools.
188
+ 4. Add CI checks so new ungated tools cannot quietly ship.
189
+ 5. Replay incidents and policy changes against saved traces.
190
+
191
+ ## What CapFence Is Not
192
+
193
+ CapFence is a runtime authorization and audit layer. It does not replace:
194
+
195
+ - sandboxing for shell/code execution
196
+ - least-privilege credentials
197
+ - network egress controls
198
+ - prompt-injection defenses
199
+ - human review for genuinely ambiguous high-risk actions
200
+
201
+ Use it as the deterministic control point before tool execution.
202
+
203
+ ## Why Not Prompt Guardrails?
204
+
205
+ Prompt guardrails are useful, but they do not enforce execution. A prompt can be bypassed, misinterpreted, or ignored under pressure. CapFence adds a deterministic enforcement boundary that blocks tool calls before they execute and records a tamper-evident audit trail.
206
+
207
+ ## Where It Sits In Your Stack
208
+
209
+ ```
210
+ Agent framework -> CapFence gate -> Tool/API/DB/Shell
211
+ ```
212
+
213
+ CapFence does not replace sandboxing, network egress controls, or least-privilege credentials. It complements them by enforcing runtime policy at the tool boundary.
214
+
215
+ ## Project Status
216
+
217
+ CapFence is beta infrastructure for agent tool governance. The repo includes:
218
+
219
+ - deterministic gate and policy engine
220
+ - local audit log with hash-chain verification
221
+ - approval workflows
222
+ - observe mode and bypass audit trails
223
+ - framework adapters
224
+ - MCP gateway and adapter
225
+ - static scanner and CI mode
226
+ - OWASP Agentic Top 10 and EU AI Act evidence reports
227
+ - typed Python package with ruff, mypy, and pytest coverage
228
+
229
+ Current local verification: run `pytest -q`.
230
+
231
+ ## Documentation
232
+
233
+ - Docs: https://capfence.dev/
234
+ - PyPI: https://pypi.org/project/capfence/
235
+ - Repository: https://github.com/capfencelabs/capfence-python
236
+
237
+ Useful starting points:
238
+
239
+ - [Quickstart](docs/getting-started/quickstart.md)
240
+ - [First policy](docs/getting-started/first-policy.md)
241
+ - [Recipes](docs/recipes/index.md)
242
+ - [Compatibility matrix](docs/integrations/compatibility.md)
243
+ - [Protect shell tools](docs/guides/protect-shell-tools.md)
244
+ - [Protect payment agents](docs/guides/protect-payment-agents.md)
245
+ - [Secure MCP servers](docs/guides/secure-mcp-servers.md)
246
+ - [Demo walkthrough](docs/examples/demo-walkthrough.md)
247
+ - [Demo cast](docs/examples/demo-cast.md)
248
+ - [Policy schema](docs/reference/policy-schema.md)
249
+
250
+ ## Contributing
251
+
252
+ ```bash
253
+ git clone https://github.com/capfencelabs/capfence-python.git
254
+ cd capfence-python
255
+ pip install -e ".[dev]"
256
+ pytest tests/ -q
257
+ ```
258
+
259
+ Policy recipes, framework adapters, taxonomies, docs, and focused bug reports are welcome.
260
+
261
+ ## License
262
+
263
+ MIT License
264
+
265
+ <p align="center">
266
+ <sub>Built by <a href="https://github.com/capfencelabs">CapFence Labs</a></sub>
267
+ </p>