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
- Python AST parser for imports, classes, functions, and summaries
- Lightweight dependency graph
- Context selector using prompt keywords and graph metadata
- Token counting with
tiktokenwhen 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.
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
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 contextguardrail-0.1.0.tar.gz.
File metadata
- Download URL: contextguardrail-0.1.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
483ca9dee6568ac6b7f69e0fa0c383a895993e8f09bb356199d8a2c62ea1cfb9
|
|
| MD5 |
549d7e490a8871acbc0817b1c83016d2
|
|
| BLAKE2b-256 |
0e1edbeca5d5bd0bc1f89cdb98e6d37392715cd8bbab73c51e821ad20c12a610
|
Provenance
The following attestation bundles were made for contextguardrail-0.1.0.tar.gz:
Publisher:
workflow.yml on sachnaror/contextguardrail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contextguardrail-0.1.0.tar.gz -
Subject digest:
483ca9dee6568ac6b7f69e0fa0c383a895993e8f09bb356199d8a2c62ea1cfb9 - Sigstore transparency entry: 1693407182
- Sigstore integration time:
-
Permalink:
sachnaror/contextguardrail@21a794e2f480541218b31272bd4c61b9b68cc343 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sachnaror
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@21a794e2f480541218b31272bd4c61b9b68cc343 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file contextguardrail-0.1.0-py3-none-any.whl.
File metadata
- Download URL: contextguardrail-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7abeadbd92f65b2e93d31731614cee88e681720663931281aef6667656d05b9a
|
|
| MD5 |
27bcf46345fb65228abfd4e2703b8572
|
|
| BLAKE2b-256 |
94457ab147dd6866fb0484d2a6133896c0fbcf45bcaecde811c04ce5c5edc944
|
Provenance
The following attestation bundles were made for contextguardrail-0.1.0-py3-none-any.whl:
Publisher:
workflow.yml on sachnaror/contextguardrail
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
contextguardrail-0.1.0-py3-none-any.whl -
Subject digest:
7abeadbd92f65b2e93d31731614cee88e681720663931281aef6667656d05b9a - Sigstore transparency entry: 1693407374
- Sigstore integration time:
-
Permalink:
sachnaror/contextguardrail@21a794e2f480541218b31272bd4c61b9b68cc343 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sachnaror
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@21a794e2f480541218b31272bd4c61b9b68cc343 -
Trigger Event:
workflow_dispatch
-
Statement type: