Skip to main content

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.

PyPI License Python


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.log with 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astrict-2.0.0.tar.gz (7.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

astrict-2.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

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

Hashes for astrict-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8f7da95e4c9a7cf69e6945f6aed45a7954ff80e18222d426bad8282727ce2389
MD5 bf8b13ab5128b978a7f2a30fb23c4487
BLAKE2b-256 b595e00c6fcdde3f1a4fed47fab61d36642a89a825990336a7735f780fe9fdcd

See more details on using hashes here.

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

Hashes for astrict-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d0b95465e02a6d636c864290f951d53226bdb78026f0ee26561f2a9a7b6d85c
MD5 94908ba1545e272de8747cdb87d3090e
BLAKE2b-256 672d4d5ddb27a1756766ba525d1c3715061afbcfdc7ad92a7e96168df9b2691c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page