Skip to content

Repository files navigation

πŸ›‘οΈ Checkrail

Deterministic Quality Gates & Hierarchical Context Scaffolding for AI Coding Agents

License: MIT CI / Quality Gates Bash 4.4+ Python 3.12+ Security: Gitleaks PRs Welcome

An open-source verification harness and hierarchical context scaffolding designed to enforce deterministic boundaries and multi-tier quality gates for autonomous AI coding agents.

Disclaimer: Checkrail is an independent open-source engineering project. It is not affiliated with, endorsed by, or associated with any other project, commercial platform, or trademark holder.


πŸ“Œ Project Status

Experimental (pre-1.0). Checkrail is under active development. Gate specifications, file formats, and runtime interfaces may evolve across releases. Use in production environments at your own discretion. No benchmark results have been published yet for token optimization claims.


πŸ”¬ Scientific & Industrial Rationale

As Large Language Models (LLMs) and autonomous agent frameworks (Kilo, Claude Code, OpenCode, Cursor, Devin) transition from exploratory code-completion to fully autonomous codebase refactoring and CI/CD operations, they introduce critical failure modes:

  1. Context Bloat & Token Degradation (Attention Bleed): Recursive file-tree scanning and unfiltered context dumps exhaust attention mechanisms, increasing operational latency, API costs, and hallucination rates.
  2. Guardrail & Security Erosion: Unconstrained agents inadvertently modify security manifests, weaken CI checks, or bypass permission boundaries.
  3. Secret Ingestion & Exfiltration: Accidental ingestion and staging of .env files, SSH credentials, and private keys.
  4. Repository Documentation Drift: Autonomous changes break manual architectural maps, invalidating agent grounding on subsequent turns.
  5. Session Amnesia & State Loss: Fragmented state transitions between multi-turn or multi-agent worktree handovers.

Checkrail introduces a multi-tiered, deterministic verification and context-management harness that enforces formal safety boundaries and is architecturally designed to mitigate context degradation and enforce policy and quality gate compliance before code reaches review.


πŸ›οΈ Architectural Taxonomy & Core Pillars

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Layer 0: AGENTS.md (Root Invariants)                  β”‚
β”‚           Deterministic trigger routing β€’ Lean L0 context routing           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                β–Ό                                             β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Layer 1: Architecture Core  β”‚             β”‚   Layer 2: Protocol Engine    β”‚
β”‚    (docs/agent/SUMMARY.md)    β”‚             β”‚   (docs/agent/protocol.md)    β”‚
β”‚  Domain context, Stack & Flow β”‚             β”‚   Deep workflows & fallback   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                β”‚                                             β”‚
                β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Automated Governance & Verification Harness              β”‚
β”‚  β”œβ”€β”€ 9-Tier Quality Verification (scripts/quality-gates.sh)                 β”‚
β”‚  β”œβ”€β”€ Zero-Drift Compact Indexing (scripts/sync-docs.sh)                     β”‚
β”‚  β”œβ”€β”€ Sandboxed Permission Rules (kilo.jsonc)                                β”‚
β”‚  β”œβ”€β”€ Formal Empirical Audit Matrix (docs/agent/bootstrap-audit.md)          β”‚
β”‚  └── Deterministic State Handover (docs/agent/HANDOVER.md)                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

1. ⚑ Hierarchical Context Minimization

Checkrail discards monolithic prompts in favor of an indexed 3-layer architecture:

  • Layer 0 (AGENTS.md): Always-on routing table. Directs agents to exact files without recursive exploration.
  • Layer 1 (docs/agent/SUMMARY.md): High-level domain, stack specifications, and pipeline models.
  • Layer 2 (docs/agent/protocol.md): Deep execution workflows, loaded strictly when blocking ambiguities arise.

2. πŸ›‘οΈ 9-Tier Quality Verification Gates (scripts/quality-gates.sh)

