Metadata-Version: 2.5
Name: paper-library-kit
Version: 0.2.0
Summary: Git-native, anti-hallucination literature knowledge graph & AI-readable paper library toolkit for AI coding agents.
Project-URL: Homepage, https://github.com/Debiddo0506/paper-library-kit
Project-URL: Repository, https://github.com/Debiddo0506/paper-library-kit
Project-URL: Issues, https://github.com/Debiddo0506/paper-library-kit/issues
Project-URL: Demo, https://debiddo0506.github.io/paper-library-kit/
Author: Debiddo0506
License: MIT License
        
        Copyright (c) 2026 Debiddo0506
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai-agents,anti-hallucination,claude-code,knowledge-graph,literature-review,pdf-to-markdown,research-tools
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.10
Requires-Dist: pyyaml>=6.0
Provides-Extra: all
Requires-Dist: mcp<3,>=2.0; extra == 'all'
Requires-Dist: pymupdf4llm>=0.0.17; extra == 'all'
Requires-Dist: pymupdf>=1.24.0; extra == 'all'
Provides-Extra: mcp
Requires-Dist: mcp<3,>=2.0; extra == 'mcp'
Provides-Extra: pdf
Requires-Dist: pymupdf4llm>=0.0.17; extra == 'pdf'
Requires-Dist: pymupdf>=1.24.0; extra == 'pdf'
Description-Content-Type: text/markdown

# Paper Library Kit (`plk`)

<!-- mcp-name: io.github.Debiddo0506/paper-library-kit -->

