Skip to main content

Reality-First Development Protocol - Prevents AI hallucination and ensures spec-driven development

Project description

RFD Protocol

Reality-First Development - Prevents AI hallucination and ensures spec-driven development

CI Pipeline Release Pipeline PyPI version Python 3.8+ License: MIT

What is RFD?

RFD (Reality-First Development) is a protocol that eliminates AI hallucination and prevents squirrel-brain in software development by enforcing concrete reality checkpoints. Instead of trusting AI claims about what was implemented, RFD validates that code actually runs, tests pass, and features work.

Core Benefits

  • ๐ŸŽฏ Prevents AI Hallucination: Drops error rate from 48% to ~0%
  • ๐Ÿง  Eliminates Squirrel Brain: Can't drift from defined features
  • ๐Ÿ“‹ Spec-Driven Development: Features must be specified before implementation
  • โœ… Reality Checkpoints: Every change is validated against working code
  • ๐Ÿ”„ Session Persistence: Context maintained across all sessions
  • ๐ŸŒ Universal Drop-in: Works with any tech stack (25+ languages)
  • ๐Ÿ”’ Recovery Guaranteed: Always recoverable from any state

๐Ÿ“š Documentation

Quick Start (2 Minutes)

Installation

# Install from PyPI
pip install rfd-protocol

# Or upgrade to latest
pip install --upgrade rfd-protocol

Initialize Your Project

# RECOMMENDED: Use the interactive wizard
rfd init --wizard

# Or quick init for simple projects
rfd init

# For existing projects
rfd init --wizard --mode brownfield

# From a PRD/requirements doc
rfd init --from-prd requirements.md

Start Development

# Check your status
rfd check

# Start working on a feature
rfd session start hello_world

# Build and validate
rfd build
rfd validate

# Save your progress
rfd checkpoint "Feature working"

# End your session
rfd session end

How RFD Prevents Squirreling

RFD makes it impossible to lose focus or claim false progress:

# PROJECT.md locks your features
features:
  - id: user_auth
    acceptance: "Users can login"  # โ† Must be proven
    status: building               # โ† Can't work on others

Try to squirrel? RFD stops you:

rfd session start random_feature
โŒ Error: Feature 'random_feature' not found in PROJECT.md

rfd checkpoint "Did something"  
โŒ Error: Validation failed - cannot checkpoint

Reality enforcement:

  • โœ… Code must compile/run
  • โœ… Tests must pass
  • โœ… APIs must respond
  • โŒ No mocks or stubs
  • โŒ No theoretical progress

Project Architecture

Our repository follows modern Python packaging standards with a clear separation of concerns:

rfd-protocol/
โ”œโ”€โ”€ README.md                  # This file
โ”œโ”€โ”€ PROJECT.md                 # Project specification
โ”œโ”€โ”€ pyproject.toml            # Modern Python packaging config
โ”œโ”€โ”€ requirements.txt          # Runtime dependencies
โ”‚
โ”œโ”€โ”€ src/rfd/                  # ๐ŸŽฏ MAIN PACKAGE (modern Python layout)
โ”‚   โ”œโ”€โ”€ __init__.py          # Package entry point, version info
โ”‚   โ”œโ”€โ”€ cli.py               # Command-line interface
โ”‚   โ”œโ”€โ”€ rfd.py              # Core RFD orchestration class
โ”‚   โ”œโ”€โ”€ validation.py       # AI hallucination detection engine
โ”‚   โ”œโ”€โ”€ session.py          # Session management & persistence
โ”‚   โ”œโ”€โ”€ build.py            # Build automation engine
โ”‚   โ”œโ”€โ”€ spec.py             # Specification management
โ”‚   โ””โ”€โ”€ templates/          # Project templates
โ”‚
โ”œโ”€โ”€ tests/                   # ๐Ÿงช COMPREHENSIVE TEST SUITE
โ”‚   โ”œโ”€โ”€ conftest.py         # Shared pytest fixtures
โ”‚   โ”œโ”€โ”€ unit/               # Fast, isolated tests
โ”‚   โ”œโ”€โ”€ integration/        # Component interaction tests
โ”‚   โ”œโ”€โ”€ system/             # End-to-end workflow tests
โ”‚   โ””โ”€โ”€ fixtures/           # Test data and sample projects
โ”‚
โ”œโ”€โ”€ docs/                   # ๐Ÿ“š DOCUMENTATION
โ”‚   โ”œโ”€โ”€ AGENTS.md           # Agent orchestration definitions
โ”‚   โ”œโ”€โ”€ CLAUDE.md           # Claude Code CLI configuration
โ”‚   โ”œโ”€โ”€ INSTALL.md          # Installation instructions
โ”‚   โ”œโ”€โ”€ RFD-PROTOCOL.md     # Core protocol specification
โ”‚   โ”œโ”€โ”€ @RFD-PROTOCOL.md    # Protocol summary
โ”‚   โ””โ”€โ”€ RFD-PLAN.md         # Development roadmap
โ”‚
โ”œโ”€โ”€ tools/                  # ๐Ÿ”ง DEVELOPMENT TOOLS
โ”‚   โ”œโ”€โ”€ comprehensive_audit.py    # Codebase audit tool
โ”‚   โ””โ”€โ”€ detailed_bug_analysis.py  # Bug analysis tool
โ”‚
โ”œโ”€โ”€ scripts/                # ๐Ÿ“œ LEGACY SCRIPTS
โ”‚   โ””โ”€โ”€ [legacy tools]      # Historical development scripts
โ”‚
โ”œโ”€โ”€ .github/workflows/      # ๐Ÿš€ CI/CD PIPELINE
โ”‚   โ”œโ”€โ”€ ci.yml             # Continuous integration
โ”‚   โ””โ”€โ”€ release.yml        # Automated releases
โ”‚
โ””โ”€โ”€ rfd -> .rfd/rfd.py     # ๐Ÿ”— SYMLINK (legacy compatibility)

