Hierarchical static analysis engine that captures tribal knowledge, enforces business logic, and prevents AI-generated code violations using AST analysis.
Project description
๐ก๏ธ Astrict
Your team's memory, automated.
Astrict is a hierarchical static analysis engine that captures tribal knowledge, enforces business logic, and prevents AI-generated code violations using AST analysis.
Unlike traditional linters that focus on syntax, Astrict encodes your team's hard-won lessons: the outage that happened at 3 AM, the architectural decision from Q3 planning, the performance bottleneck that cost $50K.
Every rule has an author. Every violation explains the history. Every enforcement teaches the team.
Why Astrict?
Most production failures aren't caused by invalid syntax โ they're caused by valid code that should never have been allowed:
- ๐ฐ Floating-point arithmetic used for money (AI tools love generating this)
- ๐ Secrets hardcoded into source code
- โฑ๏ธ HTTP requests without timeouts (caused a $50K outage)
- ๐๏ธ Architectural rules enforced only by convention
These rules are documented informally and enforced inconsistently. Astrict makes them explicit, enforceable, and non-ignorable.
Key Features
๐๏ธ Hierarchical Authority
Rules are organized by who wrote them and how critical they are:
| Layer | Owner | Enforcement | Example |
|---|---|---|---|
| GLOBAL | Security Team | ๐ซ BLOCK | No hardcoded secrets |
| TEAM | Tech Lead | โ ๏ธ WARN | No requests without timeout |
| PERSONAL | Developer | ๐ก NUDGE | Remind me to write tests |
Higher authority always wins. Lower layers can never override higher mandates.
๐ง Tribal Knowledge Capture
Every rule carries its story:
- Author: Who wrote this rule (accountability)
- Rationale: Why it exists (learning)
- Incident: What outage caused it (prevention)
- Decision PR: What team discussion led to it (context)
๐ค AI Code Safety
Catches common mistakes in AI-generated code:
- Float for money โ Use Decimal
console.logwith passwords โ Use proper logger- SQL string concatenation โ Use parameterized queries
- Missing timeouts โ Always specify
๐ Multi-Language
Python (full), JavaScript/TypeScript (partial), Go/Java (basic). Severity is capped by detection confidence โ Astrict never blocks a build on uncertain detection.
โก AST-Based Detection
Uses Tree-sitter for semantic analysis, not fragile regex. Deterministic, explainable, and fast.
Quick Start
# Install
pip install astrict
# Initialize in your project
cd my-project
astrict init
# Scan
astrict scan
# Scan with full context (author, incident, rationale)
astrict scan --verbose
Example Output
๐ก๏ธ Astrict โ Scanning project...
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ซ BLOCKING VIOLATIONS (1)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
global.no-float-money
File: src/payments.py:45
Author: security@company.com
๐ซ CRITICAL: Float used for financial value!
๐ค AI Code Safety Rule โ Common in AI-generated code
Fix: Use Decimal
from decimal import Decimal
price = Decimal("10.99")
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๏ธ WARNINGS (1)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
team.no-requests-without-timeout
File: src/api.py:123
Author: @senior-backend-dev
Incident: 2024-03-15 outage
โ ๏ธ HTTP request without timeout detected!
๐ฅ This caused the 2024-03-15 production outage
โ Build FAILED
How Astrict Differs
| Feature | Semgrep | SonarQube | Astrict |
|---|---|---|---|
| Security rules | โ Strong | โ Good | โ Good |
| Tribal knowledge | โ None | โ None | โ Core feature |
| Incident linking | โ None | โ None | โ Built-in |
| Author attribution | โ None | โ None | โ Every rule |
| AI code safety | โ None | โ None | โ Built-in |
| Rule hierarchy | โ Flat | โ Flat | โ GLOBAL>TEAM>PERSONAL |
| Personal rules | โ No | โ No | โ Git-ignored |
Integrations
VS Code Extension
Real-time analysis with rich hover tooltips showing rule context.
Install "Astrict" from VS Code Marketplace
GitHub Actions
- uses: saadparast/astrict-action@v2
with:
fail-on-block: 'true'
post-pr-comment: 'true'
Pre-commit Hook
repos:
- repo: https://github.com/saadparast/astrict
rev: v2.0.0
hooks:
- id: astrict-scan
Writing Rules
Incident-Driven Rule (from a production failure)
- metadata:
id: "team.no-requests-without-timeout"
author: "@senior-dev"
created: "2024-03-16"
incident: "2024-03-15-prod-hang"
rationale: |
On March 15, a requests.get() without timeout hung for
30 minutes and took down production. Cost: $50K.
layer: TEAM
severity: WARN
pattern:
type: ai_pattern
ai_tool_patterns:
- "requests\\.(get|post)\\([^)]*(?!timeout)[^)]*\\)"
message: |
โ ๏ธ HTTP request without timeout!
๐ฅ This caused the 2024-03-15 outage.
Fix: requests.get(url, timeout=10)
AI Code Safety Rule
- metadata:
id: "global.no-float-money"
author: "security@company.com"
rationale: "AI tools generate float for money. $0.1 + $0.2 โ $0.3"
tags: ["ai-safety", "finance"]
layer: GLOBAL
severity: BLOCK
pattern:
type: ai_pattern
target_matches: "price|salary|balance|amount"
ai_tool_patterns:
- "(?i)(price|amount)\\s*=\\s*\\d+\\.\\d+"
correct_pattern: "from decimal import Decimal; price = Decimal('10.99')"
message: |
๐ซ Float used for financial value!
๐ค AI tools commonly generate this mistake.
Fix: Use Decimal
Project Structure
your-project/
โโโ .astrict/
โ โโโ global.yaml # Security rules (BLOCK) โ committed
โ โโโ team.yaml # Tribal knowledge (WARN) โ committed
โ โโโ personal.yaml # Your habits (NUDGE) โ git-ignored
โโโ src/
CLI Commands
| Command | Description |
|---|---|
astrict scan |
Scan project for violations |
astrict init |
Initialize .astrict/ directory |
astrict explain <rule-id> |
Show full rule context |
astrict validate |
Validate rule files |
astrict audit --output report.json |
Generate compliance report |
astrict langs |
Show supported languages |
License
Elastic License 2.0 โ see LICENSE
Built by @saadparast
Turn your outages into rules. Your team's memory, automated. ๐ก๏ธ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file astrict-2.0.0.tar.gz.
File metadata
- Download URL: astrict-2.0.0.tar.gz
- Upload date:
- Size: 7.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f7da95e4c9a7cf69e6945f6aed45a7954ff80e18222d426bad8282727ce2389
|
|
| MD5 |
bf8b13ab5128b978a7f2a30fb23c4487
|
|
| BLAKE2b-256 |
b595e00c6fcdde3f1a4fed47fab61d36642a89a825990336a7735f780fe9fdcd
|
File details
Details for the file astrict-2.0.0-py3-none-any.whl.
File metadata
- Download URL: astrict-2.0.0-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d0b95465e02a6d636c864290f951d53226bdb78026f0ee26561f2a9a7b6d85c
|
|
| MD5 |
94908ba1545e272de8747cdb87d3090e
|
|
| BLAKE2b-256 |
672d4d5ddb27a1756766ba525d1c3715061afbcfdc7ad92a7e96168df9b2691c
|