Skip to main content

Local-first token firewall for AI coding agents

Project description

ContextGuardrail

ContextGuardrail is a local-first MVP for reducing AI coding-agent context. It scans a repo, builds a lightweight code graph, selects relevant files for a prompt, prevents replaying already-sent files, caches repeated asks, and reports estimated token/cost savings.

Install locally

cd /Users/homesachin/Desktop/zoneone/contextguardrail
python -m venv .venv
source .venv/bin/activate
pip install -e .

Use

contextguardrail init
contextguardrail index /path/to/repo
contextguardrail ask "Where is authentication handled?"
contextguardrail stats
contextguardrail export
contextguardrail clean

All state is stored in the indexed repo under .contextguardrail/.

MVP Features

  • Repo scanner with incremental hashing
  • Supported file scanning for .py, .md, .css, .js, .html, .txt, .env, Dockerfile, .example, and .json
  • Python AST parser for imports, classes, functions, and summaries
  • Lightweight dependency graph
  • Context selector using prompt keywords and graph metadata
  • Token counting with tiktoken when available, word-count fallback otherwise
  • Semantic cache for repeated prompt and selected-file sets
  • Replay prevention so already-sent files are skipped unless changed
  • Context diffing via file hashes
  • Cost observability through contextguardrail stats

This version intentionally skips dashboards, multi-user support, Neo4j, and agent orchestration.

Supported Files

ContextGuardrail indexes common application, documentation, config, and deployment files:

.py
.md
.css
.js
.html
.txt
.env
Dockerfile
.example
.json

Dockerfile is matched by filename, so it works even though it has no extension. .env and .example files are matched by suffix, which covers files like .env, .env.example, and settings.example.

Project Layout

contextguardrail/
├── pyproject.toml              # Package metadata, dependencies, CLI entrypoints
├── README.md                   # Project documentation and usage guide
├── contextguardrail/
│   ├── scanner.py              # Scan repo and detect files, hashes, changes
│   ├── config.py               # Global settings and configuration loading
│   ├── budget.py               # Token estimation and budget enforcement
│   ├── exporter.py             # Export graph, summaries, and reports
│   ├── graph.py                # Build dependency graph from source code
│   ├── selector.py             # Select most relevant context for a prompt
│   ├── cache.py                # Semantic cache and replay prevention
│   ├── cli.py                  # Main CLI commands exposed to users
│   ├── stats.py                # Usage metrics and cost-saving reports
│   └── storage.py              # SQLite helpers and persistence layer
└── tests/
    └── test_budget.py          # Unit tests for token budgeting logic

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

contextguardrail-0.2.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

contextguardrail-0.2.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file contextguardrail-0.2.0.tar.gz.

File metadata

  • Download URL: contextguardrail-0.2.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for contextguardrail-0.2.0.tar.gz
Algorithm Hash digest
SHA256 db1670b447b0ce2606bdee4d05f7ff666357f4fb70aa37ccbcaca6353f6a6b9d
MD5 4fe4bacdf8afb29dc3f96642d73a9369
BLAKE2b-256 7e724d702292b703b85a261f3234214f5183dbbc678e825ab0257aae3c8e223e

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextguardrail-0.2.0.tar.gz:

Publisher: workflow.yml on sachnaror/contextguardrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file contextguardrail-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for contextguardrail-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7070265361c7ad8a91362d3f5aee71915b6de99764c1746c3b1274777aec8571
MD5 4a351f6d2cd9dfef249ffc5cd0efbce0
BLAKE2b-256 6ea2fa6e9ede0c06bb63b0bf32f798157b848e2a2d73dac27d37ea7eaacec13d

See more details on using hashes here.

Provenance

The following attestation bundles were made for contextguardrail-0.2.0-py3-none-any.whl:

Publisher: workflow.yml on sachnaror/contextguardrail

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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