Skip to main content

Python companion CLI for bootstrapping the Node-based DocGuard tool in uv-managed projects.

Project description

DocGuard

Early beta — expect rough edges. Documentation-aware pre-commit guard for AI-assisted development.

DocGuard reads your project's markdown docs, looks at staged changes across any text-based language, and blocks commits that contradict the rules you've written down. It is not a linter. It enforces your project's documented intent.

BLOCK services/user_service.py:18  [architecture]
  Direct database call from request handler
  Cited: docs/architecture.md:23
    "All database access must go through the repository layer"

Summary: 1 error(s), 0 warning(s).
Commit blocked. Bypass: git commit --no-verify  or  DOCGUARD_BYPASS=1 git commit

Install

npm install --save-dev @mobasshirkhan/docguard
npx docguard init

For uv-managed Python projects, you can bootstrap from this repo through uvx:

uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard install

That Python helper installs the npm package in the current repo and then runs docguard init. Use --package-manager if you want pnpm, yarn, or bun instead of auto-detecting.

docguard init will:

  • write .docguard.json
  • install a pre-commit hook (Husky-aware, falls back to .git/hooks/)
  • update .gitignore
  • pre-warm the local embedding model (~25 MB one-time download)

You also need a Groq API key (free tier works). Three ways to set it:

.env file in your project root (easiest):

GROQ_API_KEY=gsk_...

DocGuard reads .env from the repo root automatically. Existing shell env vars are not overridden.

Or shell session:

export GROQ_API_KEY=gsk_...

Or system-wide (Windows):

setx GROQ_API_KEY "gsk_..."

Get a key at console.groq.com. Without one, DocGuard skips semantic checks and lets commits through.

Requirements

  • Node >= 18.17
  • Disk: @xenova/transformers adds ~70 MB to node_modules (local embeddings, no per-commit API cost)

Usage

The hook runs automatically on every git commit. To run manually:

docguard check

Bypass:

git commit --no-verify          # standard git escape hatch
DOCGUARD_BYPASS=1 git commit    # explicit, logged to .docguard/bypass.log

Uninstall:

docguard uninstall              # removes hook + cache
docguard uninstall --purge      # also removes .docguard.json

Configuration

.docguard.json:

{
  "docs": ["./docs/**/*.md"],
  "ignore": [
    "**/*.test.*",
    "**/*.spec.*",
    "**/__tests__/**",
    "**/test/**",
    "**/tests/**",
    "**/__pycache__/**",
    "**/.pytest_cache/**",
    "**/node_modules/**",
    "**/.venv/**",
    "**/venv/**",
    "**/vendor/**"
  ],
  "severity": {
    "security":     "block",
    "architecture": "warn",
    "api-contract": "warn",
    "naming":       "warn",
    "style":        "warn"
  },
  "priority": {
    "./docs/architecture.md": "critical"
  },
  "llm": {
    "provider": "groq",
    "model": "llama-3.3-70b-versatile"
  },
  "retrieval": {
    "topK": 6,
    "minScore": 0.15
  },
  "timeoutMs": 5000
}
  • severity — per-category, never per-named-rule. Categories are fixed: security, architecture, api-contract, naming, style.
  • priority — boost retrieval ranking for critical docs.
  • timeoutMs — hard cap on the semantic check. On timeout, commit is allowed.

How it works

  1. Reads staged hunks via git diff --cached.
  2. Splits configured markdown into ≤1500-char chunks by heading.
  3. Embeds chunks locally with MiniLM (@xenova/transformers), cached to .docguard/cache/.
  4. Ranks chunks against the diff by cosine + path overlap + priority.
  5. Sends only the top-relevant chunks plus the diff to Groq for judgment.
  6. Validates the response: every violation must cite a chunk_id with a quote that is a real substring of the chunk. Otherwise it's downgraded to a warning.

DocGuard is language-agnostic at review time: if Git can stage it as text, DocGuard can compare that diff against your docs. The current package runtime is still Node-based, but the repository under review can be Python, Go, Java, Ruby, PHP, Rust, mixed-language monorepos, or anything similar.

For Python and uv users, the companion bootstrap CLI supports:

uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard install
uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard check
uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard uninstall

Trust guarantees

  • No telemetry. Nothing leaves your machine except the redacted diff + relevant doc chunks going to Groq for the semantic check.
  • Citation-or-downgrade. Every blocking violation must reference a real chunk and quote real text. Hallucinated citations are auto-downgraded to warn.
  • DocGuard never blocks on its own bugs. Internal errors fail open (commit proceeds, error logged).
  • Bypass is local, visible, and logged.

Project docs

License

MIT

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

docguard-0.1.1b4.tar.gz (79.7 kB view details)

Uploaded Source

Built Distribution

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

docguard-0.1.1b4-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file docguard-0.1.1b4.tar.gz.

File metadata

  • Download URL: docguard-0.1.1b4.tar.gz
  • Upload date:
  • Size: 79.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docguard-0.1.1b4.tar.gz
Algorithm Hash digest
SHA256 4e02cdb0ce7ef53d4e234bab92a07a4781cf1488eceaeff7b897842ee0077c37
MD5 4c488d115e1d51c4d9b2abaa45dfaca0
BLAKE2b-256 6145358c70fa36b19026ef3192d834d5075536eec81e7efc6ecdf08259600b07

See more details on using hashes here.

Provenance

The following attestation bundles were made for docguard-0.1.1b4.tar.gz:

Publisher: publish-pypi.yml on mobi2400/DocsGuard-

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

File details

Details for the file docguard-0.1.1b4-py3-none-any.whl.

File metadata

  • Download URL: docguard-0.1.1b4-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for docguard-0.1.1b4-py3-none-any.whl
Algorithm Hash digest
SHA256 96554303e2f1f94aaed454cc842e38f984e47881fb3a890a08fbe9028d6c546e
MD5 c2bb36a60c2a0b523f8625ea2532ddc5
BLAKE2b-256 feaa8616d4b4a4f6af6161ef482450d1cc66af26083760f9f6560069408966cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for docguard-0.1.1b4-py3-none-any.whl:

Publisher: publish-pypi.yml on mobi2400/DocsGuard-

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