iil-docs-agent 0.2.0__tar.gz
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.
- iil_docs_agent-0.2.0/.github/workflows/ci-docs-agent.yml +42 -0
- iil_docs_agent-0.2.0/.gitignore +50 -0
- iil_docs_agent-0.2.0/.pre-commit-hooks.yaml +17 -0
- iil_docs_agent-0.2.0/PKG-INFO +214 -0
- iil_docs_agent-0.2.0/README.md +195 -0
- iil_docs_agent-0.2.0/docs/Makefile +12 -0
- iil_docs_agent-0.2.0/docs/api/analyzer.rst +38 -0
- iil_docs_agent-0.2.0/docs/api/cli.rst +9 -0
- iil_docs_agent-0.2.0/docs/api/generator.rst +30 -0
- iil_docs_agent-0.2.0/docs/api/llm_client.rst +15 -0
- iil_docs_agent-0.2.0/docs/api/models.rst +29 -0
- iil_docs_agent-0.2.0/docs/api/prompts.rst +21 -0
- iil_docs_agent-0.2.0/docs/architecture.rst +105 -0
- iil_docs_agent-0.2.0/docs/changelog.rst +38 -0
- iil_docs_agent-0.2.0/docs/cli.rst +117 -0
- iil_docs_agent-0.2.0/docs/conf.py +38 -0
- iil_docs_agent-0.2.0/docs/configuration.rst +79 -0
- iil_docs_agent-0.2.0/docs/index.rst +47 -0
- iil_docs_agent-0.2.0/docs/integration.rst +114 -0
- iil_docs_agent-0.2.0/docs/quickstart.rst +97 -0
- iil_docs_agent-0.2.0/pyproject.toml +44 -0
- iil_docs_agent-0.2.0/src/docs_agent/__init__.py +7 -0
- iil_docs_agent-0.2.0/src/docs_agent/analyzer/__init__.py +1 -0
- iil_docs_agent-0.2.0/src/docs_agent/analyzer/ast_scanner.py +231 -0
- iil_docs_agent-0.2.0/src/docs_agent/analyzer/diataxis_classifier.py +206 -0
- iil_docs_agent-0.2.0/src/docs_agent/analyzer/llm_classifier.py +149 -0
- iil_docs_agent-0.2.0/src/docs_agent/cli.py +454 -0
- iil_docs_agent-0.2.0/src/docs_agent/generator/__init__.py +1 -0
- iil_docs_agent-0.2.0/src/docs_agent/generator/code_inserter.py +230 -0
- iil_docs_agent-0.2.0/src/docs_agent/generator/docstring_gen.py +216 -0
- iil_docs_agent-0.2.0/src/docs_agent/llm_client.py +181 -0
- iil_docs_agent-0.2.0/src/docs_agent/models.py +99 -0
- iil_docs_agent-0.2.0/src/docs_agent/prompts.py +77 -0
- iil_docs_agent-0.2.0/tests/__init__.py +0 -0
- iil_docs_agent-0.2.0/tests/test_ast_scanner.py +175 -0
- iil_docs_agent-0.2.0/tests/test_code_inserter.py +119 -0
- iil_docs_agent-0.2.0/tests/test_diataxis_classifier.py +130 -0
- iil_docs_agent-0.2.0/tests/test_llm_classifier.py +191 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: Docs Agent CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths:
|
|
7
|
+
- "packages/docs-agent/**"
|
|
8
|
+
pull_request:
|
|
9
|
+
branches: [main]
|
|
10
|
+
paths:
|
|
11
|
+
- "packages/docs-agent/**"
|
|
12
|
+
|
|
13
|
+
concurrency:
|
|
14
|
+
group: docs-agent-${{ github.ref }}
|
|
15
|
+
cancel-in-progress: true
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
test:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
defaults:
|
|
21
|
+
run:
|
|
22
|
+
working-directory: packages/docs-agent
|
|
23
|
+
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
|
|
27
|
+
- uses: actions/setup-python@v5
|
|
28
|
+
with:
|
|
29
|
+
python-version: "3.12"
|
|
30
|
+
|
|
31
|
+
- name: Install dependencies
|
|
32
|
+
run: |
|
|
33
|
+
python -m pip install --upgrade pip
|
|
34
|
+
pip install typer rich pytest pytest-cov libcst
|
|
35
|
+
|
|
36
|
+
- name: Run tests
|
|
37
|
+
run: |
|
|
38
|
+
python -m pytest tests/ -v --tb=short
|
|
39
|
+
|
|
40
|
+
- name: Smoke test CLI
|
|
41
|
+
run: |
|
|
42
|
+
PYTHONPATH=src python -m docs_agent.cli audit ../../ --scope docstrings --output json
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*\.class
|
|
5
|
+
.venv/
|
|
6
|
+
venv/
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
# Django
|
|
11
|
+
*.log
|
|
12
|
+
db.sqlite3
|
|
13
|
+
media/
|
|
14
|
+
staticfiles/
|
|
15
|
+
# Environment
|
|
16
|
+
.env
|
|
17
|
+
.env.local
|
|
18
|
+
.env.prod
|
|
19
|
+
|
|
20
|
+
# Secrets (ADR-045) — NEVER commit plaintext
|
|
21
|
+
secrets.env
|
|
22
|
+
!secrets.enc.env
|
|
23
|
+
# IDE
|
|
24
|
+
.idea/
|
|
25
|
+
.vscode/
|
|
26
|
+
*.swp
|
|
27
|
+
# OS
|
|
28
|
+
.DS_Store
|
|
29
|
+
Thumbs.db
|
|
30
|
+
# Large files
|
|
31
|
+
*.sqlite3
|
|
32
|
+
*.log
|
|
33
|
+
output_batch/
|
|
34
|
+
app_backup/
|
|
35
|
+
docs_legacy/
|
|
36
|
+
# Sphinx build output
|
|
37
|
+
docs/_build/
|
|
38
|
+
*:Zone.Identifier
|
|
39
|
+
# Local Windsurf/MCP config — machine-specific, never commit
|
|
40
|
+
.windsurf/mcp_config.json
|
|
41
|
+
# Local infra plaintext secrets — NEVER commit
|
|
42
|
+
infra/*.env
|
|
43
|
+
infra/*.key
|
|
44
|
+
# Validate-ports CI draft (not yet integrated)
|
|
45
|
+
.github/workflows/validate-ports.yml
|
|
46
|
+
# Markdownlint local config override
|
|
47
|
+
.markdownlint.json
|
|
48
|
+
# Concept review drafts (local working copies, not for VCS)
|
|
49
|
+
docs/concepts/REVIEW-*
|
|
50
|
+
env_loader.py
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
- id: docs-agent-coverage
|
|
2
|
+
name: docs-agent docstring coverage
|
|
3
|
+
description: Check docstring coverage meets minimum threshold
|
|
4
|
+
entry: docs-agent audit --scope docstrings --output table
|
|
5
|
+
language: python
|
|
6
|
+
types: [python]
|
|
7
|
+
pass_filenames: false
|
|
8
|
+
additional_dependencies: ["typer>=0.12.0", "rich>=13.0.0"]
|
|
9
|
+
|
|
10
|
+
- id: docs-agent-coverage-strict
|
|
11
|
+
name: docs-agent coverage (strict)
|
|
12
|
+
description: Fail if docstring coverage is below 50%
|
|
13
|
+
entry: docs-agent audit --scope docstrings --min-coverage 50
|
|
14
|
+
language: python
|
|
15
|
+
types: [python]
|
|
16
|
+
pass_filenames: false
|
|
17
|
+
additional_dependencies: ["typer>=0.12.0", "rich>=13.0.0"]
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: iil-docs-agent
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: AI-assisted documentation quality agent — AST scanner, DIATAXIS classifier, CLI
|
|
5
|
+
Author: Achim Dehnert
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: rich>=13.0.0
|
|
9
|
+
Requires-Dist: typer>=0.12.0
|
|
10
|
+
Provides-Extra: dev
|
|
11
|
+
Requires-Dist: libcst>=1.1.0; extra == 'dev'
|
|
12
|
+
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
14
|
+
Provides-Extra: llm
|
|
15
|
+
Requires-Dist: httpx>=0.27.0; extra == 'llm'
|
|
16
|
+
Requires-Dist: libcst>=1.1.0; extra == 'llm'
|
|
17
|
+
Requires-Dist: openai>=1.0.0; extra == 'llm'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# Docs Agent
|
|
21
|
+
|
|
22
|
+
AI-assisted documentation quality tool for Python projects.
|
|
23
|
+
|
|
24
|
+
Scans codebases for docstring coverage, classifies documentation files using the
|
|
25
|
+
[DIATAXIS framework](https://diataxis.fr/), and generates missing docstrings via LLM.
|
|
26
|
+
|
|
27
|
+
## Features
|
|
28
|
+
|
|
29
|
+
- **Docstring Coverage Audit** — AST-based scanning of Python files with per-module reporting
|
|
30
|
+
- **DIATAXIS Classification** — Heuristic + LLM-powered classification of docs into tutorial/guide/reference/explanation
|
|
31
|
+
- **LLM Docstring Generation** — Batch generation of Google-style docstrings via llm_mcp gateway or OpenAI API
|
|
32
|
+
- **Non-Destructive Code Insertion** — Insert generated docstrings using libcst while preserving all formatting
|
|
33
|
+
- **Pre-Commit Hooks** — Enforce coverage thresholds in CI/CD pipelines
|
|
34
|
+
- **CI Integration** — GitHub Actions workflow for automated testing
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
# From platform monorepo (editable, recommended)
|
|
40
|
+
pip install -e packages/docs-agent
|
|
41
|
+
|
|
42
|
+
# With LLM support (httpx, openai, libcst)
|
|
43
|
+
pip install -e "packages/docs-agent[llm]"
|
|
44
|
+
|
|
45
|
+
# With dev tools (pytest, coverage)
|
|
46
|
+
pip install -e "packages/docs-agent[dev]"
|
|
47
|
+
|
|
48
|
+
# From GitHub (in requirements.txt)
|
|
49
|
+
docs-agent @ git+https://github.com/achimdehnert/platform.git@main#subdirectory=packages/docs-agent
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick Start
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Audit docstring coverage
|
|
56
|
+
docs-agent audit /path/to/repo
|
|
57
|
+
|
|
58
|
+
# Audit only apps/ directory
|
|
59
|
+
docs-agent audit /path/to/repo --apps-only
|
|
60
|
+
|
|
61
|
+
# JSON output for CI
|
|
62
|
+
docs-agent audit /path/to/repo --output json
|
|
63
|
+
|
|
64
|
+
# Fail if coverage < 60%
|
|
65
|
+
docs-agent audit /path/to/repo --min-coverage 60
|
|
66
|
+
|
|
67
|
+
# DIATAXIS only
|
|
68
|
+
docs-agent audit /path/to/repo --scope diataxis
|
|
69
|
+
|
|
70
|
+
# Refine low-confidence classifications via LLM
|
|
71
|
+
docs-agent audit /path/to/repo --scope diataxis --refine
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## CLI Reference
|
|
75
|
+
|
|
76
|
+
### `docs-agent audit`
|
|
77
|
+
|
|
78
|
+
Audit a repository for documentation quality.
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
Usage: docs-agent audit [OPTIONS] REPO_PATH
|
|
82
|
+
|
|
83
|
+
Arguments:
|
|
84
|
+
REPO_PATH Path to the repository root [required]
|
|
85
|
+
|
|
86
|
+
Options:
|
|
87
|
+
--scope TEXT Audit scope: docstrings, diataxis, or all [default: all]
|
|
88
|
+
--apps-only Only scan apps/ directory for docstrings
|
|
89
|
+
--min-coverage FLOAT Fail if docstring coverage is below this %
|
|
90
|
+
--output TEXT Output format: table or json [default: table]
|
|
91
|
+
--refine Use LLM to refine low-confidence DIATAXIS classifications
|
|
92
|
+
--llm-url TEXT URL of the llm_mcp HTTP gateway [default: http://localhost:8100]
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### `docs-agent generate`
|
|
96
|
+
|
|
97
|
+
Generate docstrings for undocumented code items via LLM.
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
Usage: docs-agent generate [OPTIONS] REPO_PATH
|
|
101
|
+
|
|
102
|
+
Arguments:
|
|
103
|
+
REPO_PATH Path to the repository root [required]
|
|
104
|
+
|
|
105
|
+
Options:
|
|
106
|
+
--apps-only Only scan apps/ directory
|
|
107
|
+
--dry-run / --apply Preview changes (default) or apply them
|
|
108
|
+
--max-items INTEGER Maximum items to generate docstrings for [default: 20]
|
|
109
|
+
--llm-url TEXT URL of the llm_mcp HTTP gateway [default: http://localhost:8100]
|
|
110
|
+
--model TEXT LLM model name [default: gpt-4o-mini]
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Example Output
|
|
114
|
+
|
|
115
|
+
### Docstring Coverage Table
|
|
116
|
+
|
|
117
|
+
```text
|
|
118
|
+
Module Coverage
|
|
119
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
|
|
120
|
+
┃ Module ┃ Items ┃ Documented ┃ Coverage ┃
|
|
121
|
+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╉━━━━━━━╉━━━━━━━━━━━━╉━━━━━━━━━━┩
|
|
122
|
+
│ apps/core/models.py │ 12 │ 8 │ 67% │
|
|
123
|
+
│ apps/core/services.py │ 6 │ 6 │ 100% │
|
|
124
|
+
│ apps/core/views.py │ 9 │ 3 │ 33% │
|
|
125
|
+
└───────────────────────────────┴───────┴────────────┴──────────┘
|
|
126
|
+
|
|
127
|
+
Total: 17/27 items documented (63.0%)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### DIATAXIS Classification
|
|
131
|
+
|
|
132
|
+
```text
|
|
133
|
+
DIATAXIS Classification
|
|
134
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
|
|
135
|
+
┃ Document ┃ Quadrant ┃ Confidence ┃
|
|
136
|
+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╉━━━━━━━━━━━━━╉━━━━━━━━━━━━┩
|
|
137
|
+
│ docs/getting-started.md │ tutorial │ 85% │
|
|
138
|
+
│ docs/deploy-guide.md │ guide │ 72% │
|
|
139
|
+
│ docs/api-reference.md │ reference │ 90% │
|
|
140
|
+
│ docs/adr/ADR-001.md │ explanation │ 78% │
|
|
141
|
+
└─────────────────────────────┴─────────────┴────────────┘
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Pre-Commit Integration
|
|
145
|
+
|
|
146
|
+
Add to your `.pre-commit-config.yaml`:
|
|
147
|
+
|
|
148
|
+
```yaml
|
|
149
|
+
repos:
|
|
150
|
+
- repo: https://github.com/achimdehnert/platform
|
|
151
|
+
rev: main
|
|
152
|
+
hooks:
|
|
153
|
+
- id: docs-agent-coverage
|
|
154
|
+
args: ["--scope", "docstrings", "--min-coverage", "50"]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Architecture
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
docs_agent/
|
|
161
|
+
├── analyzer/
|
|
162
|
+
│ ├── ast_scanner.py # AST-based docstring coverage scanning
|
|
163
|
+
│ ├── diataxis_classifier.py # Heuristic DIATAXIS classification
|
|
164
|
+
│ └── llm_classifier.py # LLM fallback for low-confidence docs
|
|
165
|
+
├── generator/
|
|
166
|
+
│ ├── docstring_gen.py # Batch LLM docstring generation
|
|
167
|
+
│ └── code_inserter.py # Non-destructive libcst insertion
|
|
168
|
+
├── cli.py # Typer CLI (audit + generate commands)
|
|
169
|
+
├── llm_client.py # HTTP gateway + OpenAI fallback
|
|
170
|
+
├── models.py # Data models (CodeItem, Coverage, etc.)
|
|
171
|
+
└── prompts.py # LLM prompt templates
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Configuration
|
|
175
|
+
|
|
176
|
+
### Environment Variables
|
|
177
|
+
|
|
178
|
+
| Variable | Default | Description |
|
|
179
|
+
| --- | --- | --- |
|
|
180
|
+
| `DOCS_AGENT_LLM_URL` | `http://localhost:8100` | llm_mcp gateway URL |
|
|
181
|
+
| `DOCS_AGENT_LLM_MODEL` | `gpt-4o-mini` | LLM model name |
|
|
182
|
+
| `OPENAI_API_KEY` | — | Direct OpenAI fallback (optional) |
|
|
183
|
+
|
|
184
|
+
### LLM Backend
|
|
185
|
+
|
|
186
|
+
The docs-agent tries backends in this order:
|
|
187
|
+
|
|
188
|
+
1. **llm_mcp HTTP gateway** (default, `http://localhost:8100`) — production setup
|
|
189
|
+
2. **Direct OpenAI API** — fallback if gateway is down and `OPENAI_API_KEY` is set
|
|
190
|
+
|
|
191
|
+
## Development
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
cd packages/docs-agent
|
|
195
|
+
|
|
196
|
+
# Install with dev + LLM extras
|
|
197
|
+
pip install -e ".[dev,llm]"
|
|
198
|
+
|
|
199
|
+
# Run tests
|
|
200
|
+
pytest tests/ -v
|
|
201
|
+
|
|
202
|
+
# Run with coverage
|
|
203
|
+
pytest tests/ --cov=docs_agent --cov-report=term-missing
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Related
|
|
207
|
+
|
|
208
|
+
- **ADR-046**: Documentation Quality Standards (defines the docs-agent specification)
|
|
209
|
+
- **DIATAXIS**: <https://diataxis.fr/> — Documentation framework
|
|
210
|
+
- **Platform**: <https://github.com/achimdehnert/platform> — Monorepo
|
|
211
|
+
|
|
212
|
+
## License
|
|
213
|
+
|
|
214
|
+
MIT
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
# Docs Agent
|
|
2
|
+
|
|
3
|
+
AI-assisted documentation quality tool for Python projects.
|
|
4
|
+
|
|
5
|
+
Scans codebases for docstring coverage, classifies documentation files using the
|
|
6
|
+
[DIATAXIS framework](https://diataxis.fr/), and generates missing docstrings via LLM.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Docstring Coverage Audit** — AST-based scanning of Python files with per-module reporting
|
|
11
|
+
- **DIATAXIS Classification** — Heuristic + LLM-powered classification of docs into tutorial/guide/reference/explanation
|
|
12
|
+
- **LLM Docstring Generation** — Batch generation of Google-style docstrings via llm_mcp gateway or OpenAI API
|
|
13
|
+
- **Non-Destructive Code Insertion** — Insert generated docstrings using libcst while preserving all formatting
|
|
14
|
+
- **Pre-Commit Hooks** — Enforce coverage thresholds in CI/CD pipelines
|
|
15
|
+
- **CI Integration** — GitHub Actions workflow for automated testing
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# From platform monorepo (editable, recommended)
|
|
21
|
+
pip install -e packages/docs-agent
|
|
22
|
+
|
|
23
|
+
# With LLM support (httpx, openai, libcst)
|
|
24
|
+
pip install -e "packages/docs-agent[llm]"
|
|
25
|
+
|
|
26
|
+
# With dev tools (pytest, coverage)
|
|
27
|
+
pip install -e "packages/docs-agent[dev]"
|
|
28
|
+
|
|
29
|
+
# From GitHub (in requirements.txt)
|
|
30
|
+
docs-agent @ git+https://github.com/achimdehnert/platform.git@main#subdirectory=packages/docs-agent
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
# Audit docstring coverage
|
|
37
|
+
docs-agent audit /path/to/repo
|
|
38
|
+
|
|
39
|
+
# Audit only apps/ directory
|
|
40
|
+
docs-agent audit /path/to/repo --apps-only
|
|
41
|
+
|
|
42
|
+
# JSON output for CI
|
|
43
|
+
docs-agent audit /path/to/repo --output json
|
|
44
|
+
|
|
45
|
+
# Fail if coverage < 60%
|
|
46
|
+
docs-agent audit /path/to/repo --min-coverage 60
|
|
47
|
+
|
|
48
|
+
# DIATAXIS only
|
|
49
|
+
docs-agent audit /path/to/repo --scope diataxis
|
|
50
|
+
|
|
51
|
+
# Refine low-confidence classifications via LLM
|
|
52
|
+
docs-agent audit /path/to/repo --scope diataxis --refine
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## CLI Reference
|
|
56
|
+
|
|
57
|
+
### `docs-agent audit`
|
|
58
|
+
|
|
59
|
+
Audit a repository for documentation quality.
|
|
60
|
+
|
|
61
|
+
```text
|
|
62
|
+
Usage: docs-agent audit [OPTIONS] REPO_PATH
|
|
63
|
+
|
|
64
|
+
Arguments:
|
|
65
|
+
REPO_PATH Path to the repository root [required]
|
|
66
|
+
|
|
67
|
+
Options:
|
|
68
|
+
--scope TEXT Audit scope: docstrings, diataxis, or all [default: all]
|
|
69
|
+
--apps-only Only scan apps/ directory for docstrings
|
|
70
|
+
--min-coverage FLOAT Fail if docstring coverage is below this %
|
|
71
|
+
--output TEXT Output format: table or json [default: table]
|
|
72
|
+
--refine Use LLM to refine low-confidence DIATAXIS classifications
|
|
73
|
+
--llm-url TEXT URL of the llm_mcp HTTP gateway [default: http://localhost:8100]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### `docs-agent generate`
|
|
77
|
+
|
|
78
|
+
Generate docstrings for undocumented code items via LLM.
|
|
79
|
+
|
|
80
|
+
```text
|
|
81
|
+
Usage: docs-agent generate [OPTIONS] REPO_PATH
|
|
82
|
+
|
|
83
|
+
Arguments:
|
|
84
|
+
REPO_PATH Path to the repository root [required]
|
|
85
|
+
|
|
86
|
+
Options:
|
|
87
|
+
--apps-only Only scan apps/ directory
|
|
88
|
+
--dry-run / --apply Preview changes (default) or apply them
|
|
89
|
+
--max-items INTEGER Maximum items to generate docstrings for [default: 20]
|
|
90
|
+
--llm-url TEXT URL of the llm_mcp HTTP gateway [default: http://localhost:8100]
|
|
91
|
+
--model TEXT LLM model name [default: gpt-4o-mini]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Example Output
|
|
95
|
+
|
|
96
|
+
### Docstring Coverage Table
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
Module Coverage
|
|
100
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓
|
|
101
|
+
┃ Module ┃ Items ┃ Documented ┃ Coverage ┃
|
|
102
|
+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╉━━━━━━━╉━━━━━━━━━━━━╉━━━━━━━━━━┩
|
|
103
|
+
│ apps/core/models.py │ 12 │ 8 │ 67% │
|
|
104
|
+
│ apps/core/services.py │ 6 │ 6 │ 100% │
|
|
105
|
+
│ apps/core/views.py │ 9 │ 3 │ 33% │
|
|
106
|
+
└───────────────────────────────┴───────┴────────────┴──────────┘
|
|
107
|
+
|
|
108
|
+
Total: 17/27 items documented (63.0%)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### DIATAXIS Classification
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
DIATAXIS Classification
|
|
115
|
+
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
|
|
116
|
+
┃ Document ┃ Quadrant ┃ Confidence ┃
|
|
117
|
+
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╉━━━━━━━━━━━━━╉━━━━━━━━━━━━┩
|
|
118
|
+
│ docs/getting-started.md │ tutorial │ 85% │
|
|
119
|
+
│ docs/deploy-guide.md │ guide │ 72% │
|
|
120
|
+
│ docs/api-reference.md │ reference │ 90% │
|
|
121
|
+
│ docs/adr/ADR-001.md │ explanation │ 78% │
|
|
122
|
+
└─────────────────────────────┴─────────────┴────────────┘
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Pre-Commit Integration
|
|
126
|
+
|
|
127
|
+
Add to your `.pre-commit-config.yaml`:
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
repos:
|
|
131
|
+
- repo: https://github.com/achimdehnert/platform
|
|
132
|
+
rev: main
|
|
133
|
+
hooks:
|
|
134
|
+
- id: docs-agent-coverage
|
|
135
|
+
args: ["--scope", "docstrings", "--min-coverage", "50"]
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Architecture
|
|
139
|
+
|
|
140
|
+
```text
|
|
141
|
+
docs_agent/
|
|
142
|
+
├── analyzer/
|
|
143
|
+
│ ├── ast_scanner.py # AST-based docstring coverage scanning
|
|
144
|
+
│ ├── diataxis_classifier.py # Heuristic DIATAXIS classification
|
|
145
|
+
│ └── llm_classifier.py # LLM fallback for low-confidence docs
|
|
146
|
+
├── generator/
|
|
147
|
+
│ ├── docstring_gen.py # Batch LLM docstring generation
|
|
148
|
+
│ └── code_inserter.py # Non-destructive libcst insertion
|
|
149
|
+
├── cli.py # Typer CLI (audit + generate commands)
|
|
150
|
+
├── llm_client.py # HTTP gateway + OpenAI fallback
|
|
151
|
+
├── models.py # Data models (CodeItem, Coverage, etc.)
|
|
152
|
+
└── prompts.py # LLM prompt templates
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Configuration
|
|
156
|
+
|
|
157
|
+
### Environment Variables
|
|
158
|
+
|
|
159
|
+
| Variable | Default | Description |
|
|
160
|
+
| --- | --- | --- |
|
|
161
|
+
| `DOCS_AGENT_LLM_URL` | `http://localhost:8100` | llm_mcp gateway URL |
|
|
162
|
+
| `DOCS_AGENT_LLM_MODEL` | `gpt-4o-mini` | LLM model name |
|
|
163
|
+
| `OPENAI_API_KEY` | — | Direct OpenAI fallback (optional) |
|
|
164
|
+
|
|
165
|
+
### LLM Backend
|
|
166
|
+
|
|
167
|
+
The docs-agent tries backends in this order:
|
|
168
|
+
|
|
169
|
+
1. **llm_mcp HTTP gateway** (default, `http://localhost:8100`) — production setup
|
|
170
|
+
2. **Direct OpenAI API** — fallback if gateway is down and `OPENAI_API_KEY` is set
|
|
171
|
+
|
|
172
|
+
## Development
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
cd packages/docs-agent
|
|
176
|
+
|
|
177
|
+
# Install with dev + LLM extras
|
|
178
|
+
pip install -e ".[dev,llm]"
|
|
179
|
+
|
|
180
|
+
# Run tests
|
|
181
|
+
pytest tests/ -v
|
|
182
|
+
|
|
183
|
+
# Run with coverage
|
|
184
|
+
pytest tests/ --cov=docs_agent --cov-report=term-missing
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Related
|
|
188
|
+
|
|
189
|
+
- **ADR-046**: Documentation Quality Standards (defines the docs-agent specification)
|
|
190
|
+
- **DIATAXIS**: <https://diataxis.fr/> — Documentation framework
|
|
191
|
+
- **Platform**: <https://github.com/achimdehnert/platform> — Monorepo
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
SPHINXOPTS ?=
|
|
2
|
+
SPHINXBUILD ?= sphinx-build
|
|
3
|
+
SOURCEDIR = .
|
|
4
|
+
BUILDDIR = _build
|
|
5
|
+
|
|
6
|
+
help:
|
|
7
|
+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
8
|
+
|
|
9
|
+
.PHONY: help Makefile
|
|
10
|
+
|
|
11
|
+
%: Makefile
|
|
12
|
+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Analyzer
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
AST Scanner
|
|
5
|
+
-----------
|
|
6
|
+
|
|
7
|
+
.. module:: docs_agent.analyzer.ast_scanner
|
|
8
|
+
:synopsis: AST-based docstring coverage scanning.
|
|
9
|
+
|
|
10
|
+
.. autofunction:: scan_repo
|
|
11
|
+
|
|
12
|
+
.. autofunction:: scan_module
|
|
13
|
+
|
|
14
|
+
DIATAXIS Classifier (Heuristic)
|
|
15
|
+
-------------------------------
|
|
16
|
+
|
|
17
|
+
.. module:: docs_agent.analyzer.diataxis_classifier
|
|
18
|
+
:synopsis: Heuristic DIATAXIS classification via trigger words.
|
|
19
|
+
|
|
20
|
+
.. autofunction:: classify_file
|
|
21
|
+
|
|
22
|
+
.. autofunction:: classify_repo
|
|
23
|
+
|
|
24
|
+
.. autodata:: DOC_EXTENSIONS
|
|
25
|
+
|
|
26
|
+
.. autodata:: SKIP_DIRS
|
|
27
|
+
|
|
28
|
+
DIATAXIS Classifier (LLM)
|
|
29
|
+
--------------------------
|
|
30
|
+
|
|
31
|
+
.. module:: docs_agent.analyzer.llm_classifier
|
|
32
|
+
:synopsis: LLM-based fallback classifier for low-confidence documents.
|
|
33
|
+
|
|
34
|
+
.. autofunction:: reclassify_low_confidence
|
|
35
|
+
|
|
36
|
+
.. autodata:: DEFAULT_THRESHOLD
|
|
37
|
+
|
|
38
|
+
.. autodata:: PREVIEW_CHARS
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Generator
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
Docstring Generator
|
|
5
|
+
-------------------
|
|
6
|
+
|
|
7
|
+
.. module:: docs_agent.generator.docstring_gen
|
|
8
|
+
:synopsis: LLM-based batch docstring generation.
|
|
9
|
+
|
|
10
|
+
.. autoclass:: GeneratedDocstring
|
|
11
|
+
:members:
|
|
12
|
+
:undoc-members:
|
|
13
|
+
|
|
14
|
+
.. autofunction:: generate_docstrings
|
|
15
|
+
|
|
16
|
+
.. autodata:: BATCH_SIZE
|
|
17
|
+
|
|
18
|
+
Code Inserter
|
|
19
|
+
-------------
|
|
20
|
+
|
|
21
|
+
.. module:: docs_agent.generator.code_inserter
|
|
22
|
+
:synopsis: Non-destructive docstring insertion via libcst.
|
|
23
|
+
|
|
24
|
+
.. autoclass:: InsertionResult
|
|
25
|
+
:members:
|
|
26
|
+
:undoc-members:
|
|
27
|
+
|
|
28
|
+
.. autofunction:: insert_docstrings
|
|
29
|
+
|
|
30
|
+
.. autodata:: MODULE_DOCSTRING_KEY
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
LLM Client
|
|
2
|
+
==========
|
|
3
|
+
|
|
4
|
+
.. module:: docs_agent.llm_client
|
|
5
|
+
:synopsis: Async LLM client with HTTP gateway and OpenAI fallback.
|
|
6
|
+
|
|
7
|
+
.. autoclass:: LLMConfig
|
|
8
|
+
:members:
|
|
9
|
+
:undoc-members:
|
|
10
|
+
|
|
11
|
+
.. autoclass:: LLMResponse
|
|
12
|
+
:members:
|
|
13
|
+
:undoc-members:
|
|
14
|
+
|
|
15
|
+
.. autofunction:: generate
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Data Models
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
.. module:: docs_agent.models
|
|
5
|
+
:synopsis: Data models for docs-agent analysis results.
|
|
6
|
+
|
|
7
|
+
.. autoclass:: ItemKind
|
|
8
|
+
:members:
|
|
9
|
+
:undoc-members:
|
|
10
|
+
|
|
11
|
+
.. autoclass:: DiaxisQuadrant
|
|
12
|
+
:members:
|
|
13
|
+
:undoc-members:
|
|
14
|
+
|
|
15
|
+
.. autoclass:: CodeItem
|
|
16
|
+
:members:
|
|
17
|
+
:undoc-members:
|
|
18
|
+
|
|
19
|
+
.. autoclass:: ModuleCoverage
|
|
20
|
+
:members:
|
|
21
|
+
:undoc-members:
|
|
22
|
+
|
|
23
|
+
.. autoclass:: RepoCoverage
|
|
24
|
+
:members:
|
|
25
|
+
:undoc-members:
|
|
26
|
+
|
|
27
|
+
.. autoclass:: DiaxisClassification
|
|
28
|
+
:members:
|
|
29
|
+
:undoc-members:
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Prompt Templates
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
.. module:: docs_agent.prompts
|
|
5
|
+
:synopsis: LLM prompt templates for docstring generation and DIATAXIS classification.
|
|
6
|
+
|
|
7
|
+
Docstring Generation
|
|
8
|
+
--------------------
|
|
9
|
+
|
|
10
|
+
.. autodata:: SYSTEM_DOCSTRING
|
|
11
|
+
|
|
12
|
+
.. autodata:: PROMPT_DOCSTRING_SINGLE
|
|
13
|
+
|
|
14
|
+
.. autodata:: PROMPT_DOCSTRING_BATCH
|
|
15
|
+
|
|
16
|
+
DIATAXIS Classification
|
|
17
|
+
-----------------------
|
|
18
|
+
|
|
19
|
+
.. autodata:: SYSTEM_DIATAXIS
|
|
20
|
+
|
|
21
|
+
.. autodata:: PROMPT_DIATAXIS_CLASSIFY
|