docguard 0.1.1b4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: docguard
3
+ Version: 0.1.1b4
4
+ Summary: Python companion CLI for bootstrapping the Node-based DocGuard tool in uv-managed projects.
5
+ Author: mobasshir khan
6
+ License: MIT
7
+ License-File: LICENSE
8
+ Keywords: docguard,documentation,git-hooks,pre-commit,uv
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Software Development :: Quality Assurance
19
+ Classifier: Topic :: Software Development :: Version Control :: Git
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+
23
+ # DocGuard
24
+
25
+ > **Early beta — expect rough edges.** Documentation-aware pre-commit guard for AI-assisted development.
26
+
27
+ 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.
28
+
29
+ ```
30
+ BLOCK services/user_service.py:18 [architecture]
31
+ Direct database call from request handler
32
+ Cited: docs/architecture.md:23
33
+ "All database access must go through the repository layer"
34
+
35
+ Summary: 1 error(s), 0 warning(s).
36
+ Commit blocked. Bypass: git commit --no-verify or DOCGUARD_BYPASS=1 git commit
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ npm install --save-dev @mobasshirkhan/docguard
45
+ npx docguard init
46
+ ```
47
+
48
+ For `uv`-managed Python projects, you can bootstrap from this repo through `uvx`:
49
+
50
+ ```bash
51
+ uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard install
52
+ ```
53
+
54
+ 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.
55
+
56
+ `docguard init` will:
57
+
58
+ - write `.docguard.json`
59
+ - install a `pre-commit` hook (Husky-aware, falls back to `.git/hooks/`)
60
+ - update `.gitignore`
61
+ - pre-warm the local embedding model (~25 MB one-time download)
62
+
63
+ You also need a Groq API key (free tier works). Three ways to set it:
64
+
65
+ **`.env` file in your project root (easiest):**
66
+ ```
67
+ GROQ_API_KEY=gsk_...
68
+ ```
69
+ DocGuard reads `.env` from the repo root automatically. Existing shell env vars are not overridden.
70
+
71
+ **Or shell session:**
72
+ ```bash
73
+ export GROQ_API_KEY=gsk_...
74
+ ```
75
+
76
+ **Or system-wide (Windows):**
77
+ ```powershell
78
+ setx GROQ_API_KEY "gsk_..."
79
+ ```
80
+
81
+ Get a key at [console.groq.com](https://console.groq.com). Without one, DocGuard skips semantic checks and lets commits through.
82
+
83
+ ## Requirements
84
+
85
+ - Node `>= 18.17`
86
+ - Disk: `@xenova/transformers` adds ~70 MB to `node_modules` (local embeddings, no per-commit API cost)
87
+
88
+ ## Usage
89
+
90
+ The hook runs automatically on every `git commit`. To run manually:
91
+
92
+ ```bash
93
+ docguard check
94
+ ```
95
+
96
+ Bypass:
97
+
98
+ ```bash
99
+ git commit --no-verify # standard git escape hatch
100
+ DOCGUARD_BYPASS=1 git commit # explicit, logged to .docguard/bypass.log
101
+ ```
102
+
103
+ Uninstall:
104
+
105
+ ```bash
106
+ docguard uninstall # removes hook + cache
107
+ docguard uninstall --purge # also removes .docguard.json
108
+ ```
109
+
110
+ ## Configuration
111
+
112
+ `.docguard.json`:
113
+
114
+ ```json
115
+ {
116
+ "docs": ["./docs/**/*.md"],
117
+ "ignore": [
118
+ "**/*.test.*",
119
+ "**/*.spec.*",
120
+ "**/__tests__/**",
121
+ "**/test/**",
122
+ "**/tests/**",
123
+ "**/__pycache__/**",
124
+ "**/.pytest_cache/**",
125
+ "**/node_modules/**",
126
+ "**/.venv/**",
127
+ "**/venv/**",
128
+ "**/vendor/**"
129
+ ],
130
+ "severity": {
131
+ "security": "block",
132
+ "architecture": "warn",
133
+ "api-contract": "warn",
134
+ "naming": "warn",
135
+ "style": "warn"
136
+ },
137
+ "priority": {
138
+ "./docs/architecture.md": "critical"
139
+ },
140
+ "llm": {
141
+ "provider": "groq",
142
+ "model": "llama-3.3-70b-versatile"
143
+ },
144
+ "retrieval": {
145
+ "topK": 6,
146
+ "minScore": 0.15
147
+ },
148
+ "timeoutMs": 5000
149
+ }
150
+ ```
151
+
152
+ - **severity** — per-category, never per-named-rule. Categories are fixed: `security`, `architecture`, `api-contract`, `naming`, `style`.
153
+ - **priority** — boost retrieval ranking for critical docs.
154
+ - **timeoutMs** — hard cap on the semantic check. On timeout, commit is allowed.
155
+
156
+ ## How it works
157
+
158
+ 1. Reads staged hunks via `git diff --cached`.
159
+ 2. Splits configured markdown into ≤1500-char chunks by heading.
160
+ 3. Embeds chunks locally with MiniLM (`@xenova/transformers`), cached to `.docguard/cache/`.
161
+ 4. Ranks chunks against the diff by cosine + path overlap + priority.
162
+ 5. Sends only the top-relevant chunks plus the diff to Groq for judgment.
163
+ 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.
164
+
165
+ 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.
166
+
167
+ For Python and `uv` users, the companion bootstrap CLI supports:
168
+
169
+ ```bash
170
+ uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard install
171
+ uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard check
172
+ uvx --from git+https://github.com/mobi2400/DocsGuard-.git docguard uninstall
173
+ ```
174
+
175
+ ## Trust guarantees
176
+
177
+ - **No telemetry.** Nothing leaves your machine except the redacted diff + relevant doc chunks going to Groq for the semantic check.
178
+ - **Citation-or-downgrade.** Every blocking violation must reference a real chunk and quote real text. Hallucinated citations are auto-downgraded to warn.
179
+ - **DocGuard never blocks on its own bugs.** Internal errors fail open (commit proceeds, error logged).
180
+ - **Bypass is local, visible, and logged.**
181
+
182
+ ## Project docs
183
+
184
+ - [SPEC.md](SPEC.md) — locked v1 build spec
185
+ - [docguard-v1-phases.md](docguard-v1-phases.md) — phased build plan
186
+ - [docs/explainer.md](docs/explainer.md) — long-form intro
187
+
188
+ ## License
189
+
190
+ MIT
@@ -0,0 +1,7 @@
1
+ docguard_bootstrap/__init__.py,sha256=8jDPfyb6nGA6iu_nbGr7qXemQrFMYmQKo1Wc4u6Lo8w,51
2
+ docguard_bootstrap/cli.py,sha256=B-czBR6cxo6THQv1oI_gww028iPRpocnzcRoktmM0bs,5338
3
+ docguard-0.1.1b4.dist-info/METADATA,sha256=T6adRVKip_fjhdOW6PfwdVD4XDjwHsZBErx6Dlk8qxA,6103
4
+ docguard-0.1.1b4.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
5
+ docguard-0.1.1b4.dist-info/entry_points.txt,sha256=ziUpRy-tWHwHp5rezxGVBGHGdclKobAj1bL3mf6KFAA,139
6
+ docguard-0.1.1b4.dist-info/licenses/LICENSE,sha256=gCW-u3dos3QJR0zXEQTAt1jTZHda6hEmnVmr_Umeh4A,1071
7
+ docguard-0.1.1b4.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.30.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ dg = docguard_bootstrap.cli:main
3
+ docguard = docguard_bootstrap.cli:main
4
+ docguard-bootstrap = docguard_bootstrap.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 mobasshir khan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ __all__ = ["__version__"]
2
+
3
+ __version__ = "0.1.1b4"
@@ -0,0 +1,172 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import shutil
5
+ import subprocess
6
+ import sys
7
+ from pathlib import Path
8
+
9
+ DOCGUARD_NPM_PACKAGE = "@mobasshirkhan/docguard"
10
+
11
+ INSTALL_COMMANDS: dict[str, list[str]] = {
12
+ "npm": ["npm", "install", "--save-dev", DOCGUARD_NPM_PACKAGE],
13
+ "pnpm": ["pnpm", "add", "-D", DOCGUARD_NPM_PACKAGE],
14
+ "yarn": ["yarn", "add", "-D", DOCGUARD_NPM_PACKAGE],
15
+ "bun": ["bun", "add", "-d", DOCGUARD_NPM_PACKAGE],
16
+ }
17
+
18
+ EXEC_COMMANDS: dict[str, list[str]] = {
19
+ "npm": ["npx", "docguard"],
20
+ "pnpm": ["pnpm", "exec", "docguard"],
21
+ "yarn": ["yarn", "exec", "docguard"],
22
+ "bun": ["bunx", "docguard"],
23
+ }
24
+
25
+ PACKAGE_MANAGERS: tuple[str, ...] = ("npm", "pnpm", "yarn", "bun")
26
+
27
+
28
+ def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
29
+ parser = argparse.ArgumentParser(
30
+ prog="docguard",
31
+ description="Bootstrap DocGuard inside a Python or mixed-language repository.",
32
+ )
33
+ parser.add_argument(
34
+ "--cwd",
35
+ default=".",
36
+ help="Repository path to operate on. Defaults to the current working directory.",
37
+ )
38
+ parser.add_argument(
39
+ "--package-manager",
40
+ choices=("auto", *PACKAGE_MANAGERS),
41
+ default="auto",
42
+ help="JavaScript package manager to use for installing and running DocGuard.",
43
+ )
44
+
45
+ subparsers = parser.add_subparsers(dest="command", required=True)
46
+
47
+ install = subparsers.add_parser(
48
+ "install",
49
+ help="Install the npm package and optionally run `docguard init`.",
50
+ )
51
+ install.add_argument(
52
+ "--skip-init",
53
+ action="store_true",
54
+ help="Install DocGuard without running `docguard init`.",
55
+ )
56
+
57
+ subparsers.add_parser("init", help="Run `docguard init` through the selected package manager.")
58
+ subparsers.add_parser("check", help="Run `docguard check` through the selected package manager.")
59
+ uninstall = subparsers.add_parser(
60
+ "uninstall",
61
+ help="Run `docguard uninstall` through the selected package manager.",
62
+ )
63
+ uninstall.add_argument(
64
+ "--purge",
65
+ action="store_true",
66
+ help="Also remove `.docguard.json`.",
67
+ )
68
+
69
+ return parser.parse_args(argv)
70
+
71
+
72
+ def fail(message: str) -> int:
73
+ sys.stderr.write(f"docguard: {message}\n")
74
+ return 1
75
+
76
+
77
+ def detect_package_manager(choice: str) -> str:
78
+ if choice != "auto":
79
+ return choice
80
+
81
+ for manager in PACKAGE_MANAGERS:
82
+ if shutil.which(manager) is not None:
83
+ return manager
84
+
85
+ raise RuntimeError(
86
+ "No supported JavaScript package manager found. Install npm, pnpm, yarn, or bun first."
87
+ )
88
+
89
+
90
+ def ensure_repo(path: Path) -> None:
91
+ if not (path / ".git").exists():
92
+ raise RuntimeError(f"{path} is not a Git repository. Run this inside your project root.")
93
+
94
+
95
+ def ensure_binaries(package_manager: str) -> None:
96
+ missing: list[str] = []
97
+ if shutil.which("node") is None:
98
+ missing.append("node")
99
+ if shutil.which(package_manager) is None:
100
+ missing.append(package_manager)
101
+
102
+ if package_manager == "npm" and shutil.which("npx") is None:
103
+ missing.append("npx")
104
+ if package_manager == "bun" and shutil.which("bunx") is None:
105
+ missing.append("bunx")
106
+
107
+ if missing:
108
+ joined = ", ".join(missing)
109
+ raise RuntimeError(f"Missing required executable(s): {joined}.")
110
+
111
+
112
+ def resolve_command(command: list[str]) -> list[str]:
113
+ executable = shutil.which(command[0])
114
+ if executable is None:
115
+ raise RuntimeError(f"Executable not found: {command[0]}")
116
+ return [executable, *command[1:]]
117
+
118
+
119
+ def run(command: list[str], cwd: Path) -> None:
120
+ completed = subprocess.run(resolve_command(command), cwd=str(cwd), check=False)
121
+ if completed.returncode != 0:
122
+ rendered = " ".join(command)
123
+ raise RuntimeError(f"Command failed with exit code {completed.returncode}: {rendered}")
124
+
125
+
126
+ def exec_docguard(package_manager: str, cwd: Path, *args: str) -> None:
127
+ base = EXEC_COMMANDS[package_manager]
128
+ run([*base, *args], cwd)
129
+
130
+
131
+ def handle_install(package_manager: str, cwd: Path, skip_init: bool) -> int:
132
+ run(INSTALL_COMMANDS[package_manager], cwd)
133
+ if not skip_init:
134
+ exec_docguard(package_manager, cwd, "init")
135
+ return 0
136
+
137
+
138
+ def handle_command(args: argparse.Namespace) -> int:
139
+ cwd = Path(args.cwd).resolve()
140
+ ensure_repo(cwd)
141
+ package_manager = detect_package_manager(args.package_manager)
142
+ ensure_binaries(package_manager)
143
+
144
+ if args.command == "install":
145
+ return handle_install(package_manager, cwd, args.skip_init)
146
+ if args.command == "init":
147
+ exec_docguard(package_manager, cwd, "init")
148
+ return 0
149
+ if args.command == "check":
150
+ exec_docguard(package_manager, cwd, "check")
151
+ return 0
152
+ if args.command == "uninstall":
153
+ uninstall_args = ["uninstall"]
154
+ if args.purge:
155
+ uninstall_args.append("--purge")
156
+ exec_docguard(package_manager, cwd, *uninstall_args)
157
+ return 0
158
+ return fail(f"Unsupported command: {args.command}")
159
+
160
+
161
+ def main(argv: list[str] | None = None) -> int:
162
+ args = parse_args(argv)
163
+ try:
164
+ return handle_command(args)
165
+ except RuntimeError as err:
166
+ return fail(str(err))
167
+ except KeyboardInterrupt:
168
+ return fail("Interrupted.")
169
+
170
+
171
+ if __name__ == "__main__":
172
+ raise SystemExit(main())