Every agent and developer change is passed through a deterministic nine-tier verification pipeline (Gate 0 – Gate 8):

  • Gate 0: Tooling Prerequisite Check β€” Verifies major/minor version compliance (.tool-versions).
  • Gate 1: Base Branch & Differential Scoping β€” Isolates target diffs and prevents unanchored commits.
  • Gate 2: Clean Tree & Working-Copy Integrity β€” Validates staging consistency and rejects untracked drift.
  • Gate 3: Protected Guardrail Defense β€” Blocks agent mutations to security, CI, and policy files unless explicitly authorized with --allow-guardrail.
  • Gate 4: Shell Syntax & POSIX/LF Compliance β€” Strict bash -n validation and line-ending verification.
  • Gate 5: Static Analysis & Code Quality β€” Python static typing, linting (ruff), and QA harnesses.
  • Gate 6: Infrastructure & Configuration Verification β€” Validates Terraform and cloud orchestration manifests.
  • Gate 7: Deterministic Documentation Verification β€” Fails if documentation index (docs/file-index.md) drifts from disk state.
  • Gate 8: Anti-Leak Cryptographic & Secret Scan β€” Integrated Gitleaks analysis and fallback heuristic scanning.

3. πŸ“‘ Zero-Drift Repository Indexing (scripts/sync-docs.sh)

  • Generates a compact, deterministic inventory in docs/file-index.md from scripts/file-descriptions.txt.
  • Provides structural grounding to agents within a bounded token budget (≀ 20 KB, enforced by sync-docs.sh).

4. πŸ”’ Engine Sandbox & Permission Map (kilo.jsonc)

  • Strict deny/ask rules for destructive actions (rm -rf, raw .env reading, unconstrained shell execution).

5. πŸ”„ Bounded State Handover Protocol (docs/agent/HANDOVER.md)

  • Bounded 40-line invariant state schema ([TASK], [DIFF_SUMMARY], [GATES_STATUS], [NEXT], [BLOCKERS]) providing continuous context across distributed worktrees and agent sessions.

πŸ“Š Bootstrap Audit Record (F-01 to F-24)

Checkrail documents a failure-mode analysis and remediation record in docs/agent/bootstrap-audit.md, covering 24 hardened-bootstrap findings and their verified fixes, including:

  • Subshell variable-inheritance failures in child processes.
  • Cross-platform Bash compatibility, including macOS's default Bash 3.2.
  • Path-traversal and symlink-overwrite defenses.
  • TOCTOU (Time-of-Check to Time-of-Use) atomic file operations.
  • Windows execution alias stub handling in CI environments.

βš–οΈ Honest Limitations

  1. Not a Formal Proof: Checkrail enforces deterministic static checks, shell validation, and git boundaries. It does not mathematically prove the runtime semantic correctness of generated application code.
  2. Token Metrics Are Architectural: Token efficiency gains stem from structured context separation (L0/L1/L2) avoiding full-tree reads. Empirical benchmark quantification is ongoing and not yet published.
  3. POSIX / Linux Centric: Checkrail is built primarily for Bash-compatible environments (Linux, macOS, WSL2). Native Windows environments without a POSIX layer are not supported.
  4. No Semantic Logic Guarantee: The gates verify syntax, diff scope, secret absence, and structureβ€”not whether the business logic meets user intent.

πŸš€ Quick Start

1. Installation & Environment Verification

git clone https://github.com/miladjln/checkrail.git
cd checkrail

# Run full diagnostic verification
bash scripts/doctor.sh

2. Pre-Commit Integration

# Register quality gates into local git hooks
pre-commit install

3. Documentation Synchronization

Whenever repository files or modules change:

# Update descriptions in scripts/file-descriptions.txt, then:
bash scripts/sync-docs.sh

# Stage the regenerated index
git add docs/file-index.md

4. Quality Gate Execution

# Fast-tier gate for staged changes (Pre-Commit)
bash scripts/quality-gates.sh --staged-only --fast

# Complete 9-tier verification suite (CI Equivalent)
bash scripts/quality-gates.sh

πŸ› οΈ Script Harness Reference

