<p align="center">
  <img src="docs/assets/banner.webp" alt="Booklin, the book-to-skill wizard, holding an open book whose pages scatter into sparkles that settle into an ordered grid" width="100%">
</p>

<h1 align="center">book-to-skill</h1>

<p align="center">
  <a href="README.md"><strong>English</strong></a> ·
  <a href="README.ru.md">Русский</a> ·
  <a href="README.zh-CN.md">简体中文</a> ·
  <a href="README.ja.md">日本語</a>
</p>

<p align="center">
<strong>Turn any technical book, document folder, or collection of sources into a unified agent skill — ready to study, reference, and use while you work in GitHub Copilot CLI, Amp, Claude Code, Codex, Hermes Agent, OpenCode, or OpenClaw.</strong></p>

<p align="center">
  <a href="https://github.com/virgiliojr94/book-to-skill/releases"><img src="https://img.shields.io/github/v/release/virgiliojr94/book-to-skill?style=for-the-badge&color=blueviolet" alt="Latest release"></a>
  <img src="https://img.shields.io/badge/Agent_Skills-Open_Standard-blueviolet?style=for-the-badge" alt="Agent Skills standard">
  <img src="https://img.shields.io/badge/PDF%20%E2%80%A2%20EPUB%20%E2%80%A2%20DOCX%20%E2%80%A2%20MD%20%E2%80%A2%20HTML%20%E2%80%A2%20RTF%20%E2%80%A2%20MOBI%20%E2%80%A2%20MCP-supported-green?style=for-the-badge" alt="Formats and MCP supported">
  <img src="https://img.shields.io/badge/License-MIT-blue?style=for-the-badge" alt="MIT License">
  <a href="https://github.com/sponsors/virgiliojr94"><img src="https://img.shields.io/github/sponsors/virgiliojr94?style=for-the-badge&color=ea4aaa&logo=githubsponsors&logoColor=white" alt="Sponsor"></a>
</p>

<p align="center">
  <a href="https://trendshift.io/repositories/27038?utm_source=repository-badge&amp;utm_medium=badge&amp;utm_campaign=badge-repository-27038" target="_blank" rel="noopener noreferrer"><img src="https://trendshift.io/api/badge/repositories/27038" alt="virgiliojr94%2Fbook-to-skill | Trendshift" width="250" height="55"/></a>
  <a href="https://trendshift.io/repositories/27038?utm_source=trendshift-badge&amp;utm_medium=badge&amp;utm_campaign=badge-trendshift-27038" target="_blank" rel="noopener noreferrer"><img src="https://trendshift.io/api/badge/trendshift/repositories/27038/daily?language=Python" alt="virgiliojr94%2Fbook-to-skill | Trendshift (daily, Python)" width="250" height="55"/></a>
   <a href="https://www.star-history.com/virgiliojr94/book-to-skill"><img src="https://api.star-history.com/badge?repo=virgiliojr94/book-to-skill&type=rank" alt="Star History Rank" /></a>
</p>



<p align="center">
  <a href="#-why">Why</a> ·
  <a href="#-what-it-generates">What it generates</a> ·
  <a href="#-search--read-mcp">Search &amp; Read (MCP)</a> ·
  <a href="docs/usage.md">Usage</a> ·
  <a href="docs/install.md">Install</a> ·
  <a href="docs/faq.md">FAQ</a> ·
  <a href="docs/performance.md">Performance</a> ·
  <a href="docs/architecture.md">Architecture</a> ·
  <a href="#-sponsors">Sponsors</a> ·
  <a href="CHANGELOG.md">Changelog</a>
</p>

<p align="center">
  <strong>Compile books and documentation into structured, on-demand agent skills.</strong>
</p>

