Skip to content
Nobody-KnowsBetterPublic

About

Automated documentation drift detection powered by AST diffing and Qwen 2.5 Coder. Catches outdated docs, API signature changes, and config drifts in PRs with precise autofixes.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

56 Commits

Folders and files

Repository files navigation

πŸ›‘οΈ DocGuard β€” AI-Powered Documentation Intelligence Platform

CI Live Website GitHub Action Python 3.11+ FastAPI Next.js Ollama License: MIT

Prevent documentation rot before code merges. DocGuard detects the exact sentences in your docs that a pull request or code change invalidated, pinpoints the responsible code diff, and opens a fix pull request in one click.

🌐 Live Demo Website: docguard-org.vercel.app


πŸš€ Use It On Your Repository (GitHub Action)

Sign in on the website and click Add to GitHub Actions on a repository. DocGuard opens a setup pull request, and once you merge it, every pull request gets checked. You can also add .github/workflows/docguard.yml yourself:

name: DocGuard

# Runs on pull requests from forks too, so outside contributors see the report.
# DocGuard only reads the pull request's code. It never runs it.
on:
  pull_request_target:

permissions:
  contents: read
  pull-requests: write

jobs:
  docguard:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: Nobody-KnowsBetter/ooli@main

Every pull request now gets a comment naming the exact doc sentences it made wrong, the code change responsible, a suggested fix and a link to fix it in that pull request. There's no comment when nothing drifted. Everything runs inside your own GitHub Actions: no account, no API key, and your code stays there.

Input Default What it does
use-model true Runs Qwen for ambiguous sentences rules can't decide. Model is downloaded only when needed.
model qwen2.5-coder:3b The Ollama model to use.
comment true Posts the report on the pull request. It always appears in the job summary too.
fail-on-drift false Fails the check when it confirms drift.

Outputs: drift-count, confirmed-count, possible-count.


πŸ’‘ The Problem

Developers constantly modify code without updating documentation:

# In src/config.py
TIMEOUT_SECONDS = 13456  # Changed from 30

While documentation quietly rots:

# In docs/configuration.md
The request timeout is 30 seconds.

Traditional CI/CD linters test code execution and syntax, but fail to detect when ordinary English prose, parameter tables, tutorials, or API guides contradict code reality.

These silent documentation drifts lead to:

  • Broken onboarding instructions and developer confusion.
  • Inaccurate parameter references and invalid CLI flag examples.
  • Time wasted debugging discrepancies between code reality and written documentation.

DocGuard solves this through a hybrid pipeline: combining deterministic Python AST analysis for zero-hallucination code extraction with lightweight, local LLM reasoning (Qwen 2.5 Coder) to verify contextual prose.


✨ Key Features

  • πŸ” Deterministic AST Diffing: Tracks changes to CLI flags (argparse), function parameters, constants, route paths, configuration defaults, and environment variables. Skips tests and private symbols to minimize noise.
  • πŸ“‘ Smart Doc Chunking: Parses Markdown files into addressable semantic sentences and sections with exact line numbers, automatically filtering out changelogs and release notes.
  • 🧠 Hybrid Verification Engine:
    • Deterministic Rules: Instantly verifies exact symbol and value collisions.
    • Local LLM Reasoning (Qwen 2.5 Coder 3B via Ollama): Analyzes ambiguous sentences that mention outdated values without explicitly naming the variable (e.g., "Requests give up after 30 seconds" when default timeout changed to 60).
    • Zero Cost / Offline Capable: Runs locally using ~2 GB RAM without mandatory cloud API keys. No closed-model APIs are used.
  • πŸ› οΈ Automated Patch Proposals: Generates precise, line-by-line documentation diffs ready to be applied with a single click.
  • πŸ“Š Interactive Web Dashboard: Modern Next.js UI providing repository health scores, drift histories, findings breakdown, and repository configuration.
  • πŸ”‘ Maintainer Portal & GitHub OAuth: Sign in with GitHub to automatically sync your repositories (private repositories only when run locally) and poll PRs in real time.

πŸ—οΈ Architecture Pipeline

DocGuard avoids generic LLM hallucination by employing a structured analysis funnel:

flowchart TD
    PR["Git Pull Request / Commit Diff"] --> AST["Python AST Analyzer"]
    PR --> Chunker["Markdown Doc Chunker"]
    
    AST -->|"Extracted Symbols, Defaults & Flags"| Matcher["Semantic Candidate Mapper"]
    Chunker -->|"Sentences with File & Line Locations"| Matcher
    
    Matcher --> Heuristic{"Rule Engine (Exact Match?)"}
    Heuristic -->|"Exact Match (Deterministic)"| Report["Drift Finding & Score"]
    Heuristic -->|"Ambiguous Prose Match"| LLM["Qwen 2.5 Coder (Ollama)"]
    LLM --> Report
    
    Report --> Dashboard["Interactive Next.js Dashboard"]
    Report --> Autofix["Automated Markdown Patch (.patch)"]