Directory Purposes

Core Directories

  • src/rfd/: Modern Python package following PEP standards. This is the main codebase.
  • tests/: Comprehensive test suite with 90+ test functions across unit/integration/system categories.
  • .rfd/: Legacy system directory for backward compatibility. Contains working database and CLI.

Documentation Directories

  • docs/: Essential documentation and specifications.
  • docs/archive/: Historical documents from development phases.
  • research/: Background research and design decisions.

Development Directories

  • tools/: Development and analysis tools.
  • scripts/: Legacy development scripts.
  • .github/workflows/: CI/CD automation.

Transition Directories

  • nexus_rfd_protocol/: Old package structure being phased out.
  • rfd (symlink): Legacy CLI compatibility.

Core Concepts

Reality-First Principles

  1. Code that runs > Perfect architecture
  2. Working features > Planned features
  3. Real data > Mocked responses
  4. Passing tests > Theoretical correctness

Validation Engine

RFD continuously validates:

  • โœ… Files actually exist (detects AI file creation lies)
  • โœ… Functions are implemented (not just claimed)
  • โœ… APIs respond correctly
  • โœ… Tests pass with real data
  • โœ… Build processes work

Session Management

  • Persistent Context: RFD maintains what you're working on across restarts
  • Memory: AI remembers what worked/failed in previous sessions
  • Progress Tracking: Visual progress through complex features
  • Auto-Recovery: Continue from last checkpoint if interrupted

Integration with Claude Code

RFD is specifically designed to prevent AI hallucination and keep Claude on track:

Starting a Claude Session

Say this to Claude:

Continue the RFD project. Run 'rfd check' and follow the current session.

What Claude Will Do Automatically

  1. Check Status: rfd check - Know exactly where you left off
  2. Read Context: Reviews .rfd/context/current.md for your task
  3. Follow Spec: Reads acceptance criteria from PROJECT.md
  4. Validate Reality: Runs rfd validate after every change
  5. Save Progress: Runs rfd checkpoint when tests pass

Why This Prevents Hallucination

# Claude claims: "I implemented the feature"
rfd validate
โŒ feature_login: No endpoint found
โŒ tests: 0/5 passing
# Reality: Nothing was actually implemented

# Claude can't fake progress:
rfd checkpoint "Added login"
โŒ Cannot checkpoint - validation failing

Session Recovery

# New Claude session after restart:
"Continue the RFD session"

# Claude automatically:
rfd check
> Session: user_auth (started yesterday)
> Last checkpoint: "Login endpoint working"
> Next: Implement password reset

# Continues exactly where you left off!

See Claude Code Guide for complete integration details.

Command Reference

Core Commands