[![CI](https://github.com/Debiddo0506/paper-library-kit/actions/workflows/ci.yml/badge.svg)](https://github.com/Debiddo0506/paper-library-kit/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](pyproject.toml)
[![PyPI](https://img.shields.io/pypi/v/paper-library-kit.svg)](https://pypi.org/project/paper-library-kit/)
[![Downloads](https://static.pepy.tech/badge/paper-library-kit/month)](https://pepy.tech/project/paper-library-kit)
[![Glama MCP Server](https://glama.ai/mcp/servers/Debiddo0506/paper-library-kit/badges/score.svg)](https://glama.ai/mcp/servers/Debiddo0506/paper-library-kit)

**Stop letting AI coding agents hallucinate DOIs and burn tokens reading raw PDFs.**

![Demo: a fabricated quote is rejected, the real verbatim quote passes](assets/demo/demo.gif)

`paper-library-kit` is a **Git-native, verbatim-verified literature knowledge graph, PDF-to-Markdown pipeline, and proactive debugging hook** designed for **Claude Code, Codex, Cursor, and Perplexity/Gemini research workflows**.

> **English** ｜ [繁體中文版說明 (Traditional Chinese)](README.zh-TW.md) ｜ [Live Interactive Evolution Graph Demo (16 Real AI-Agent/RAG Papers)](https://debiddo0506.github.io/paper-library-kit/)

---

## Why This Exists

Standard reference managers (Zotero, Mendeley) are built for humans, while naive vector RAG stores often fail in rigorous engineering and academic workflows:

| Common AI Failure Mode | How `paper-library-kit` Fixes It |
|---|---|
| **Fabricated DOIs** during deep-research surveys | `plk verify` extracts every DOI in a Markdown file and checks title similarity live against **Crossref** |
| **Token bloat & garbled columns** when agents read raw PDFs | `plk ingest` converts PDFs to clean two-column Markdown with `=== p.N ===` markers + cropped figures; raw PDFs stay archived locally (never in Git) |
| **Hallucinated numbers & unit swaps** in summaries | `plk cards` & `plk check` enforce **verbatim `«quote»` substring matching** and **number-unit adjacency** before writing any entry |
| **Isolated paper lists** with no technical lineage | `plk cites` runs 4-source citation cross-auditing and `plk graph build` compiles a zero-backend interactive HTML evolution timeline |
| **Forgetting relevant papers** while debugging | `.claude/hooks/paper_hint.py` automatically surfaces the top 3 papers & evolution links when you log recurring failures |

---

## 5-Stage Pipeline

```mermaid
flowchart LR
    S1["1. Survey & Gaps\nplk lit / verify / chain / gap"] --> S2["2. PDF to AI-Readable\nplk ingest / ocr / audit-pdfs"]
    S2 --> S3["3. Verbatim Cards & Tags\nplk cards / check / meta-health"]
    S3 --> S4["4. Relation Graph & Timeline\nplk backfill / cites / graph build"]
    S4 --> S5["5. Retrieval & Proactive Hooks\nplk search / neighbors / paper_hint.py"]
```

---

## Real Anti-Hallucination Catch Examples

1. **Catching misquoted metrics before they enter your notes (`plk check`)**:
   ```text
   ✗ [number not found]    M05: 5 datasets @ plug-and-play retrieval correction evaluation
   ✗ [value not in quote]  M05: 5 «Experiments on five datasets demonstrate that CRAG»
   ```
   If the paper text says `"five datasets"` and an LLM rewrites `"5"`, or attaches a model number like `SM15T30A` as `30 A`, `check_core_tags.py` rejects it immediately.

2. **Catching LLM-hallucinated DOIs (`plk verify survey_notes.md`)**:
   ```text
   | Verdict              | Sim  | DOI                        | Crossref Actual Title                     | In Lib |
   |----------------------|------|----------------------------|-------------------------------------------|--------|
   | OK                   | 1.00 | 10.48550/arxiv.2210.03629  | ReAct: Synergizing Reasoning and Acting   | M01    |
   | MISMATCH (wrong ref) | 0.14 | 10.1109/jssc.2020.9999999  | Unrelated Journal Article                 | —      |
   ```

---

## Quick Start (30 Seconds)

### Option A: Try the 15-Paper Demo Immediately (No PDFs Needed)
```bash
pip install paper-library-kit
plk --lang en demo          # builds sample AI-Agent/RAG library + interactive evo_graph.html
```
Or test the MCP server with zero local setup via `uvx`:
```bash
uvx --from "paper-library-kit[mcp]" plk mcp --demo
```

### Option B: Start Your Own Research Library
```bash
pip install "paper-library-kit[all]"   # or `pip install paper-library-kit` for core CLI only
plk init ./my-research
cd my-research
plk --lang en import-bib refs.bib      # import an existing Zotero / Overleaf .bib file
plk ingest --arxiv 2310.06770          # or fetch arXiv PDF + metadata directly
```
Edit [`config/paper_config.yaml`](config/paper_config.yaml) for your domain (`topics`, `themes` swimlanes, controlled `vocab`, `aliases`, `lang: en`, and local `pdf_archive_dir`).

> Optional system packages for scanned PDFs: `poppler-utils` (`pdftoppm`/`pdftotext`) and `tesseract-ocr`.  
> Optional environment variable for high-rate OpenAlex queries: `export OPENALEX_API_KEY=...`

---

## CLI & Prompt Reference

### Unified `plk` Commands (pass `--lang en` or set `lang: en` in `paper_config.yaml`)
| Stage | Commands | Purpose |
|---|---|---|
| **0. Quick Start** | `plk init`, `plk demo`, `plk import-bib` | Initialize project, launch 15-paper demo, import BibTeX `.bib` into `ingest_bib.tsv` |
| **1. Survey** | `plk lit search`, `plk verify`, `plk chain`, `plk gap` | Crossref/OpenAlex search, DOI anti-hallucination verification, citation chains, problem-gap scan |
| **2. Convert** | `plk ingest [--arxiv]`, `plk ocr`, `plk audit-pdfs` | PDF / arXiv -> `=== p.N ===` Markdown + cropped `images/` + SHA-256 `meta.yaml`, OCR, 6-point audit |
| **3. Verify** | `plk cards`, `plk check`, `plk meta-health`, `plk triage-apply` | Build `summary.md` & TSVs from YAML with verbatim quote verification, OpenAlex metadata audit |
| **4. Graph** | `plk backfill`, `plk rel-context`, `plk check-relations`, `plk cites`, `plk graph` | Batch relation backfill, 4-source citation audit (`H x T x O x Y`), compile `evo_graph.html` |
| **5. Retrieve** | `plk search`, `plk show`, `plk neighbors`, `plk path`, `plk vocab` | Multi-signal search (problem ID, vocab, alias, `--fulltext`), multi-hop graph traversal |

### Ready-to-Use Prompt Templates
- **English**: [`prompts/en/`](prompts/en/) (`00_AGENT_LITERATURE_RULES.md` through `05_PROMPT_RELATION_NETWORK.md`)
- **繁體中文**: [`prompts/`](prompts/) (`00_AGENT_LITERATURE_RULES.md` through `05_PROMPT_RELATION_NETWORK.md`)

---

## Local MCP Server

Listed on PyPI, the **Official MCP Registry** (`io.github.Debiddo0506/paper-library-kit`), and **Glama**.

### Zero-Clone Launch via `uvx`
```bash
uvx --from "paper-library-kit[mcp]" plk mcp --demo
# Or point at your own initialized research directory:
uvx --from "paper-library-kit[mcp]" plk mcp --project-dir /absolute/path/to/my-research
```
Or install into your Python environment with `pip install "paper-library-kit[mcp]"` and run `plk mcp --project-dir ...`. Without `--project-dir`, `plk` looks for an initialized library in the current working directory.

Clients that support `mcpServers` (Claude Desktop, Claude Code, Cursor, etc.) can configure it directly:

```json
{
  "mcpServers": {
    "paper-library": {
      "command": "uvx",
      "args": [
        "--from",
        "paper-library-kit[mcp]",
        "plk",
        "mcp",
        "--project-dir",
        "/absolute/path/to/my-research"
      ]
    }
  }
}
```

The client discovers four read-only tools:

| Tool | Example arguments |
|---|---|
| `search` | `{"terms": ["tile-rendering"], "limit": 5}` |
| `show` | `{"paper_id": "R01"}` |
| `neighbors` | `{"paper_id": "R01", "depth": 2, "include_cites": false}` |
| `path` | `{"start_id": "R01", "end_id": "R02"}` |

Each tool returns the corresponding CLI `--json` value in a `result` field.
For full-text queries, pass `"fulltext": true` with `terms`. For indexed
queries, `search` also accepts `block` and `text`. Graph tools include citation
edges by default. A disconnected `path` returns `{"result": null}`.

### Glama MCP Directory & Online Testing

[![Paper Library Kit MCP server](https://glama.ai/mcp/servers/Debiddo0506/paper-library-kit/badges/score.svg)](https://glama.ai/mcp/servers/Debiddo0506/paper-library-kit)

View the server listing on [Glama MCP Servers](https://glama.ai/mcp/servers/Debiddo0506/paper-library-kit) before installing locally to:
- Browse the server's tools (`search`, `show`, `neighbors`, `path`) and check its quality score
- Test the server online using [Glama MCP Inspector](https://glama.ai/mcp/inspector)

---

## Development, Tests & Contributing

```bash
python -m unittest discover -s tests -v
```

Ready to contribute? Browse the [14 open `good first issue` tickets](https://github.com/Debiddo0506/paper-library-kit/issues?q=is%3Aopen+label%3A%22good+first+issue%22) or see [`ROADMAP.md`](ROADMAP.md) (Marker/Docling backend, BibTeX/Zotero importer, arXiv downloader, Obsidian exporter, `--lang en` CLI mode, domain presets) and [`CONTRIBUTING.md`](CONTRIBUTING.md).

## License

MIT License — see [`LICENSE`](LICENSE). **Never commit copyrighted PDFs or private API keys to a public repository.**