> 💖 **Keep book-to-skill moving forward:** Maintained independently in personal time (1,247 tests passing, 26 skipped, on master `f5b0c05`; community PR reviews, security hardening, and releases like v2.0). If this project saves you engineering hours or tokens, **[sponsor its maintenance on GitHub →](https://github.com/sponsors/virgiliojr94)**

**How it works, in 3 steps:**

1. **Point or Search** — give it a local file/folder (`/book-to-skill ./my-book.pdf`) **or** search remotely via MCP (`/book-to-skill search "Pro Git"`).
2. **It distills** the book into a skill — frameworks, decision rules, anti-patterns, and per-chapter files. Structure, not a summary.
3. **Your agent loads it on demand** — ask `/my-book replication` and it reads the right chapter and answers from the chapter text it loads. Answer accuracy is not measured yet.

---

## 🤔 Why

<img align="right" width="200" src="docs/assets/booklin.png" alt="Booklin — the book-to-skill mascot, a purple wizard holding a book">

You buy a great technical book. You read it once. Three months later you can't remember chapter 7 existed.

The usual workarounds don't help:
- 📄 "Let me just search the PDF" → you get a list of pages, not answers
- 🧠 "I'll ask the agent about this book" → it either hallucinates or says it doesn't have the content
- 📝 "I'll take notes as I read" → you end up with a 200-line doc you never open again

**book-to-skill solves this by turning the book into a structured skill your agent loads on demand.**

Once installed, you just type `/your-book-slug replication` and the agent reads the right chapter and answers from the chapter text. No digging through PDFs. The book becomes part of your workflow.

Works with any host that supports the open [Agent Skills](https://github.com/agentskills/agentskills) standard — GitHub Copilot CLI, Amp, Claude Code, Codex, Hermes Agent, OpenCode, and OpenClaw all read the same `SKILL.md` format.
---

## 📦 What it generates

Running `/book-to-skill your-book.pdf` (or a folder, glob, or list of files) creates a full skill in the user-level cross-agent skills directory `~/.agents/skills/<slug>/` — one copy that Copilot CLI, Amp, Codex, OpenCode, and OpenClaw discover natively (OpenCode also reads its own managed root `~/.config/opencode/skills/<slug>/`; OpenClaw also discovers it when using its default state directory, with a non-default `OPENCLAW_STATE_DIR` use the active state's `skills/` root instead). When run under Claude Code, the converter also attempts a verified symlink at `~/.claude/skills/<slug>/` — Claude Code sees the skill when the link read-back confirms it; otherwise the run report says so. Hermes Agent partitions its personal skills by category and does not scan the cross-agent root, so a Hermes install lands in `/skills/<category>/<slug>/` instead. OpenClaw-managed, OpenCode-managed, and project-local destinations remain available when explicitly requested:

| File | Purpose |
|------|---------|
| `SKILL.md` | Core mental models + chapter index |
| `chapters/ch01-*.md` … | One file per chapter, loaded on-demand |
| `glossary.md` | Every key term, alphabetically sorted with chapter refs |
| `patterns.md` | All techniques, algorithms, and design patterns |
| `cheatsheet.md` | Decision tables and quick-reference rules |

**Chapter files are loaded on-demand** — they don't count against the skill budget until you ask about that topic.

---

## 🏢 Beyond books

The name says "book", but the input is any structured prose. The same extraction works on knowledge you own and re-read constantly:

- **Internal documentation** — architecture decision records, runbooks, onboarding guides. Fold a whole `docs/` folder into one skill and ask it while you code.
- **Brand & design systems** — voice guidelines, tone-of-voice docs, component principles. Turn a brand book into a skill your team queries instead of skimming a 60-page PDF.
- **Research clusters** — a stack of papers plus your own notes, merged into a single unified skill and updated as new material lands (see [Update / fold-in](#-usage)).
- **Specs & standards** — RFCs, API contracts, compliance docs you reference but never memorize.

If you re-open a document often enough to wish you'd memorized it, it's a candidate.

---


## 🧾 The Discovery Loop Tax

A PDF-reading agent doesn't just read — it *navigates*: it re-fetches the ToC, backtracks, and re-processes all of it on every turn. book-to-skill pays that structuring cost **once**, at conversion, so queries stay proportional to the answer — fewer tokens per query than dumping the book into context. Dump side counted with tiktoken on two real books; book-to-skill side assumed at ~5,000 tokens, not measured, so the ratio is an estimate (see docs/performance.md).

📊 **Full methodology, numbers, and per-book tables → [docs/performance.md](docs/performance.md#the-discovery-loop-tax)**

---

## ⚙️ How it works

Two halves: a deterministic Python **extractor** (document → clean text + metadata) and a spec-driven **generator** (your agent follows `SKILL.md` to turn that into a structured skill). On-demand chapter files keep the loaded skill small.

🔧 **Full walkthrough (Steps 0–10, extraction modes, token budgets) → [docs/how-it-works.md](docs/how-it-works.md)**

---

## 🚀 Usage

Two entry points — pick whichever fits what you have right now:

```text
/book-to-skill <path|folder|glob> [skill-name]   # convert local files (PDF, EPUB, DOCX, MD…)
/book-to-skill search "<title, author, ISBN, or DOI>"  # discover & read incrementally via MCP
```

Plus analyze-only, generate-from-analysis, and update/fold-in workflows. After a conversion, the converter can publish the generated skill to GitHub (`--private` by default) so any host installs it with `npx skills add`.

▶️ **All modes and examples → [docs/usage.md](docs/usage.md)**

💬 **In practice → [use cases](https://github.com/virgiliojr94/book-to-skill-use-cases)** — a DevEx book became a survey of 300+ engineers; a scanned PDF that stalled became [#130](https://github.com/virgiliojr94/book-to-skill/pull/130). Add yours: the account lives in your own Gist, the index takes a one-line PR.

---

## 🔍 Search & Read (MCP)

Don't have the book file handy? When an MCP book provider (such as `libgen-mcp`) is configured in your host agent, **Search & Read** lets you search by title, author, ISBN, or DOI, pick the exact edition, and convert it chapter by chapter into the same structured skill layout — **without downloading a permanent copy to your disk**:

```text
/book-to-skill search "Pro Git"
```

- **Guided setup if needed:** Run `/book-to-skill` or `/book-to-skill search` without an active MCP provider and the skill walks you through installing and configuring `libgen-mcp` for your host (or converting a local file right away).
- **Zero-network core & ephemeral synthesis:** Your host agent invokes MCP `search`, `get_details`, and `read`, discarding raw fragments after each chapter is synthesized; `book_to_skill/` never makes outbound network requests or writes `full_text.txt` ([docs/architecture.md](docs/architecture.md), [references/search-and-read.md](references/search-and-read.md)).
- **Configurable policy (`BOOK_TO_SKILL_REMOTE_POLICY`):** Restrict or allow providers (`enabled_providers`, `blocked_providers`), require explicit confirmation before reading, and enforce private-by-default publishing.
- **Access & temporary cache notice:** Confirming before reading does **not** equal copyright-holder authorization, and MCP `read` may temporarily cache the source on the MCP server and send read text to your model. See [Copyright & fair use](#-copyright--fair-use) and [SECURITY.md](SECURITY.md).

---

## 📥 Install

```bash
# One command, any host — via the cross-agent skills CLI:
npx skills add virgiliojr94/book-to-skill

# Or manually — clone into your skills folder (registers /book-to-skill):
git clone https://github.com/virgiliojr94/book-to-skill.git ~/.claude/skills/book-to-skill
# (Copilot CLI: ~/.copilot/skills/ · Amp/cross-agent: ~/.agents/skills/)
# (Hermes Agent: ${HERMES_HOME:-$HOME/.hermes}/skills/<category>/)
# (OpenClaw: ${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/skills/; ~/.agents/skills/ only with default state)
# (OpenCode: ~/.agents/skills/ — it also reads ~/.config/opencode/skills/)
```

📥 **All hosts, optional extractors, and the standalone CLI → [docs/install.md](docs/install.md)**

---

## ❓ FAQ

Common questions — "why not just dump the PDF?", cost, privacy, non-book inputs, multi-file books.

❓ **Answers → [docs/faq.md](docs/faq.md)**

---

<details>
<summary>🔧 <strong>Requirements</strong></summary>


The extractor tries tools in order per format and uses the first available. If nothing is installed, it tells you which command to run. Plain text, Markdown, reStructuredText and AsciiDoc need no extra deps.

> **Check your setup in one command:** `python3 scripts/extract.py --check` prints which extractors are installed for every format and the exact command to install anything missing — no file needed.

**PDF — choose by book type:**

| Book type | Tool | Install | Speed |
|-----------|------|---------|-------|
| Text-heavy (prose, few tables) | `pdftotext` (poppler) | `sudo apt install poppler-utils` | ⚡ instant |
| Text-heavy fallback | `pypdf` | `pip3 install pypdf` | ⚡ instant |
| Text-heavy fallback | `pdfminer.six` | `pip3 install pdfminer.six` | ⚡ instant |
| **Technical (code, tables, formulas)** | **`docling`** | `pip3 install docling` | ~1.5s/page |

> Before extraction begins, the skill asks you whether the book is **technical** or **text-heavy** and picks the right tool automatically. Docling preserves markdown tables and code blocks; pdftotext is faster for prose-only books.

> **Scanned PDFs need OCR first.** A PDF that is page images with no text layer — a photographed or scanned book — has nothing for these tools to extract. The extractor checks the first pages and stops immediately with an explanation, rather than working through the whole book to produce an empty skill. Run OCR yourself, then convert the result:
>
> ```bash
> ocrmypdf input.pdf output.pdf
> ```

**EPUB:**

| Tool | Install | Quality |
|------|---------|---------|
| `ebooklib` + `beautifulsoup4` | `pip3 install ebooklib beautifulsoup4` | ⭐⭐⭐ Best |
| stdlib `zipfile` | built-in — no install needed | ⭐⭐ Always available |

**Other formats:**

| Format | Tool | Install |
|--------|------|---------|
| DOCX | `python-docx` (fallback: stdlib ZIP/XML) | `pip3 install python-docx` |
| HTML | `beautifulsoup4` (fallback: stdlib `html.parser`) | `pip3 install beautifulsoup4` |
| RTF | `striprtf` (fallback: regex) | `pip3 install striprtf` |
| MOBI / AZW / AZW3 | Calibre `ebook-convert` (external app, not pip) | https://calibre-ebook.com/download |
| TXT / Markdown / reStructuredText / AsciiDoc | built-in | — |

---


</details>

<details>
<summary>📁 <strong>Repository structure</strong></summary>


```
book-to-skill/
├── SKILL.md                  # Skill definition + Steps 0-6 (input, extraction, cost estimate, destination)
├── GENERATION.md             # Steps 7-11 + Update/Fold-in Workflow + Quality Rules — loaded on-demand
├── references/
│   └── search-and-read.md    # Lazy-loaded Mode 2 MCP Search & Read protocol + setup
├── scripts/
│   └── extract.py            # Thin CLI entrypoint shim
├── book_to_skill/            # Zero-network Python package
│   ├── config.py             # Extensions, paths, dependency constants
│   ├── dependencies.py       # Optional-dep probing + --check
│   ├── sanitize.py           # Zero-width/bidi prompt-injection sanitization + Kangxi folding
│   ├── utils.py              # CLI parsing, multi-source resolution, chapter/outline detection
│   ├── parsers/              # Format-specific parsers (pdf, epub, docx, html, rtf, calibre, text)
│   └── remote/               # Offline MCP discovery, policy, reader state, checkpoints, coverage
├── tools/
│   ├── discovery_tax.py      # Measures token cost vs context-dump / discovery loop
│   ├── scan_generated_skill.py # Prompt-injection & safety scanner for generated skills
│   ├── validate_skill.py     # Checks generated SKILL.md across 6 host lenses
│   └── ground_check.py       # Fidelity gate: claims land in their chapters + counts match lists (Step 9.5b)
├── tests/                    # 1,247 pytest tests, passing at f5b0c05 (parsers, security, offline mock MCP E2E)
├── docs/
│   ├── performance.md        # Token counts (measured) vs estimates, discovery tax, cost
│   └── architecture.md       # Pipeline + component map
├── CHANGELOG.md              # Release history (semver)
├── CONTRIBUTING.md           # Dev setup, PR conventions, release process
├── SECURITY.md               # Security boundaries & vulnerability reporting
└── README.md                 # This file
```

---


</details>

---
## ⚖️ Copyright & fair use

book-to-skill ships **no book content** — not a single page. It's a converter you point at files you already own (or query through an MCP provider you configure).

- **Processing is local (files) and ephemeral (Search & Read).** Local extraction and analysis run on your machine and never upload files. In Search & Read, `book_to_skill/` still makes zero network calls and writes no permanent `full_text.txt`; your host agent calls your configured MCP server (`read`), which may temporarily cache full files on the server and transmit read chunks to your model under those providers' data terms.
- **You use your own copy and remain responsible for access rights.** Bring a book you bought, docs your company owns, or papers you have the right to read. In Search & Read, explicit confirmation before reading records your consent to proceed — it does **not** equal copyright-holder authorization.
- **The output is your notes.** A generated skill is a structured, synthesized derivative — framework names, definitions, takeaways — not a reproduction of the text. The skill explicitly never copies raw passages (see Quality Rule #7). Treat it like handwritten study notes: yours, for personal use.
- **Don't redistribute.** Publishing or sharing a generated skill of a copyrighted work can infringe the rights holder. Keep skills of third-party books private (Search & Read enforces `--private` by default). Internal docs, your own writing, and openly-licensed material are fine to share within the bounds of their license.

When in doubt, follow the license or terms of the source document. This project is a tool; how you use it is on you.

---

## 💖 Sponsors

<img align="right" width="150" src="docs/assets/booklin-celebrating.png" alt="Booklin celebrating">

`book-to-skill` is free, MIT-licensed, and maintained independently on personal time. Keeping it reliable across 7 agent hosts takes steady engineering:

- **Reviewing and verifying community PRs** one by one against real regressions
- **Maintaining 1,247 automated tests** (passing at `f5b0c05`, 26 skipped) across Python 3.9–3.13, Linux/Windows, and parser fallbacks
- **Security hardening & new capabilities** (prompt-injection sanitization, DOCX/EPUB guards, and v2.0 MCP Search & Read)
- **Multilingual chapter support & documentation**

If `book-to-skill` saves you engineering hours, study time, or model tokens — or if your team uses it internally — please consider sponsoring its ongoing maintenance and next releases:

> **💖 [Sponsor on GitHub → github.com/sponsors/virgiliojr94](https://github.com/sponsors/virgiliojr94)**

- **Tiers:** Gold ($100+/mo) · Silver ($50–99/mo) · Bronze ($15–49/mo) · Backers ($5–14/mo or one-time)
- **Recognition:** Sponsors are featured in [BACKERS.md](BACKERS.md) (Gold/Silver/Bronze links & logos, or anonymous on request).

Thank you to our current backers ([Gui Santos](https://github.com/guiofsaints) and supporters) for helping keep open, privacy-first tooling alive. ✨

## License

MIT — applies to the converter (code + skill definition) in this repository, **not** to any book or document you process with it.

---

Copyright (c) 2025 virgiliojr94 License files are attached. [MIT](https://knowen.md/f/9833e77c-92ec-431d-8fba-7b3beff917f7)

### MIT notice

````text
MIT License

Copyright (c) 2025 virgiliojr94

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.
````