Script Function Key Flags
scripts/doctor.sh Health check for environment, dependencies, CRLF, and pack integrity. None
scripts/quality-gates.sh Comprehensive 9-tier automated quality and security gates. --staged-only, --fast, --allow-guardrail, --ack-new-guardrail, --quiet, --strict-versions
scripts/sync-docs.sh Deterministic documentation indexer and drift detector. --check, --compact, --full

πŸ“‚ Repository Topology

checkrail/
β”œβ”€β”€ .github/
β”‚   β”œβ”€β”€ workflows/
β”‚   β”‚   └── quality-gates.yml       # Production CI Verification Pipeline
β”‚   β”œβ”€β”€ ISSUE_TEMPLATE/             # Standardized Bug & Feature Blueprints
β”‚   β”œβ”€β”€ PULL_REQUEST_TEMPLATE.md    # Gate-Enforced Pull Request Checklist
β”‚   β”œβ”€β”€ dependabot.yml              # Automated Dependency & Action Updates
β”‚   └── CODEOWNERS                  # Access & Ownership Matrix
β”œβ”€β”€ .kilo/                          # Autonomous Agent Workspace & Subagent Runtime
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ agent/
β”‚   β”‚   β”œβ”€β”€ SUMMARY.md              # Layer 1 Architectural Context
β”‚   β”‚   β”œβ”€β”€ protocol.md             # Layer 2 Execution Protocol
β”‚   β”‚   β”œβ”€β”€ HANDOVER.md             # Standardized State Handover File
β”‚   β”‚   └── bootstrap-audit.md      # Formal Security & Regression Audit Log
β”‚   └── file-index.md               # Auto-Generated Compact File Inventory
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ doctor.sh                   # Environment Diagnostic & Health Script
β”‚   β”œβ”€β”€ file-descriptions.txt       # Canonical File Description Register
β”‚   β”œβ”€β”€ quality-gates.sh            # 9-Tier Security & Quality Gate Harness
β”‚   └── sync-docs.sh                # Zero-Drift Documentation Synchronizer
β”œβ”€β”€ .gitattributes                  # LF Enforcement & Normalization Policy
β”œβ”€β”€ .gitignore                      # Comprehensive VCS Ignore Register
β”œβ”€β”€ .kilocodeignore                 # LLM Context Exclusion Filter
β”œβ”€β”€ .pre-commit-config.yaml         # Pre-commit Hook Hookpack Configuration
β”œβ”€β”€ .tool-versions                  # Pinned Tool Runtime Versions
β”œβ”€β”€ AGENTS.md                       # Layer 0 Root Agent Rulebook & Invariants
β”œβ”€β”€ CITATION.cff                    # Formal Academic Citation Metadata
β”œβ”€β”€ CONTRIBUTING.md                 # Engineering & Contribution Guidelines
β”œβ”€β”€ kilo.jsonc                      # Engine Security Sandbox & Permissions
β”œβ”€β”€ LICENSE                         # MIT Open-Source License
β”œβ”€β”€ README.md                       # Comprehensive Technical Specification
└── SECURITY.md                     # Security Vulnerability & Disclosure Policy

πŸ“‘ Citation & Academic Reference

If you incorporate Checkrail in academic papers, research benchmarks, or industrial autonomous frameworks, please cite:

@software{jalilian2026checkrail,
  author = {Jalilian, Seyed Milad},
  title = {Checkrail: Deterministic Quality Gates and Hierarchical Context Scaffolding for AI Coding Agents},
  year = {2026},
  url = {https://github.com/miladjln/checkrail},
  version = {0.1.0}
}

🀝 Contributing

We welcome contributions from engineers and researchers. Please review CONTRIBUTING.md for workflow protocols and gate standards.


πŸ›‘οΈ Security

For vulnerability disclosures and security policies, refer to SECURITY.md.


πŸ“„ License

This project is licensed under the MIT License β€” see the LICENSE file.

Copyright (c) 2026 Seyed Milad Jalilian

About

Deterministic Quality Gates & Hierarchical Context Scaffolding for AI Coding Agents

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages