infrastructure-doctor
Skill for the doctor infrastructure module providing repository-level diagnostics and safe, reversible automated repair. Use when the local checkout is acting up, before opening a bug, when onboarding a fresh clone, or as a periodic health probe. Every mutation is backed up under .doctor/backups/ and journalled in .doctor/actions.jsonl so any change can be undone byte-for-byte.
Best use case
infrastructure-doctor is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Skill for the doctor infrastructure module providing repository-level diagnostics and safe, reversible automated repair. Use when the local checkout is acting up, before opening a bug, when onboarding a fresh clone, or as a periodic health probe. Every mutation is backed up under .doctor/backups/ and journalled in .doctor/actions.jsonl so any change can be undone byte-for-byte.
Teams using infrastructure-doctor should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/doctor/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How infrastructure-doctor Compares
| Feature / Agent | infrastructure-doctor | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Skill for the doctor infrastructure module providing repository-level diagnostics and safe, reversible automated repair. Use when the local checkout is acting up, before opening a bug, when onboarding a fresh clone, or as a periodic health probe. Every mutation is backed up under .doctor/backups/ and journalled in .doctor/actions.jsonl so any change can be undone byte-for-byte.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Doctor Module
Repository-level "doctor mode": a diagnostic engine plus an automated, audited resolution engine. The doctor never leaves the patient worse off — every mutation is snapshotted before it runs and can be reversed by a single `undo` command.
## Quick start
```bash
# Diagnose only (read-only).
uv run python -m infrastructure.doctor
# Same, JSON for an agent.
uv run python -m infrastructure.doctor --json diagnose
# Show what would be fixed (no changes).
uv run python -m infrastructure.doctor fix --plan
# Apply the safest set of fixes.
uv run python -m infrastructure.doctor fix --apply
# Allow `uv sync` and other moderate-therapy fixes.
uv run python -m infrastructure.doctor fix --apply --moderate
# Allow radical fixes (e.g. delete orphan output directories — still backed up).
uv run python -m infrastructure.doctor fix --apply --aggressive
# Reverse the most recent applied, reversible action.
uv run python -m infrastructure.doctor undo --last
# Reverse one specific action (see `history`).
uv run python -m infrastructure.doctor undo --action-id <id>
# Inspect the journal.
uv run python -m infrastructure.doctor history
# Agent-facing capability manifest.
uv run python -m infrastructure.doctor capabilities
# Stable-text robot manual.
uv run python -m infrastructure.doctor robot-docs
```
## Safety contract
Every fix flows through `infrastructure.doctor.safety.mutate(plan, state)`. That function is the **only** code in this module that writes to the filesystem on behalf of a fixer. It guarantees:
1. Paths in `plan.affected_paths` are resolved and confirmed to be inside the repo and outside `.doctor/`.
2. Every existing path is copied byte-for-byte into `.doctor/backups/<action_id>/` and its SHA-256 is recorded.
3. The registered handler for `plan.action_kind` runs (`delete_paths`, `chmod`, `write_file`, `run_uv_sync`).
4. Post-mutation hashes are taken; the result is appended to `.doctor/actions.jsonl` as a single JSON line.
5. If the handler raises, the journal still records the attempt with `applied=false` and `error` populated — audit is never silently lost.
`undo(record)` inverts a reversible record by restoring every path from its backup, then verifying the post-restore hash equals the original `pre_hash`. A mismatch raises `DoctorSafetyError` rather than overwriting unexpected content.
## Detector / fixer inventory
| Code | Detector | Default fix (therapy) |
| ------ | ----------------------------------- | -------------------------------------------------- |
| DOC101 | uv on PATH | — (install manually) |
| DOC102 | Python version >= 3.10 | — (install manually) |
| DOC103 | run.sh executable | `fix_make_run_sh_executable` (conservative) |
| DOC201 | project layout | — |
| DOC202 | per-project pyproject.toml | — |
| DOC203 | manuscript/config.yaml integrity | — |
| DOC301 | __pycache__ / pytest / mypy / ruff | `fix_clean_pycache` (conservative, fully reversible) |
| DOC302 | stale .coverage / coverage_*.json | `fix_clean_coverage_files` (conservative) |
| DOC303 | orphan output/<name>/ dirs | `fix_remove_orphan_output_dirs` (radical, reversible) |
| DOC401 | pre-commit local hook installed | `fix_install_pre_commit_hook` (conservative) |
| DOC402 | uv.lock vs pyproject.toml drift | `fix_run_uv_sync` (moderate, **not** reversible) |
| DOC501–504 | Ollama / Docker / XeLaTeX / Pandoc | — |
| DOC601 | .doctor/ writable | — |
## Exit codes (stable)
| Code | Meaning |
| ---- | -------------------------------- |
| 0 | healthy |
| 1 | warnings present |
| 2 | one or more errors |
| 3 | one or more criticals |
| 4 | regression after a fix |
| 64 | usage error (BSD `EX_USAGE`) |
## Public API
```python
from infrastructure.doctor import (
DoctorState, run_detectors, build_plans_for_findings,
mutate, undo, load_journal,
compute_scorecard, compute_exit_code,
render_report_text, render_report_json,
)
```
## Where state lives
```
.doctor/
├── backups/<action_id>/ # full snapshot of every path the fix touched
├── actions.jsonl # append-only audit log (one JSON line per action)
└── state.json # (reserved for future last-run summary)
```
`.doctor/` should be added to `.gitignore`. The doctor never writes outside this directory except to apply the fix itself.
## Tests
```bash
uv run pytest tests/infra_tests/doctor/ -v --no-cov
```
Follows the repo's no-mocks policy: every test runs against a real temporary repo and exercises the actual mutate/undo path.Related Skills
infrastructure-validation
Skill for the validation infrastructure module providing PDF validation, markdown validation, output integrity checks, link verification, documentation audits, issue categorization, and repository scanning. Use when validating research outputs, checking document quality, running audits, or verifying cross-references.
infrastructure-steganography
Skill for the steganography infrastructure module providing QR code generation with dynamic mailto links, hash manifests, metadata payloads, and document-wide overlay processing. Use this module to insert opt-in cryptographic and steganographic provenance data onto PDFs.
infrastructure-skills
Programmatic discovery of first-party agent SKILL.md files under configured public repo roots (infrastructure, projects, docs/prompts, and .cursor/skills). Use when enumerating skills, validating .cursor/skill_manifest.json, writing docs/_generated/skills_index.md, checking docs/prompts workflow contracts, or wiring editor automation. Exposes discover_skills, write_skill_manifest, manifest_matches_discovery, and check_skill_contracts.
infrastructure-search-literature
Paperclip-style multi-source literature search across arXiv, Crossref, local JSON corpora, and (opt-in) the Paperclip API. Provides Paper/SearchQuery/SearchResult data models, a LiteratureClient aggregator with per-backend failure isolation, DOI/arXiv-aware deduplication via merge_papers, deterministic JSON caching via SearchCache, an HttpClient protocol for test injection, and a CLI (search/to-bibtex). Use when finding papers by topic, building reading lists, populating references.bib from a query, or replaying a prior search reproducibly.
infrastructure-search
Discovery utilities for academic literature. Currently exposes the `literature` submodule — Paperclip-style multi-source search across arXiv, Crossref, local JSON corpora, and (opt-in) the Paperclip API, with deterministic JSON caching, a `LiteratureClient` aggregator, normalised `Paper` records, and a CLI. Use when the user wants to find papers, build reading lists, populate references.bib from a query, or replay a prior search reproducibly. Designed to host additional discovery workflows without breaking the public API.
infrastructure-scientific
Skill for the scientific infrastructure module providing numerical stability checks, performance benchmarking, scientific documentation generation, implementation validation, and module/workflow templates. Use when benchmarking functions, checking numerical stability, validating scientific implementations, or creating scientific module scaffolds.
infrastructure-reporting
Skill for the reporting infrastructure module providing pipeline reporting, error aggregation, executive summaries, dashboard generation, test reporting, and multi-project reports. Use when generating build reports, aggregating errors, creating visual dashboards, or producing executive summaries across projects.
infrastructure-rendering
Skill for the rendering infrastructure module providing multi-format output generation including PDF manuscripts, HTML web pages, Beamer/Reveal.js slides, and posters. Use when rendering research outputs, converting markdown to PDF, generating slides, or configuring LaTeX rendering.
infrastructure-reference-citation
BibTeX read/write/convert that matches the syntax/semantics of projects/template_code_project/manuscript/references.bib (consumed by Pandoc with --natbib -- see infrastructure/rendering/_pdf_combined_renderer.py). Provides BibEntry/BibDatabase models, parse_bibfile/render_database functions, paper_to_bibentry conversion from literature search results, generate_citation_key in the project's house style (firstauthorlastname+year+firsttitleword), LaTeX-special-character escape helpers, and a CLI (validate/format/convert). Use when reading or writing .bib files, exporting search results to BibTeX, or generating citation keys.
infrastructure-reference
Bibliographic-reference utilities for research projects. Read, write, and convert BibTeX entries that match the syntax/semantics of projects/template_code_project/manuscript/references.bib (consumed by Pandoc with --natbib during PDF render -- see infrastructure/rendering/_pdf_combined_renderer.py). Currently exposes the `citation` submodule (BibTeX I/O + Paper→BibEntry conversion); designed to host additional reference workflows (e.g. CSL-JSON export, ORCID lookups) without breaking the public API.
infrastructure-publishing
Skill for the publishing infrastructure module providing academic publishing workflows including BibTeX CLI citation generation, APA/MLA citation helper functions, DOI management, Zenodo publication, arXiv submission preparation, GitHub releases, and publication readiness validation. Use when publishing research, generating citations, minting DOIs, or preparing submissions.
infrastructure-prose
Prose analysis utilities for research manuscripts and prose-focused projects. Provides readability metrics (Flesch, Flesch-Kincaid, Gunning Fog), heading-outline structural analysis, editorial quality flags (passive voice, hedge words, citation density, long sentences), aggregate ManuscriptReport across a manuscript directory, and a CLI (metrics/outline/quality/report). Use when analyzing manuscripts for readability, building editorial dashboards, validating heading structure, extracting citation keys from prose, or wiring prose-quality gates into the pipeline.