rfd init                    # Initialize RFD in current directory
rfd check                   # Quick status check
rfd spec create            # Interactive spec creation
rfd spec review            # Review current specification

Development Workflow

rfd session start <feature>  # Start working on a feature  
rfd build [feature]          # Build/compile feature
rfd validate [--feature X]  # Run validation tests
rfd checkpoint "message"     # Save working state
rfd session end             # Mark feature complete

Spec-Kit Style Commands (NEW!)

rfd speckit constitution    # Create immutable project principles
rfd speckit specify        # Define detailed specifications
rfd speckit clarify       # Identify and resolve ambiguities
rfd speckit plan          # Create implementation plan
rfd speckit tasks         # Generate task breakdown
rfd analyze               # Cross-artifact consistency analysis

State Management

rfd revert                  # Revert to last checkpoint
rfd memory show            # Show AI memory
rfd memory reset           # Clear AI memory

Specification Format

RFD uses YAML frontmatter in PROJECT.md as the single source of truth. See PROJECT_SCHEMA.md for complete schema documentation.

Quick Schema Reference

---
# Required Fields
name: "Project Name"
description: "Brief project description"
version: "1.0.0"

# Stack (extensible beyond these core fields)
stack:
  language: python          # Required
  framework: fastapi        # Required  
  database: postgresql      # Required
  runtime: python-3.11      # Optional
  package_manager: pip      # Optional
  test_framework: pytest    # Optional
  deployment: docker        # Optional

# Validation Rules
rules:
  max_files: 50
  max_loc_per_file: 500
  must_pass_tests: true
  no_mocks_in_prod: true
  min_test_coverage: 80     # Optional
  require_types: true       # Optional

# Features (at least 1 required)
features:
  - id: feature_id
    description: "What this feature does"
    acceptance: "How to verify it works"
    status: pending          # pending|building|testing|complete
    priority: high           # Optional: critical|high|medium|low
    depends_on: []           # Optional: feature dependencies

# Constraints (recommended)
constraints:
  - "Must support 1000 concurrent users"
  - "API response time < 200ms"
  - "GDPR compliant"
---

# Project Name

Detailed project documentation in markdown...

Customizing Schema After Init

After running rfd init, you can modify PROJECT.md to:

  1. Extend the stack - Add runtime, package_manager, deployment fields
  2. Add validation rules - Set coverage requirements, complexity limits
  3. Define API contracts - Document endpoints and schemas
  4. Set team info - Track developers and responsibilities
  5. Create milestones - Plan release schedules

Example: Adding custom stack fields:

# Edit PROJECT.md and add under stack:
stack:
  language: python
  framework: fastapi
  database: postgresql
  runtime: python-3.11        # Added
  package_manager: poetry      # Added
  deployment: kubernetes       # Added
  monitoring: prometheus       # Added

RFD automatically validates schema changes and preserves custom fields.

Getting Started Guide

For Brand New Projects

  1. Create project directory:

    mkdir my-awesome-project
    cd my-awesome-project
    
  2. Initialize RFD:

    rfd init
    

    This will walk you through:

    • Project name and description
    • Technology stack selection
    • Initial feature definitions
    • Acceptance criteria
  3. Review generated files:

    • PROJECT.md - Your specification
    • CLAUDE.md - AI instructions
    • PROGRESS.md - Progress tracking
  4. Start developing:

    rfd session start <first-feature>
    # Write code...
    rfd build
    rfd validate
    rfd checkpoint "First feature working"
    

For Existing Projects

  1. Add RFD to existing project:

    cd existing-project/
    rfd init
    
  2. RFD will analyze your project:

    • Detect programming language
    • Identify build system
    • Suggest initial feature breakdown
  3. Define what you want to build:

    • Edit generated PROJECT.md
    • Add acceptance criteria for features
    • Set validation rules
  4. Start RFD workflow:

    rfd check                # See current state
    rfd session start <feature>
    # Continue development with RFD validation
    

What You Need to Provide

Minimum Required:

  • Project goal: What are you building?
  • Technology stack: Language, framework, database
  • First feature: What's the first thing you want working?

Recommended:

  • Acceptance criteria: How do you know a feature is done?
  • Validation rules: Max files, complexity limits
  • Test requirements: What tests must pass?

Technology Stack Support

