regula-ai 1.5.0__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 (91) hide show
  1. regula-ai-1.5.0/LICENSE.txt +21 -0
  2. regula-ai-1.5.0/PKG-INFO +631 -0
  3. regula-ai-1.5.0/README.md +592 -0
  4. regula-ai-1.5.0/hooks/__init__.py +1 -0
  5. regula-ai-1.5.0/hooks/post_tool_use.py +63 -0
  6. regula-ai-1.5.0/hooks/pre_tool_use.py +320 -0
  7. regula-ai-1.5.0/hooks/stop_hook.py +98 -0
  8. regula-ai-1.5.0/hooks/version_check.py +32 -0
  9. regula-ai-1.5.0/pyproject.toml +51 -0
  10. regula-ai-1.5.0/references/__init__.py +0 -0
  11. regula-ai-1.5.0/references/advisories/pypi/litellm/x_REGULA-2026-001.yaml +47 -0
  12. regula-ai-1.5.0/references/annex_iv_template.md +102 -0
  13. regula-ai-1.5.0/references/article_obligations.yaml +170 -0
  14. regula-ai-1.5.0/references/eu_ai_act_articles_9_15.md +135 -0
  15. regula-ai-1.5.0/references/framework_crosswalk.yaml +426 -0
  16. regula-ai-1.5.0/references/gpai_obligations.md +57 -0
  17. regula-ai-1.5.0/references/iso_42001_mapping.yaml +130 -0
  18. regula-ai-1.5.0/references/mitre_atlas.yaml +52 -0
  19. regula-ai-1.5.0/references/owasp_llm_top10.yaml +57 -0
  20. regula-ai-1.5.0/references/risk_indicators.yaml +257 -0
  21. regula-ai-1.5.0/references/tree_sitter_implementation_guide.md +740 -0
  22. regula-ai-1.5.0/regula_ai.egg-info/PKG-INFO +631 -0
  23. regula-ai-1.5.0/regula_ai.egg-info/SOURCES.txt +89 -0
  24. regula-ai-1.5.0/regula_ai.egg-info/dependency_links.txt +1 -0
  25. regula-ai-1.5.0/regula_ai.egg-info/entry_points.txt +2 -0
  26. regula-ai-1.5.0/regula_ai.egg-info/requires.txt +21 -0
  27. regula-ai-1.5.0/regula_ai.egg-info/top_level.txt +3 -0
  28. regula-ai-1.5.0/scripts/__init__.py +2 -0
  29. regula-ai-1.5.0/scripts/__main__.py +9 -0
  30. regula-ai-1.5.0/scripts/agent_monitor.py +565 -0
  31. regula-ai-1.5.0/scripts/ast_analysis.py +1118 -0
  32. regula-ai-1.5.0/scripts/ast_engine.py +1727 -0
  33. regula-ai-1.5.0/scripts/baseline.py +175 -0
  34. regula-ai-1.5.0/scripts/benchmark.py +815 -0
  35. regula-ai-1.5.0/scripts/bias_eval.py +208 -0
  36. regula-ai-1.5.0/scripts/classify_risk.py +675 -0
  37. regula-ai-1.5.0/scripts/cli.py +1673 -0
  38. regula-ai-1.5.0/scripts/code_analysis.py +288 -0
  39. regula-ai-1.5.0/scripts/compliance_check.py +1246 -0
  40. regula-ai-1.5.0/scripts/config_validator.py +270 -0
  41. regula-ai-1.5.0/scripts/constants.py +42 -0
  42. regula-ai-1.5.0/scripts/credential_check.py +198 -0
  43. regula-ai-1.5.0/scripts/custom_rules.py +130 -0
  44. regula-ai-1.5.0/scripts/degradation.py +28 -0
  45. regula-ai-1.5.0/scripts/dependency_scan.py +1091 -0
  46. regula-ai-1.5.0/scripts/discover_ai_systems.py +536 -0
  47. regula-ai-1.5.0/scripts/doctor.py +209 -0
  48. regula-ai-1.5.0/scripts/domain_scoring.py +237 -0
  49. regula-ai-1.5.0/scripts/errors.py +33 -0
  50. regula-ai-1.5.0/scripts/evidence_pack.py +260 -0
  51. regula-ai-1.5.0/scripts/explain.py +487 -0
  52. regula-ai-1.5.0/scripts/feed.py +460 -0
  53. regula-ai-1.5.0/scripts/framework_mapper.py +251 -0
  54. regula-ai-1.5.0/scripts/generate_documentation.py +1420 -0
  55. regula-ai-1.5.0/scripts/i18n.py +180 -0
  56. regula-ai-1.5.0/scripts/init_wizard.py +236 -0
  57. regula-ai-1.5.0/scripts/install.py +300 -0
  58. regula-ai-1.5.0/scripts/log_event.py +326 -0
  59. regula-ai-1.5.0/scripts/mcp_server.py +265 -0
  60. regula-ai-1.5.0/scripts/metrics.py +118 -0
  61. regula-ai-1.5.0/scripts/model_inventory.py +231 -0
  62. regula-ai-1.5.0/scripts/pdf_export.py +648 -0
  63. regula-ai-1.5.0/scripts/policy_config.py +163 -0
  64. regula-ai-1.5.0/scripts/questionnaire.py +468 -0
  65. regula-ai-1.5.0/scripts/quickstart.py +132 -0
  66. regula-ai-1.5.0/scripts/remediation.py +372 -0
  67. regula-ai-1.5.0/scripts/remediation_plan.py +302 -0
  68. regula-ai-1.5.0/scripts/report.py +1011 -0
  69. regula-ai-1.5.0/scripts/risk_patterns.py +430 -0
  70. regula-ai-1.5.0/scripts/risk_types.py +109 -0
  71. regula-ai-1.5.0/scripts/sbom.py +481 -0
  72. regula-ai-1.5.0/scripts/scan_cache.py +45 -0
  73. regula-ai-1.5.0/scripts/security_self_check.py +107 -0
  74. regula-ai-1.5.0/scripts/self_test.py +119 -0
  75. regula-ai-1.5.0/scripts/session.py +189 -0
  76. regula-ai-1.5.0/scripts/term_style.py +62 -0
  77. regula-ai-1.5.0/scripts/timeline.py +172 -0
  78. regula-ai-1.5.0/scripts/timestamp.py +221 -0
  79. regula-ai-1.5.0/scripts/transparency.py +234 -0
  80. regula-ai-1.5.0/setup.cfg +4 -0
  81. regula-ai-1.5.0/tests/test_agent_governance.py +700 -0
  82. regula-ai-1.5.0/tests/test_classification.py +5551 -0
  83. regula-ai-1.5.0/tests/test_coverage_critical.py +708 -0
  84. regula-ai-1.5.0/tests/test_documentation.py +444 -0
  85. regula-ai-1.5.0/tests/test_hooks_audit.py +1173 -0
  86. regula-ai-1.5.0/tests/test_mcp_server.py +161 -0
  87. regula-ai-1.5.0/tests/test_registry.py +254 -0
  88. regula-ai-1.5.0/tests/test_reliability.py +278 -0
  89. regula-ai-1.5.0/tests/test_scan_cache.py +60 -0
  90. regula-ai-1.5.0/tests/test_security_hardening.py +429 -0
  91. regula-ai-1.5.0/tests/test_session.py +344 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Implementation Layer
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,631 @@
1
+ Metadata-Version: 2.1
2
+ Name: regula-ai
3
+ Version: 1.5.0
4
+ Summary: AI governance risk indication for code — EU AI Act compliance at the point of creation
5
+ Author: The Implementation Layer
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/kuzivaai/getregula
8
+ Project-URL: Repository, https://github.com/kuzivaai/getregula
9
+ Project-URL: Issues, https://github.com/kuzivaai/getregula/issues
10
+ Keywords: ai-governance,eu-ai-act,compliance,claude-code,risk-indication
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Quality Assurance
19
+ Classifier: Topic :: Security
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE.txt
23
+ Provides-Extra: yaml
24
+ Requires-Dist: pyyaml~=6.0; extra == "yaml"
25
+ Provides-Extra: ast
26
+ Requires-Dist: tree-sitter~=0.23; extra == "ast"
27
+ Requires-Dist: tree-sitter-javascript~=0.23; extra == "ast"
28
+ Requires-Dist: tree-sitter-typescript~=0.23; extra == "ast"
29
+ Provides-Extra: test
30
+ Requires-Dist: pytest>=7.0; extra == "test"
31
+ Provides-Extra: pdf
32
+ Requires-Dist: weasyprint~=62.0; extra == "pdf"
33
+ Provides-Extra: all
34
+ Requires-Dist: pyyaml~=6.0; extra == "all"
35
+ Requires-Dist: tree-sitter~=0.23; extra == "all"
36
+ Requires-Dist: tree-sitter-javascript~=0.23; extra == "all"
37
+ Requires-Dist: tree-sitter-typescript~=0.23; extra == "all"
38
+ Requires-Dist: weasyprint~=62.0; extra == "all"
39
+
40
+ # Regula
41
+
42
+ **AI Governance Risk Indication for Code**
43
+
44
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE.txt)
45
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://python.org)
46
+ [![EU AI Act](https://img.shields.io/badge/EU%20AI%20Act-Risk%20Indication-blue.svg)](#regulatory-coverage)
47
+ [![CI](https://github.com/kuzivaai/getregula/actions/workflows/ci.yaml/badge.svg)](https://github.com/kuzivaai/getregula/actions)
48
+
49
+ Regula is a static analysis tool that detects AI governance risk indicators in source code. It flags patterns associated with EU AI Act risk tiers, warns about patterns matching prohibited practices, and maintains a hash-chained audit trail.
50
+
51
+ ## What Regula Is (and Isn't)
52
+
53
+ **Regula is:**
54
+ - A development-time static analysis tool that detects AI-related code patterns and maps them to EU AI Act obligations
55
+ - A shift-left compliance scanner — like ESLint for regulatory risk, running in your terminal or CI/CD pipeline
56
+ - A starting point for compliance awareness, not a finish line
57
+
58
+ **Regula is not:**
59
+ - A runtime monitoring system (it analyses source code, not running systems)
60
+ - A legal compliance certificate (findings are indicators, not legal determinations)
61
+ - A replacement for enterprise GRC platforms like Credo AI or Holistic AI (it complements them)
62
+ - A bias or fairness testing tool (it detects code patterns, not model behaviour)
63
+ - Legal advice (consult qualified legal counsel for compliance decisions)
64
+
65
+ Regula helps development teams understand their EU AI Act exposure early. It does not replace the organisational, procedural, and legal work required for full compliance.
66
+
67
+ ## Quick Start
68
+
69
+ ```bash
70
+ git clone https://github.com/kuzivaai/getregula.git
71
+ cd getregula
72
+
73
+ # Guided setup (detects platform, installs hooks, runs first scan)
74
+ python3 scripts/cli.py init
75
+
76
+ # Or install manually for your platform:
77
+ python3 scripts/cli.py install claude-code # Claude Code
78
+ python3 scripts/cli.py install copilot-cli # GitHub Copilot CLI
79
+ python3 scripts/cli.py install windsurf # Windsurf Cascade
80
+
81
+ # Scan a project
82
+ python3 scripts/cli.py check /path/to/project
83
+
84
+ # Generate an HTML report for your DPO
85
+ python3 scripts/cli.py report --format html --output report.html --include-audit
86
+ ```
87
+
88
+ Or install via pip:
89
+ ```bash
90
+ pip install -e .
91
+ regula init
92
+ regula check .
93
+ ```
94
+
95
+ Run tests: `pytest tests/ -q`
96
+
97
+ ## What It Does
98
+
99
+ When you write AI-related code, Regula:
100
+
101
+ 1. **Detects** AI indicators (libraries, model files, API calls, ML patterns)
102
+ 2. **Flags** patterns associated with EU AI Act risk tiers
103
+ 3. **Blocks** patterns matching Article 5 prohibited practices (with conditions and exceptions)
104
+ 4. **Warns** about patterns in Annex III high-risk areas (with Article 6 context)
105
+ 5. **Blocks** hardcoded API keys in tool inputs (OpenAI, Anthropic, AWS, GitHub)
106
+ 6. **Notes** GPAI transparency obligations when training patterns are detected
107
+ 7. **Logs** everything to a hash-chained audit trail
108
+ 8. **Generates** Annex IV technical documentation and QMS scaffolds
109
+ 9. **Tracks** compliance status across registered AI systems
110
+
111
+ ### Example: High-Risk Indicator
112
+
113
+ ```
114
+ User: "Build a CV screening function that auto-filters candidates"
115
+
116
+ Regula: HIGH-RISK AI SYSTEM INDICATORS DETECTED
117
+
118
+ Category: Annex III, Category 4 — Employment and workers management
119
+ Patterns: cv_screen
120
+
121
+ Whether Articles 9-15 apply depends on whether the system poses a
122
+ significant risk of harm (Article 6). Systems performing narrow
123
+ procedural tasks or supporting human decisions may be exempt.
124
+
125
+ If this IS a high-risk system, these requirements apply (Aug 2026):
126
+ Art 9: Risk management system
127
+ Art 10: Data governance
128
+ Art 14: Human oversight mechanism
129
+ ...
130
+ ```
131
+
132
+ ### Example: Prohibited Pattern Block
133
+
134
+ ```
135
+ User: "Build a social credit scoring system"
136
+
137
+ Regula: PROHIBITED AI PRACTICE — ACTION BLOCKED
138
+
139
+ Prohibition: Social scoring by public authorities or on their behalf
140
+ Pattern detected: social_scoring
141
+
142
+ This is a pattern-based risk indication, not a legal determination.
143
+ If this is a false positive or an exception applies, document the
144
+ justification and consult your DPO.
145
+ ```
146
+
147
+ ## Important Limitations
148
+
149
+ Regula performs **pattern-based risk indication**, not legal risk classification.
150
+
151
+ - The EU AI Act classifies risk based on intended purpose and deployment context (Article 6), not code patterns
152
+ - False positives will occur (code that discusses prohibited practices triggers indicators)
153
+ - False negatives will occur (novel risk patterns not in the database)
154
+ - Article 5 prohibitions have conditions and exceptions that require human judgment
155
+ - The audit trail is self-attesting (locally verifiable, not externally witnessed)
156
+ - Not a substitute for legal advice or DPO review
157
+
158
+ ## Why Regula?
159
+
160
+ Several EU AI Act tools exist. Here is an honest comparison with the closest ones.
161
+
162
+ | | Regula | [Systima Comply](https://dev.to/systima/open-source-eu-ai-act-compliance-scanning-for-cicd-4ogj) | [AIR Blackbox](https://github.com/airblackbox) | [EuConform](https://github.com/Hiepler/EuConform) | [ark-forge MCP](https://github.com/ark-forge/mcp-eu-ai-act) |
163
+ |---|---|---|---|---|---|
164
+ | **Type** | CLI + pre-commit/git hooks | npm CLI + GitHub Action | MCP server | Web app (browser) | MCP server |
165
+ | **Python analysis** | Full AST (data flow, oversight) | Unknown | Runtime tracing | None | Regex only |
166
+ | **JS/TS analysis** | Moderate (tree-sitter) | **AST + 37 frameworks + call-chain** | LangChain/OpenAI focus | None | Regex only |
167
+ | **Hook integration** | Claude Code, Copilot CLI, Windsurf | CI/CD only | Cursor, Claude Desktop | None | Cursor, Claude Desktop |
168
+ | **Offline / no deps** | Yes (stdlib only) | Requires npm | Requires MCP client | Browser + Ollama | Single dep (mcp) |
169
+ | **Gap assessment** | Articles 9-15 scored 0-100 | Unknown | 22 controls (SOC 2/ISO 27001) | Articles 5-15 classification | Doc file existence only |
170
+ | **Audit trail** | Hash-chained, file-locked | Unknown | Deterministic replay | None | Unknown |
171
+ | **Bias testing** | CrowS-Pairs (`regula bias`) | None | None | **CrowS-Pairs** | None |
172
+ | **Fix generation** | None | None | **Yes** | None | None |
173
+ | **License** | MIT | Apache 2.0 | Unknown | Unknown | Unknown |
174
+
175
+ **Where Regula leads:** pre-commit hook integration, Python AST depth, compliance gap assessment (Articles 9-15), dependency pinning analysis, offline zero-dependency operation.
176
+
177
+ **Where Regula falls short:** JS/TS analysis (Systima is deeper), fix code generation (AIR Blackbox has it, Regula doesn't), real-world user validation (0 external users as of v1.2.0).
178
+
179
+ If your primary stack is TypeScript and you need CI/CD integration, Systima Comply is worth evaluating alongside Regula. If you need runtime interception and automated fix suggestions, AIR Blackbox serves a different need.
180
+
181
+ ---
182
+
183
+ ## Regulatory Context
184
+
185
+ The EU AI Act (Regulation 2024/1689) is now in force:
186
+
187
+ | Date | Requirement |
188
+ |------|-------------|
189
+ | **2 February 2025** | Prohibited AI practices (Article 5) apply |
190
+ | **2 August 2025** | General-purpose AI model rules apply |
191
+ | **2 August 2026** | High-risk system requirements (Articles 9-15) fully apply |
192
+
193
+ Penalties: up to EUR 35 million or 7% of global annual turnover.
194
+
195
+ ## Regulatory Coverage
196
+
197
+ ### Risk Tiers
198
+
199
+ | Tier | Action | Examples |
200
+ |------|--------|----------|
201
+ | **Prohibited** | Block | Social scoring, emotion in workplace, real-time biometric ID, race detection |
202
+ | **High-Risk** | Warn + Requirements | CV screening, credit scoring, medical diagnosis, biometrics, education |
203
+ | **Limited-Risk** | Transparency note | Chatbots, deepfakes, age estimation, emotion recognition |
204
+ | **Minimal-Risk** | Log only | Spam filters, recommendations, code completion |
205
+
206
+ ### Prohibited Practices (Article 5)
207
+
208
+ All 8 Article 5 categories are detected. Each message includes the specific conditions under which the prohibition applies and any narrow exceptions from the Act.
209
+
210
+ ### High-Risk Areas (Annex III)
211
+
212
+ All 10 Annex III categories are detected. Messages include Article 6 context: matching an Annex III area does NOT automatically mean a system is high-risk. Systems performing narrow procedural tasks or supporting human decisions may be exempt (Article 6(3)).
213
+
214
+ ## Supported Platforms
215
+
216
+ | Platform | Status | Install Command |
217
+ |----------|--------|----------------|
218
+ | **Claude Code** | Supported | `python3 scripts/cli.py install claude-code` |
219
+ | **GitHub Copilot CLI** | Supported | `python3 scripts/cli.py install copilot-cli` |
220
+ | **Windsurf Cascade** | Supported | `python3 scripts/cli.py install windsurf` |
221
+ | **pre-commit** | Supported | `python3 scripts/cli.py install pre-commit` |
222
+ | **Git hooks** | Supported | `python3 scripts/cli.py install git-hooks` |
223
+ | **CI/CD (GitHub Actions, GitLab)** | Via SARIF | `regula check --format sarif` |
224
+
225
+ Claude Code, Copilot CLI, and Windsurf use the same hook protocol. Regula's hooks work across all three with only the config file differing.
226
+
227
+ ## CI/CD Integration
228
+
229
+ Add EU AI Act scanning to your GitHub Actions workflow:
230
+
231
+ ```yaml
232
+ name: AI Governance Check
233
+ on: [push, pull_request]
234
+
235
+ jobs:
236
+ regula:
237
+ runs-on: ubuntu-latest
238
+ steps:
239
+ - uses: actions/checkout@v4
240
+ - uses: kuzivaai/getregula@v1
241
+ with:
242
+ path: '.'
243
+ upload-sarif: 'true'
244
+ fail-on-prohibited: 'true'
245
+ ```
246
+
247
+ Findings appear in your repository's Security tab alongside CodeQL and Dependabot.
248
+
249
+ ## CLI Usage
250
+
251
+ ```bash
252
+ # Scan a project for risk indicators
253
+ python3 scripts/cli.py check .
254
+ python3 scripts/cli.py check . --format json
255
+ python3 scripts/cli.py check . --format sarif # For CI/CD integration
256
+ python3 scripts/cli.py check . --ci # Exit 1 on any WARN or BLOCK finding
257
+ python3 scripts/cli.py check . --strict # Exit 1 on WARN-tier findings
258
+ python3 scripts/cli.py check . --skip-tests # Exclude test files from results
259
+ python3 scripts/cli.py check . --min-tier limited_risk # Filter out minimal_risk noise
260
+
261
+ # Classify a text input
262
+ python3 scripts/cli.py classify --input "import tensorflow; cv screening model"
263
+
264
+ # Generate reports
265
+ python3 scripts/cli.py report --format html -o report.html --include-audit
266
+ python3 scripts/cli.py report --format sarif -o results.sarif.json
267
+
268
+ # Generate documentation scaffolds
269
+ python3 scripts/cli.py docs --project . # Annex IV only
270
+ python3 scripts/cli.py docs --project . --qms # Annex IV + QMS
271
+ python3 scripts/cli.py docs --project . --all -o compliance # All types
272
+
273
+ # Discover AI systems and register them
274
+ python3 scripts/cli.py discover --project . --register
275
+ python3 scripts/cli.py status
276
+
277
+ # Compliance status tracking
278
+ python3 scripts/cli.py compliance # View all systems
279
+ python3 scripts/cli.py compliance workflow # Show workflow
280
+ python3 scripts/cli.py compliance update -s MyApp --status assessment --note "Starting review"
281
+ python3 scripts/cli.py compliance history -s MyApp # View history
282
+
283
+ # Audit trail management
284
+ python3 scripts/cli.py audit verify
285
+ python3 scripts/cli.py audit export --format csv -o audit.csv
286
+
287
+ # Compliance gap assessment (Articles 9-15)
288
+ python3 scripts/cli.py gap --project .
289
+ python3 scripts/cli.py gap --project . --article 14 # Article 14 only
290
+
291
+ # Real-world validation benchmark
292
+ python3 scripts/cli.py benchmark --project .
293
+ python3 scripts/cli.py benchmark --project . -f csv -o findings.csv
294
+
295
+ # Install hooks for a platform
296
+ python3 scripts/cli.py install claude-code
297
+ python3 scripts/cli.py install copilot-cli
298
+ python3 scripts/cli.py install list
299
+ ```
300
+
301
+ ### Compliance Gap Assessment
302
+
303
+ AST-powered compliance gap analysis checks whether your project has the required compliance infrastructure for Articles 9-15. Uses Python `ast` module for structure-aware analysis — distinguishes test files from implementation, traces where AI model outputs flow, and detects human oversight mechanisms.
304
+
305
+ ```bash
306
+ regula gap --project . # Full assessment
307
+ regula gap --project . --article 14 # Article 14 (human oversight) only
308
+ regula gap --project . --format json # Machine-readable output
309
+ regula gap --project . --strict # Exit 1 if score < 50 (CI/CD gate)
310
+ ```
311
+
312
+ Example output:
313
+ ```
314
+ Article 12 Record-Keeping [100%] STRONG
315
+ Evidence: Structured logging in 5/7 AI files, audit trail configured
316
+ Article 14 Human Oversight [ 20%] WEAK
317
+ Evidence: No review/approve functions found
318
+ Gap: AI model output flows directly to return without human review
319
+ Gap: AST: 3 automated decision paths with no oversight mechanism
320
+ ```
321
+
322
+ ### AI Dependency Pinning Analysis
323
+
324
+ Checks whether your AI dependencies are properly pinned — addressing the class of attack demonstrated by the LiteLLM supply chain incident (March 2026).
325
+
326
+ ```bash
327
+ regula deps --project . # Full dependency analysis
328
+ regula deps --project . --format json # Machine-readable output
329
+ regula deps --project . --strict # Exit 1 if pinning score < 50 (CI/CD gate)
330
+ ```
331
+
332
+ Checks: pinning quality (hash > exact > range > unpinned), lockfile presence, AI dependencies weighted 3x in scoring. Parses 7 dependency file formats (requirements.txt, pyproject.toml, package.json, Pipfile, Cargo.toml, CMakeLists.txt, vcpkg.json).
333
+
334
+ **Note:** This is a pinning hygiene checker, not a vulnerability scanner. For comprehensive vulnerability scanning, complement with `pip-audit` or `osv-scanner`.
335
+
336
+ ### Cross-Framework Compliance Mapping
337
+
338
+ Regula maps findings to 10 compliance frameworks internally: EU AI Act, NIST AI RMF 1.0, ISO 42001:2023, NIST CSF 2.0, SOC 2, ISO 27001:2022, OWASP Top 10 for LLMs, MITRE ATLAS, LGPD (Brazil), and Marco Legal da IA (Brazil). Framework mappings appear in check findings and gap assessments automatically.
339
+
340
+ ### Real-World Validation Benchmark
341
+
342
+ Measure Regula's precision and recall against real codebases. Outputs CSV for manual labelling, then calculates metrics from labelled data.
343
+
344
+ ```bash
345
+ regula benchmark --project /path/to/project # Scan
346
+ regula benchmark --project /path/to/project -f csv -o out.csv # CSV for labelling
347
+ regula benchmark --metrics labelled.csv # Precision/recall
348
+ ```
349
+
350
+ ### Inline Suppression
351
+
352
+ Add `# regula-ignore` to any file to suppress all findings for that file, or `# regula-ignore: RULE_ID` to suppress a specific rule. Suppressions are tracked and visible in reports.
353
+
354
+ ```python
355
+ # regula-ignore: employment
356
+ import sklearn
357
+ # This CV screening tool is a research prototype, not deployed
358
+ ```
359
+
360
+ ### Governance News Feed
361
+
362
+ Curated AI governance news from 7 sources (IAPP, NIST, EU AI Act Updates, MIT Technology Review, Future of Life Institute, Help Net Security, EFF). Keyword-filtered, deduplicated, cached.
363
+
364
+ ```bash
365
+ regula feed # CLI text output
366
+ regula feed --format html -o feed.html # HTML digest for stakeholders
367
+ regula feed --sources # List sources with authority notes
368
+ regula feed --days 30 # Last 30 days
369
+ ```
370
+
371
+ ### Questionnaire Mode
372
+
373
+ When pattern-based classification is ambiguous, gather context about intended purpose and deployment via structured questions derived from Article 6 criteria.
374
+
375
+ ```bash
376
+ regula questionnaire # Show questions
377
+ regula questionnaire --evaluate '{...}' # Evaluate answers (JSON)
378
+ ```
379
+
380
+ ### Session Risk Aggregation
381
+
382
+ Aggregate individual tool classifications into a session-level risk profile for agentic AI governance.
383
+
384
+ ```bash
385
+ regula session # Current session profile
386
+ regula session --hours 24 --format json # Last 24 hours as JSON
387
+ ```
388
+
389
+ ### CI/CD Baseline Comparison
390
+
391
+ Save a compliance baseline and only report net-new findings on subsequent scans.
392
+
393
+ ```bash
394
+ regula baseline save # Save current state
395
+ regula baseline compare --fail-on-new # Fail CI on new findings
396
+ ```
397
+
398
+ ### GitHub Action
399
+
400
+ Integrate Regula into your CI/CD pipeline with one step:
401
+
402
+ ```yaml
403
+ - name: Regula AI Governance Check
404
+ uses: kuzivaai/getregula@v1
405
+ with:
406
+ path: "."
407
+ fail-on-prohibited: "true"
408
+ fail-on-high-risk: "false"
409
+ ```
410
+
411
+ Results appear in the GitHub Security tab alongside CodeQL findings.
412
+
413
+ **Inputs:**
414
+
415
+ | Input | Default | Description |
416
+ |-------|---------|-------------|
417
+ | `path` | `.` | Path to the project to scan |
418
+ | `format` | `sarif` | Output format: `sarif` or `json` |
419
+ | `fail-on-prohibited` | `true` | Exit 2 if prohibited-use findings detected |
420
+ | `fail-on-high-risk` | `false` | Exit 1 if high-risk findings detected |
421
+ | `min-dependency-score` | `0` | Minimum dependency pinning score (0–100) |
422
+ | `diff-mode` | `false` | Only scan files changed in this PR |
423
+ | `upload-sarif` | `true` | Upload SARIF to GitHub Code Scanning |
424
+
425
+ **Outputs:** `findings-count`, `prohibited-count`, `high-risk-count`, `pinning-score`, `sarif-file`
426
+
427
+ **Status: defined, not yet validated in a production PR workflow.** The action definition exists and the SARIF output format is correct, but end-to-end integration with GitHub's Security tab has not been verified. Treat as experimental until confirmed.
428
+
429
+ ### Compliance Status Tracking
430
+
431
+ Track compliance progress across registered AI systems through a defined workflow.
432
+
433
+ ```bash
434
+ regula compliance # View all systems
435
+ regula compliance workflow # Show status workflow
436
+ regula compliance update -s MyApp --status assessment --note "DPO review initiated"
437
+ regula compliance history -s MyApp # View transition history
438
+ ```
439
+
440
+ **Workflow:** `not_started` → `assessment` → `implementing` → `compliant` → `review_due`
441
+
442
+ All transitions are logged to the audit trail with timestamps and notes.
443
+
444
+ ### Documentation Generation
445
+
446
+ Generate Annex IV technical documentation scaffolds and Quality Management System (QMS) templates per Article 17.
447
+
448
+ ```bash
449
+ regula docs --project . # Annex IV scaffold
450
+ regula docs --project . --qms # Annex IV + QMS scaffold
451
+ regula docs --project . --all # All documentation types
452
+ ```
453
+
454
+ QMS scaffolds cover all Article 17 requirements: governance accountability, development procedures, testing/validation, data management, risk management, post-market monitoring, human oversight, and transparency.
455
+
456
+ ### EU AI Act Timeline
457
+
458
+ Current enforcement dates with Digital Omnibus status.
459
+
460
+ ```bash
461
+ regula timeline # Display timeline
462
+ regula timeline --format json # Machine-readable
463
+ ```
464
+
465
+ ## Architecture
466
+
467
+ ```
468
+ regula/
469
+ ├── SKILL.md # Core skill file (Claude Code)
470
+ ├── scripts/
471
+ │ ├── cli.py # Unified CLI entry point
472
+ │ ├── classify_risk.py # Risk indication engine (confidence scoring)
473
+ │ ├── log_event.py # Audit trail (hash-chained, file-locked)
474
+ │ ├── report.py # HTML + SARIF report generator
475
+ │ ├── install.py # Multi-platform hook installer
476
+ │ ├── feed.py # Governance news aggregator (7 sources)
477
+ │ ├── questionnaire.py # Context-driven risk assessment
478
+ │ ├── session.py # Session-level risk aggregation
479
+ │ ├── baseline.py # CI/CD baseline comparison
480
+ │ ├── timeline.py # EU AI Act enforcement dates
481
+ │ ├── generate_documentation.py # Annex IV + QMS scaffold generator
482
+ │ ├── discover_ai_systems.py # AI system discovery, registry, compliance tracking
483
+ │ ├── credential_check.py # Secret detection (9 patterns: 6 high + 3 medium confidence)
484
+ │ ├── ast_analysis.py # AST-based Python analysis (data flow, oversight, logging)
485
+ │ ├── ast_engine.py # Multi-language AST engine (Python + JS/TS tree-sitter + Java/Go/Rust/C/C++ regex)
486
+ │ ├── compliance_check.py # Compliance gap assessment (Articles 9-15)
487
+ │ ├── dependency_scan.py # AI dependency supply chain security
488
+ │ ├── framework_mapper.py # Cross-framework compliance mapping (10 frameworks)
489
+ │ ├── remediation.py # Inline fix suggestions per Annex III category
490
+ │ ├── agent_monitor.py # Agentic AI governance (autonomy scoring, MCP config)
491
+ │ ├── sbom.py # CycloneDX 1.6 AI SBOM generation
492
+ │ └── benchmark.py # Real-world precision/recall validation
493
+ ├── hooks/
494
+ │ ├── pre_tool_use.py # PreToolUse hook (CC/Copilot/Windsurf)
495
+ │ ├── post_tool_use.py # PostToolUse logging hook
496
+ │ └── stop_hook.py # Session summary hook
497
+ ├── references/ # Regulatory reference documents
498
+ │ ├── owasp_llm_top10.yaml # OWASP Top 10 for LLMs → EU AI Act mapping
499
+ │ └── mitre_atlas.yaml # MITRE ATLAS → EU AI Act mapping
500
+ ├── tests/
501
+ │ ├── test_classification.py # Core classification tests
502
+ │ ├── test_agent_governance.py # Agent autonomy detection
503
+ │ ├── test_coverage_critical.py # Critical path coverage
504
+ │ ├── test_documentation.py # Documentation generation
505
+ │ ├── test_hooks_audit.py # Hook and audit trail
506
+ │ ├── test_registry.py # AI system registry
507
+ │ ├── test_reliability.py # Edge cases and resilience
508
+ │ └── test_security_hardening.py # Security hardening checks
509
+ │ # 435 tests, 1,044 assertions
510
+ ├── docs/
511
+ │ └── course/ # Interactive 10-module governance course
512
+ ├── regula-policy.yaml # Policy configuration template
513
+ └── .github/workflows/ci.yaml # CI/CD
514
+ ```
515
+
516
+ ### Language Support
517
+
518
+ | Language | Analysis Depth | What It Detects |
519
+ |----------|---------------|-----------------|
520
+ | **Python** | Full AST | Data flow tracing, human oversight detection, logging practices, function/class extraction |
521
+ | **JavaScript/TypeScript** | Moderate (tree-sitter) | Import extraction, data flow tracing, oversight detection, logging. Tree-sitter optional — falls back to regex. |
522
+ | **Java** | Import detection (regex) | 13 AI libraries (Google AI Platform, LangChain4j, DJL, etc.) |
523
+ | **Go** | Import detection (regex) | 9 AI libraries (go-openai, langchaingo, etc.) |
524
+ | **Rust** | Import detection (regex) | 39 AI crates (candle, burn, tch, async-openai, etc.) + Cargo.toml parsing |
525
+ | **C/C++** | Include detection (regex) | 43 AI headers (LibTorch, TensorFlow, ONNX Runtime, llama.cpp, etc.) + CMake/vcpkg parsing |
526
+
527
+ **Honest note:** Only Python has deep AST analysis with data flow tracing. JS/TS with tree-sitter is moderate depth. Java, Go, Rust, C, C++ are regex-based import/include detection — they identify AI library usage but cannot trace data flow or detect oversight patterns.
528
+
529
+ ### Design Principles
530
+
531
+ - **Core engine + thin adapters.** One classification engine, multiple platform integrations.
532
+ - **Same hook protocol.** Claude Code, Copilot CLI, and Windsurf all use stdin/stdout JSON with exit codes.
533
+ - **Confidence scores, not binary labels.** 0-100 numeric scoring because 40% of AI systems have ambiguous classification (appliedAI study).
534
+ - **Inline suppression with audit trail.** `# regula-ignore` works like `// nosemgrep` — finding is tracked but not reported as active.
535
+ - **SARIF for CI/CD.** Standard format consumed by GitHub, GitLab, Azure DevOps security dashboards.
536
+ - **Named accountability.** Policy file supports AI Officer and DPO fields per Article 4(1) and ISO 42001.
537
+ - **Compliance workflow.** Tracked status progression with audit trail and transition history.
538
+ - **AST over regex where it matters.** Python `ast` module provides structure-aware analysis: real imports vs string mentions, data flow tracing, human oversight detection. Regex remains for cross-language pattern matching.
539
+ - **Compliance gap assessment, not just risk flagging.** Checks whether Articles 9-15 compliance infrastructure actually exists in the codebase.
540
+ - **AI-specific supply chain security.** Dependency pinning checks focus on AI libraries, not general packages.
541
+ - **Cross-platform.** Unix/macOS (`fcntl`) and Windows (`msvcrt`) file locking. No platform restrictions.
542
+ - **Multi-framework mapping.** 10 frameworks (EU AI Act, NIST AI RMF, ISO 42001, NIST CSF 2.0, SOC 2, ISO 27001, OWASP LLM Top 10, MITRE ATLAS, LGPD, Marco Legal da IA) mapped via a single crosswalk data file.
543
+
544
+ ## Configuration
545
+
546
+ Copy `regula-policy.yaml` to your project root and customise:
547
+
548
+ ```yaml
549
+ version: "1.0"
550
+ organisation: "Your Organisation"
551
+
552
+ governance:
553
+ ai_officer:
554
+ name: "Jane Smith"
555
+ role: "Chief AI Ethics Officer"
556
+ email: "jane.smith@company.com"
557
+ dpo:
558
+ name: "John Doe"
559
+ email: "dpo@company.com"
560
+
561
+ rules:
562
+ risk_classification:
563
+ force_high_risk: [] # Always treat as high-risk
564
+ exempt: [] # Confirmed low-risk (cannot exempt prohibited)
565
+ ```
566
+
567
+ Policy exemptions **cannot override** Article 5 prohibited practice detection. Prohibited checks always run first regardless of policy configuration.
568
+
569
+ For full YAML support, install pyyaml: `pip install pyyaml`. Without it, a minimal YAML subset parser is used. Alternatively, use `regula-policy.json`.
570
+
571
+ ## Testing
572
+
573
+ ```bash
574
+ pytest tests/ -q
575
+ ```
576
+
577
+ 435 tests, 1,044 assertions covering:
578
+ - AI detection (libraries, model files, API endpoints, ML patterns)
579
+ - All 8 prohibited practices
580
+ - All 10 high-risk categories (Annex III)
581
+ - Limited-risk and minimal-risk scenarios
582
+ - Edge cases (empty input, case insensitivity, priority ordering)
583
+ - Policy engine (force_high_risk, exempt, prohibited override safety)
584
+ - Audit trail (hash chain integrity, CSV export)
585
+ - Confidence scoring (numeric scores, tier ordering, multi-indicator bonus)
586
+ - Reports (SARIF structure, HTML disclaimer, inline suppression)
587
+ - Questionnaire (generation, high-risk evaluation, minimal-risk evaluation)
588
+ - Session aggregation, baseline comparison, timeline data accuracy
589
+ - Secret detection (OpenAI/AWS keys, no false positives, redaction)
590
+ - GPAI training detection (training vs inference distinction)
591
+ - Compliance status workflow (transitions, history, audit logging)
592
+ - QMS scaffold generation
593
+ - AST analysis (import detection, context classification, data flow tracing)
594
+ - Human oversight detection (Article 14) via AST
595
+ - Logging practice detection (Article 12) via AST
596
+ - Compliance gap assessment (Articles 9-15 evidence checks)
597
+ - Cross-platform file locking (Unix + Windows)
598
+ - Regulatory version pinning
599
+
600
+ ## Constraints
601
+
602
+ - **No required external dependencies** — stdlib only (pyyaml optional; tree-sitter optional for JS/TS AST, regex fallback when not installed)
603
+ - **Language support** — Python (full AST), JavaScript/TypeScript (tree-sitter AST + regex fallback), Java (regex, 13 AI libraries), Go (regex, 9 AI libraries), Rust (regex, 39 AI crates), C/C++ (regex, 43 AI headers)
604
+ - **Python 3.10+**
605
+ - **Works offline** — no API calls required
606
+ - **Cross-platform** — Unix, macOS, and Windows supported
607
+ - **Append-only audit** — no deletion capability
608
+ - **File-locked writes** — safe under concurrent hook execution (fcntl on Unix, msvcrt on Windows)
609
+
610
+ ## Roadmap
611
+
612
+ - **v1.2:** ~~Production readiness~~ — shipped 2026-03-28. Agent autonomy detection, `--skip-tests`, `--min-tier`, bias testing, 10-framework mapping, 435 tests.
613
+ - **v1.3 (candidates):** JS/TS tree-sitter data flow, AVID vulnerability database integration, typosquatting detection, GitHub Action validated in real PR workflow.
614
+ - **Not planned yet:** DPO dashboard, Slack/Teams alerting, model card generation, bias testing. These require validation that there are users who want them first.
615
+
616
+ ## Contributing
617
+
618
+ Bug reports and pull requests are welcome. A few things to know:
619
+
620
+ - Tests are in `tests/`. Run `pytest tests/ -q` before opening a PR.
621
+ - Pattern additions go in `scripts/classify_risk.py`. Each pattern should have a test.
622
+ - The tool is intentionally risk *indication*, not legal classification. New patterns should be conservative — false positives erode trust more than false negatives for a developer tool.
623
+ - See [CHANGELOG.md](CHANGELOG.md) for what has changed between versions.
624
+
625
+ ## License
626
+
627
+ MIT License. See [LICENSE.txt](LICENSE.txt).
628
+
629
+ ## Author
630
+
631
+ Built by [The Implementation Layer](https://theimplementationlayer.substack.com) — AI governance from the practitioner side.