Loading

πŸš€ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • (Optional, recommended for AI reasoning) Ollama with the app running.

1-Command Dev Environment

Start the backend API, Ollama model check, and Next.js dashboard with a single command:

./scripts/dev.sh

Note: On the first run with Ollama running, the script pulls qwen2.5-coder:3b (~2 GB). If Ollama is not running, scans gracefully fall back to deterministic rules.

Optional: GitHub Login Setup

Login is optional. Without it, you can explore the dashboard and add public repositories by name.

To enable GitHub sign-in and auto-sync for your personal/organization repos:

  1. Create an OAuth App at github.com/settings/developers with the callback URL:
    http://localhost:3000/api/auth/callback
    
  2. Run the helper script and paste the client ID and secret:
    ./scripts/setup-github-login.sh

πŸ› οΈ CLI Usage

You can also run DocGuard directly via CLI to inspect git commits or local branches:

# Run analysis between two git references
python3 backend/src/docguard.py --base HEAD~1 --head HEAD

# Run analysis and automatically apply suggested fixes
python3 backend/src/docguard.py --base HEAD~1 --head HEAD --autofix

πŸ§ͺ Try an Example

We include real-world reproduction cases in the examples/ directory. Run a sample scan on a CLI flag change:

python3 examples/run_example.py

Sample Output:

## πŸ›‘οΈ DocGuard Documentation Intelligence Report
⚠️ Documentation drift detected! (3 issues found)
Repository Documentation Health: 46%

### Issue #1: `--timeout` in `README.md`
Verdict: πŸ”΄ CONFIRMED DRIFT  |  Confidence: 97%
- Source File: cli.py
- Documentation File: README.md (Line 3)

Outdated Statement in Documentation:
> Use --timeout to stop slow jobs.

Why this is incorrect:
Flag '--timeout' was renamed to '--deadline' in cli.py:4, but this sentence still says '--timeout'.

Related Code Diff:
- add_argument("--timeout")
+ add_argument("--deadline")

Suggested Correction:
> Use --deadline to stop slow jobs.

πŸ“‚ Project Structure

DocGuard/
β”œβ”€β”€ .github/workflows/     # CI workflow and DocGuard PR drift detection action
β”œβ”€β”€ action.yml             # Official reusable GitHub Action (Nobody-KnowsBetter/ooli@main)
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ ai/            # Qwen / Ollama and LLM provider interfaces & prompts
β”‚   β”‚   β”œβ”€β”€ analyzer/      # AST comparative parser, doc chunker, and mapper
β”‚   β”‚   β”œβ”€β”€ autofix/       # Patch generator and automated fixer
β”‚   β”‚   β”œβ”€β”€ database/      # SQLite schema and scan persistence
β”‚   β”‚   β”œβ”€β”€ github_auth.py # GitHub OAuth session handler
β”‚   β”‚   β”œβ”€β”€ sync.py        # Background repo sync and PR scanning
β”‚   β”‚   └── main.py        # FastAPI routes, healthcheck, and webhook receiver
β”‚   β”œβ”€β”€ src/               # DocGuard CLI entrypoint (docguard.py)
β”‚   β”œβ”€β”€ Dockerfile         # Production Docker container definition
β”‚   └── requirements.txt   # Python backend dependencies
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/            # Static high-performance marketing landing site
β”‚   β”œβ”€β”€ src/app/dashboard/ # Next.js Maintainer Dashboard (Issues, Autofix, Repositories)
β”‚   └── next.config.js     # API proxy rewrites to backend service
β”œβ”€β”€ examples/              # Sample CLI and config drift test cases
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ dev.sh             # Unified one-command development launcher
β”‚   └── setup-github-login.sh
β”œβ”€β”€ render.yaml            # Render Blueprint deployment definition
└── tests/                 # Unit and end-to-end drift detection tests

πŸ§ͺ Running Tests

To run the complete test suite locally:

python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]" -r backend/requirements.txt
pytest

🀝 How We Work & Contributing

  1. Branch Protection: All changes must go through a feature branch and pull request. Direct pushes to main are blocked.
  2. CI Verification: PRs can only be merged when automated CI tests pass.
  3. Commit Metadata: Every commit message must name the coding agent and models used:
Add tests for URL parser

Coding agent: Claude Code
Models used in project: Qwen 2.5 Coder 3B

πŸ‘₯ Team: Binary Bandits

  • Nitanshu Goyal
  • Mausam Kumar Dwivedi
  • Himank Kaushik
  • Krish Garg

πŸ“„ License

This project is licensed under the MIT License.

About

Automated documentation drift detection powered by AST diffing and Qwen 2.5 Coder. Catches outdated docs, API signature changes, and config drifts in PRs with precise autofixes.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages