# LibrePrints Agent Instructions

This document defines the exact rules for AI assistants, scholarly crawlers, and automated tools interacting with LibrePrints (https://libreprints.org).

## 1. Public Read-Only Access (No Authentication Needed)

1. List and search preprints: `GET https://libreprints.org/api/v1/papers?q=<query>&category=<code_or_empty>&year=<yyyy>`
2. Fetch one paper record as JSON: `GET https://libreprints.org/abs/<id>.json` or `GET https://libreprints.org/api/v1/papers/<id>`
3. Fetch one paper record as clean Markdown: `GET https://libreprints.org/abs/<id>.md` (or send `Accept: text/markdown` to `/abs/<id>`)
4. Download the public compiled PDF: `GET https://libreprints.org/pdf/<id>.pdf`
5. Export citations (`bibtex`, `biblatex`, `ris`, `csl-json`, `endnote`, `typst`, `ams`, `apa`, `chicago`): `GET https://libreprints.org/api/v1/papers/<id>/citations?format=bibtex`
6. Inspect current upload limits and storage rules: `GET https://libreprints.org/api/v1/limits`
7. Harvest all public records via OAI-PMH 2.0: `GET https://libreprints.org/oai?verb=ListRecords&metadataPrefix=oai_dc`
8. Full OpenAPI 3.1 schema: `GET https://libreprints.org/openapi.json`
9. Streamable HTTP MCP endpoint: `POST https://libreprints.org/mcp` (anonymous callers have read-only discovery tools; authenticated callers unlock scoped write tools).

## 2. Source-File Privacy Rule

Raw manuscript sources (`.tex`, `.typ`, `.bib`, `.docx`, figure bundles) are strictly private to each paper's authorized authors and archive administrators. Public visitors and unauthenticated agents cannot download manuscript source files. Cite and read the compiled PDF, the structured Markdown view, or accompanying open code repositories listed under companion links.

## 3. Authenticated Agent Contributions (Scoped Keys)

Authorized group members may mint scoped agent keys (`lp_...`) from `https://libreprints.org/settings/agents` and send `Authorization: Bearer lp_...`.

- **Default principle (Agents Stage, Humans Publish):** Keys created with `draft:write` can create drafts, upload LaTeX, Typst, or PDF bundles, upload Graphical Abstracts, trigger isolated compilation, read structured `{ file, line, severity, message }` diagnostics, inspect rendered preview PNGs, attach companion links, look up published DOIs, and call `POST /api/v1/drafts/{draftId}/request-approval` to notify the human author with a revocable `noindex` review link.
- Calling `POST /api/v1/drafts/{draftId}/publish` returns HTTP 403 unless the human author explicitly granted the `publish` scope on that key.
- Always supply `X-Idempotency-Key: <unique-uuid>` on `POST` requests so network retries never create duplicate drafts or comments.
- Use `?dry_run=1` on source uploads to validate archive safety and compilation before persisting a draft.

## 4. Mandatory File-Size Limits

- Compiled or direct PDF: maximum 25.00 MB (optimize figures above 10 MB via `POST /api/v1/drafts/{draftId}/optimize-pdf`).
- Source bundle: maximum 50 MB compressed, 150 MB unpacked, 15 MB per single file, at most 500 files. Strip `.git/` and raw datasets first; link datasets via Zenodo or GitHub Releases.
- Static Graphical Abstract: maximum 10 MB (SVG, PNG, WebP, JPEG, or single-page PDF).
- Animated Graphical Abstract: maximum 15 MB and at most 30 seconds (MP4, WebM, or GIF).
- Discussion comments: maximum 16 KB of Markdown + LaTeX text, zero binary attachments.
