ai-doc-gen
AGENTS.md752 starsChanged 4 months agoMITView on GitHub
Multi-agent Python CLI tool that analyzes codebases and generates documentation: .ai/docs/*.md analyses, README.md, and AI assistant config files (CLAUDE.md, AGENTS.md, .cursor/rules/). Setup: cp .env.sample .env (fill in LLM keys), optionally cp config_example.yaml .ai/config.yaml. Tech stack: Python 3.13, pydantic-ai, GitPython, python-gitlab, logfire/OpenTelemetry, Jinja2. Also in this repo: skills/ (Claude Code skills mirroring the agents: analyze-codebase, generate-readme, generate-ai-rules) and .claude-plugin/ (plugin manifest). Keep skill instructions in sync with agent prompt changes. No automated tests. Verify changes manually: Configuration: - Required env vars…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 33,398 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository4 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- .cursor/rules/agent-development.mdcCursor rule
- .cursor/rules/code-patterns.mdcCursor rule
- .cursor/rules/project-overview.mdcCursor rule
The file
We split this AGENTS.md into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 46
Async/await: all agent operations are async
- Distinctive: line 52
No automated tests. Verify changes manually:
- Very specific: line 93
Import errors → uv sync; KeyError on startup → missing required env vars in .env
≈ “Common” is an estimate: at least 1 in 5 of the 43,423 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AI Documentation Generator
Multi-agent Python CLI tool that analyzes codebases and generates documentation: .ai/docs/*.md analyses, README.md, and AI assistant config files (CLAUDE.md, AGENTS.md, .cursor/rules/).
Build & Test
# Install dependencies (Python 3.13 required, <3.14)
uv sync
# Run analysis (writes .ai/docs/*.md)
uv run src/main.py analyze --repo-path .
# Generate README
uv run src/main.py generate readme --repo-path .
# Generate AI assistant config files (CLAUDE.md, AGENTS.md, .cursor/rules/)
uv run src/main.py generate ai-rules --repo-path .
# GitLab batch mode
uv run src/main.py cronjob analyze --max-days-since-last-commit 14
# Format and lint (run both before submitting)
uv run ruff format src/
uv run ruff check src/Setup: cp .env.sample .env (fill in LLM keys), optionally cp config_example.yaml .ai/config.yaml.
Architecture
- Multi-agent system: 5 analysis agents (structure, dependencies, data flow, request flow, API) run through a
WorkerPool(src/utils/worker_pool.py, concurrency fromANALYZER_MAX_WORKERS, 0 = CPU count); 2 AI-rules generators (markdown + cursor) run viaasyncio.gather(return_exceptions=True). - Handler pattern: each CLI command maps to a handler in
src/handlers/implementingAbstractHandler.handle(); handler configs subclassBaseHandlerConfig+ the agent config (e.g.,AnalyzeHandlerConfig(BaseHandlerConfig, AnalyzerAgentConfig)). - Tool-based agents: pydantic-ai agents with
FileReadToolandListFilesTool(src/agents/tools/); prompts are Jinja2 templates insrc/agents/prompts/*.yaml. - Configuration hierarchy: Pydantic defaults →
.ai/config.yaml→ CLI arguments (merge_dicts()); secrets come from.envvia module-level constants insrc/config.py. - LLM providers: OpenAI-compatible only (
OpenAIChatModel+OpenAIProviderwith base URL override). Three env config sets:ANALYZER_LLM_*,DOCUMENTER_LLM_*,AI_RULES_LLM_*(AI_RULES falls back to DOCUMENTER values).
Tech stack: Python 3.13, pydantic-ai, GitPython, python-gitlab, logfire/OpenTelemetry, Jinja2.
Also in this repo: skills/ (Claude Code skills mirroring the agents: analyze-codebase, generate-readme, generate-ai-rules) and .claude-plugin/ (plugin manifest). Keep skill instructions in sync with agent prompt changes.
Code Style
- Formatter/linter: Ruff (120-char lines, 4-space indent,
target-version = "py313", import sorting enabled) - Type hints: Pydantic models for all config/data structures; config classes end in
Config - Async/await: all agent operations are async
- Naming: snake_case files/functions, PascalCase classes,
_privatemethods, UPPER_SNAKE constants - Error handling: graceful degradation — partial success is acceptable; raise
ModelRetryinside tools to trigger pydantic-ai retries; log errors withexc_info=True
Testing
No automated tests. Verify changes manually:
uv run src/main.py analyze --repo-path /path/to/test/repo
uv run src/main.py analyze --repo-path . --exclude-data-flow --exclude-api-analysis
uv run src/main.py generate readme --repo-path . --use-existing-readme
uv run src/main.py generate ai-rules --repo-path . --skip-existing-claude-mdGit Workflow
- Branches:
main(production),feature/*,fix/*,ai-analysis-YYYY-MM-DD(automated) - Commits:
[Category] Brief description— categories:[Feature],[Fix]/[BUGFIX],[Refactor],[Docs],[Config],[AI] - PRs: feature branch → main, run ruff format + check first, squash merge
Key Conventions & Gotchas
Configuration:
- Required env vars (import fails without them):
ANALYZER_LLM_MODEL/BASE_URL/API_KEY,DOCUMENTER_LLM_MODEL/BASE_URL/API_KEY - Config path resolution:
--configflag, else.ai/config.yaml, else.ai/config.yml; missing config returns empty dict (no failure) - Nested YAML keys per command section (e.g.,
readme.exclude_architecture); CLI flags are--exclude-*store_true
Agent execution:
- Individual agent failures are logged but don't stop others; run fails only if ALL agents fail (ValueError)
- Retries:
*_AGENT_RETRIES(default 2) per agent + 5 HTTP retries with exponential backoff (src/utils/retry_client.py, honors Retry-After, retries 429) - Temperature 0.0, max tokens 8192 (16384 for cursor rules), timeouts 180s (240s for ai-rules)
- Absolute paths in agent output are replaced with
.for portability
Tools:
FileReadTool._run(): reads 200 lines by default,line_number/line_countfor ranges; raisesModelRetryon missing files/permission errorsListFilesTool: recursive listing with 100+ ignore patterns
GitLab cronjob:
- Branch
ai-analysis-{YYYY-MM-DD}, commit[AI] Analyzer-Agent: Create/Update AI Analysis [skip ci] - Skips archived projects, stale repos, and projects with existing branch/MR; processes projects sequentially; cleanup in try-finally
Observability:
- Langfuse optional (
ENABLE_LANGFUSE=falseto disable); OpenTelemetry instruments pydantic-ai + httpx - Logs:
.logs/{repo_name}/{YYYY_MM_DD}/{timestamp}.log(file INFO, console WARNING);Logger.init()must run before use (singleton)
Common Issues
- Import errors →
uv sync; KeyError on startup → missing required env vars in.env - Timeouts → raise
ANALYZER_LLM_TIMEOUT/DOCUMENTER_LLM_TIMEOUT/AI_RULES_LLM_TIMEOUT - Rate limiting → handled automatically (backoff + Retry-After); partial analysis → check logs, rerun
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