RFD works with any stack by detecting your configuration:

  • Python: FastAPI, Flask, Django, any framework
  • JavaScript/TypeScript: Express, NestJS, Next.js, React, Vue
  • Go: Gin, Echo, standard library
  • Rust: Actix, Rocket, Axum
  • Java/Kotlin: Spring Boot, Quarkus
  • C/C++: Any build system
  • And 20+ more languages...

Development

Running Tests

# All tests
pytest

# By category
pytest -m unit           # Fast unit tests
pytest -m integration    # Integration tests  
pytest -m system         # End-to-end tests

# With coverage
pytest --cov=src/rfd --cov-report=html

Code Quality

# Linting
ruff check src tests

# Formatting
ruff format src tests

# Type checking (optional)
mypy src --ignore-missing-imports

Troubleshooting

Common Issues

"No feature specified"

rfd session start <feature_id>  # Start a session first

"Validation failed"

rfd validate                    # See what's failing
rfd build                       # Fix build issues first

"Lost context"

rfd check                       # See current state
cat .rfd/context/current.md     # Check session file

Debug Mode

export RFD_DEBUG=1
rfd validate                    # Verbose output

Legacy vs Modern CLI

We provide two CLI options:

  • Modern: rfd (via pip install) - Uses src/rfd/ package
  • Legacy: ./rfd or python .rfd/rfd.py - Uses .rfd/ directory

Both provide the same functionality for backward compatibility.

Architecture Decisions

Why Both docs/RFD-PROTOCOL.md and docs/@RFD-PROTOCOL.md?

  • docs/RFD-PROTOCOL.md: Complete protocol specification with all details
  • docs/@RFD-PROTOCOL.md: Summary version for quick reference with @ prefix for Claude Code CLI

Why Keep Legacy .rfd/ Directory?

  • Backward Compatibility: Existing projects using RFD continue working
  • Migration Path: Gradual transition to modern package structure
  • Working Database: Contains SQLite state and session data
  • Symlink Compatibility: Legacy ./rfd command still works

Why Both nexus_rfd_protocol/ and src/rfd/?

  • Transition Period: Moving from old package name to new clean structure
  • Testing: Ensuring both old and new imports work during transition
  • Release Safety: No breaking changes for existing users

Contributing

RFD Protocol is open source. Contributions welcome!

  1. Fork the repository
  2. Create a feature branch
  3. Use RFD to develop your feature ๐Ÿ˜‰
  4. Ensure tests pass: pytest
  5. Submit a pull request

Development Setup

git clone https://github.com/kryptobaseddev/rfd-protocol.git
cd rfd-protocol
pip install -e ".[dev]"
pytest  # Run tests

License

MIT License - see LICENSE file.

Support


Built with RFD Protocol - This project was developed using its own reality-first methodology.

Version History

  • v2.4.0: SQLite WAL mode, cross-artifact analysis, spec-kit feature parity, comprehensive walkthrough
  • v2.3.0: Mock detection, critical fixes, session persistence improvements
  • v2.0.0: Spec generation, gated workflow, AI validation
  • v1.0.0: Production release with modern Python packaging, comprehensive test suite, CI/CD pipeline, and full documentation.

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

rfd_protocol-4.0.0.tar.gz (101.8 kB view details)

Uploaded Source

Built Distribution

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

rfd_protocol-4.0.0-py3-none-any.whl (89.8 kB view details)

Uploaded Python 3

File details

Details for the file rfd_protocol-4.0.0.tar.gz.

File metadata

  • Download URL: rfd_protocol-4.0.0.tar.gz
  • Upload date:
  • Size: 101.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for rfd_protocol-4.0.0.tar.gz
Algorithm Hash digest
SHA256 256bee2fa65fe2f41eb3f3756c99d1ee43630eb27c5410648826c039b325afb2
MD5 736b91732e586f6d90064d52da4cdba2
BLAKE2b-256 ba75cd44f334e5a4e2a8ab6927c61d7ec745e0afbfbfd605a289494a1d186fa7

See more details on using hashes here.

File details

Details for the file rfd_protocol-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: rfd_protocol-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 89.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for rfd_protocol-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdcd9d6dc1b46cb00d3a2fd7d3375d7603f24a2da119b92586767fc5ef4e68e7
MD5 2ea315cd4fb802245d23455d31324090
BLAKE2b-256 6adf47c9096d8c1f46c70f0ef6227e7409ca2b36f65ed6864611a3eed8a0080e

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