Contributions are welcome! coarse is a free, open-source AI academic paper reviewer and we appreciate bug reports, feature requests, and code contributions.
Requirements: Python 3.12+, uv
git clone https://github.com/Davidvandijcke/coarse.git
cd coarse
uv sync --extra dev
uv run pytest tests/ -v # run tests
uv run ruff check src/ tests/ # lintOr use make:
make check # lint + test
make test # tests only
make lint # lint only
make format # auto-formatsrc/coarse/
├── cli.py # Typer CLI, progress display (rich)
├── cli_review.py # Standalone coarse-review CLI for headless local/handoff runs
├── cli_attach.py # --attach signal-driven wait mode (pidfile + log tail + heartbeat watcher)
├── claude_code_client.py # Back-compat re-export for headless Claude client helpers
├── config.py # ~/.coarse/config.toml, API key management
├── cost.py # Cost estimation + user approval gate
├── extraction.py # PDF/TXT/MD/TeX/DOCX/HTML/EPUB → PaperText
├── extraction_cache.py # Extraction cache paths and cache read/write helpers
├── extraction_formats.py # Non-OpenRouter format-specific extraction backends
├── extraction_openrouter.py # OpenRouter OCR/file-parser transport and response parsing
├── extraction_qa.py # Post-extraction QA via vision LLM (Gemini Flash)
├── garble.py # OCR garble detection and normalization
├── headless_clients.py # Claude/Codex/Gemini CLI-backed LLMClient replacements
├── headless_isolation.py # Tool-free subprocess env, profiles, and auth isolation
├── headless_prompt.py # Fail-closed text-only serializer for headless CLI prompts
├── headless_review.py # Shared entrypoint for headless CLI review runs
├── llm.py # litellm wrapper, structured output, cost tracking
├── models.py # Single source of truth for every model ID
├── pipeline.py # review_paper() orchestrator
├── pipeline_spec.py # Shared stage manifest for runtime + cost estimators
├── progress.py # Pipeline progress event types for live CLI reporting
├── prompts.py # All LLM prompt templates
├── quality.py # Quality eval against reference review (dev only)
├── quote_verify.py # Post-processing quote verification (stricter for math)
├── recall.py # Recall eval vs. ground-truth expert reviews (dev only)
├── review_stages.py # Stage-local review helpers used by pipeline.py
├── structure.py # PaperText → PaperStructure (heading parse + math + metadata)
├── synthesis.py # Review → markdown string
├── types.py # Pydantic models (PaperText, Review, DetailedComment, …)
└── agents/
├── base.py # ReviewAgent ABC + _build_messages helper + prompt caching
├── completeness.py # Flags structural gaps and missing content
├── contradiction.py # Flags comments contradicting the paper's contribution (legacy)
├── cross_section.py # Cross-section synthesis: discussion claims vs formal results
├── crossref.py # Cross-reference consistency (legacy, superseded by editorial)
├── critique.py # Self-critique quality gate (legacy, superseded by editorial)
├── editorial.py # Merged filtering pass (dedup, contradiction, quality, ordering)
├── literature.py # Literature search (Perplexity Sonar Pro, arXiv fallback)
├── overview.py # Single-pass macro-level overview feedback
├── quote_repair.py # Batched near-miss quote re-anchoring before deterministic re-check
├── section.py # Per-section detailed review
└── verify.py # Adversarial proof verification (math sections)
paper.pdf (or .txt, .md, .tex, .docx, .html, .epub)
-> extraction.py Mistral OCR / Docling fallback -> PaperText
-> extraction_qa.py Vision LLM spot-check (auto-triggers on garbled text)
-> structure.py Parse headings + LLM classify + math detection -> PaperStructure
-> calibrate_domain \
| Parallel: domain-specific criteria + literature search
-> search_literature / (Perplexity Sonar Pro, arXiv fallback)
-> overview.py Single overview agent -> OverviewFeedback
-> completeness.py Structural-gap pass merged into overview
-> section agents \
| Parallel: detailed comments + adversarial proof verification
-> proof verify / (math sections only)
-> cross_section.py Results vs discussion synthesis (conditional)
-> editorial.py Primary dedup/consistency/quality filter
-> crossref agent Legacy fallback if editorial fails
-> critique agent Legacy fallback if editorial fails
-> quote_verify.py Programmatic fuzzy-match quotes against text
-> synthesis.py Deterministic render -> paper_review.md
- Simplicity first. Minimum code that solves the problem. No speculative features or abstractions for single-use code.
- Every file gets tests. Tests go in
tests/test_{module}.py. - Prompts in
prompts.py. All LLM prompt templates in one file. - Models in
models.py. Never hardcode model ID strings outside this file. - Types in
types.py. All Pydantic models for the pipeline. - Structured output. Use
instructor+ Pydantic for all LLM responses. - Use
uv runfor all commands (pytest, ruff, python).
coarse uses a two-branch model:
main— stable, tagged releases only. Protected: direct pushes are disallowed; changes land only via release PRs fromdev. Each merge tomainis tagged with a semantic version (v1.1.0,v1.2.0, …).dev— active development. All feature work targetsdev. Whendevhas accumulated enough changes to warrant a release, open a PR fromdevtomain, bump the version, and tag.
feat/my-feature ─► dev ─► main (release PR + tag)
Branch off dev (not main) using one of:
feat/<description> # New features
fix/<description> # Bug fixes
docs/<description> # Documentation only
chore/<description> # Tooling, CI, dependencies
Use conventional commits:
feat(pipeline): add parallel section processing
fix(extraction): handle scanned PDFs without text layer
docs: update changelog for v1.2.0
test(agents): add edge case for empty sections
Scope is optional but encouraged. Focus the subject line on the why, not the what — the diff already shows the what.
coarse follows Semantic Versioning:
- MAJOR (
2.0.0) — breaking changes to the public API or CLI - MINOR (
1.2.0) — new features, no breaking changes - PATCH (
1.1.1) — bug fixes only
Version bumps happen only on release PRs from dev to main. Feature PRs into dev must NOT bump the version — that's the release manager's job. The version lives in two places that must stay in sync (CI enforces this):
pyproject.toml→[project] version = "..."src/coarse/__init__.py→__version__ = "..."
If you use Claude Code, run /pre-pr — it runs every check below plus the
security scanner and five parallel review agents. Otherwise, run them
manually:
-
python3 scripts/security_scanner.pyreports no CRITICAL findings (ormake security) -
bash scripts/doc-sync-check.shexits 0 -
uv run ruff check src/ tests/passes (ormake lint) -
uv run pytest tests/ -vpasses (ormake test) -
CHANGELOG.mdupdated under## Unreleasedin the appropriate subsection (Added/Changed/Fixed/Removed) - New code has tests in
tests/test_<module>.py - Commit messages follow conventional commits
- PR targets
dev(notmain) — unless you're the maintainer cutting a release
Workflow automation lives in .claude/commands/. Run with a / in chat.
| Command | When to use it |
|---|---|
/pre-pr |
Before every push. Security gate + doc sync + 5 parallel review agents + lint/tests/changelog. |
/security-review |
Standalone security audit. Blocking gate inside /pre-pr; also runs in CI via .github/workflows/security.yml. |
/architecture-review |
After a big refactor or new agent. Import graph + layer check + 3 parallel structural agents. |
/module-review |
Focused audit of one module against the 11-point bug checklist. Supports --module <path>, --changed, --all. |
/worktree-start |
Create a new worktree off dev for a feature/fix. |
/dev-loop |
Supervised autonomous development loop for component builds. |
- Fork the repository (external contributors) or create a branch directly (maintainers).
- Branch off
dev:git checkout dev && git pull && git checkout -b feat/my-feature - Make your changes, commit with a conventional message.
- Run
make check(lint + tests). - Update
CHANGELOG.mdunder## Unreleased. - Open a PR against
dev.
When dev is ready to release:
- On
dev, bump the version inpyproject.tomlandsrc/coarse/__init__.py. - Rename the
## Unreleasedheading inCHANGELOG.mdto## vX.Y.Z — YYYY-MM-DD, and add a fresh empty## Unreleasedsection above it. - Commit:
git commit -m "release: vX.Y.Z". - Open a PR from
dev→maintitledrelease: vX.Y.Z. - After merge, tag the merge commit on
main:git tag -a vX.Y.Z -m "vX.Y.Z" && git push origin vX.Y.Z. - Pushing the tag triggers
.github/workflows/release.yml, which runs the test suite, verifies the tag matchespyproject.tomland__init__.py, builds the sdist + wheel withuv build, and publishes to PyPI via Trusted Publishing (OIDC). No API token is stored in the repo — thepublishjob runs in thepypiGitHub environment and mints a short-lived OIDC token that PyPI accepts. - Fast-forward
devtomainso both branches line up for the next cycle:git checkout dev && git merge --ff-only main && git push.
First-time PyPI setup (one-time per project): on PyPI, go to Manage → Publishing → Add a new pending publisher and register:
- PyPI Project Name:
coarse-ink - Owner:
Davidvandijcke - Repository name:
coarse - Workflow name:
release.yml - Environment name:
pypi
Until this is registered, the publish job will fail on the first run with invalid-publisher. After registering, re-run the failed workflow (or push a new tag) and the publish will succeed.
Open an issue at github.com/Davidvandijcke/coarse/issues. Include:
- coarse version (
coarse --version) - Python version
- OS
- Steps to reproduce
- Error output / logs
Maintainers apply area: * and priority: * labels during triage — contributors don't need to pick these. Every new issue gets a needs triage label automatically; once a maintainer has looked at it, that label is removed.
Security issues: if you find something sensitive (exposed secrets, auth bypass, etc.), please email david.van.dijcke@gmail.com instead of opening a public issue. Use the security label for non-sensitive security-related improvements.