Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.
Python agent-skillsai-agentsbook-to-skillcontext-engineeringdocument-processingedtechknowledge-baseknowledge-managementllmpdf-to-markdownragself-studystudy-tools
feat: expand format docs, ToC detection window, REPL-style extraction guidance
Virgilio Borges8afa49b7b112
diff --git a/README.md b/README.mdindex 108160b..5c81c91 100644--- a/README.md+++ b/README.md@@ -1,12 +1,12 @@<h1 align="center">📚 book-to-skill</h1><p align="center">- <strong>Turn any technical book (PDF or EPUB) into a Claude Code skill — ready to study, reference, and use while you work.</strong>+ <strong>Turn any technical book or document into a Claude Code skill — ready to study, reference, and use while you work.</strong></p><p align="center"><img src="https://img.shields.io/badge/Claude_Code-Skill-blueviolet?style=for-the-badge" alt="Claude Code Skill">- <img src="https://img.shields.io/badge/PDF%20%2B%20EPUB-supported-green?style=for-the-badge" alt="PDF + EPUB">+ <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-supported-green?style=for-the-badge" alt="Formats supported"><img src="https://img.shields.io/badge/effort-high-orange?style=for-the-badge" alt="Effort: high"><img src="https://img.shields.io/badge/License-MIT-blue?style=for-the-badge" alt="MIT License"></p>@@ -57,9 +57,11 @@ Running `/book-to-skill your-book.pdf` (or `.epub`) creates a full skill at `~/.## 🚀 Usage```-/book-to-skill <path-to-pdf-or-epub> [skill-name-slug]+/book-to-skill <path-to-document> [skill-name-slug]```+Supported document formats: PDF, EPUB, DOCX, TXT, Markdown, reStructuredText, AsciiDoc, HTML, RTF, MOBI/AZW/AZW3.+**Examples:**```bash@@ -86,9 +88,9 @@ After the skill is created, use it like any other Claude Code skill:## 🔧 Requirements-At least one extraction tool must be installed.+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.-**For PDF — choose by book type:**+**PDF — choose by book type:**| Book type | Tool | Install | Speed ||-----------|------|---------|-------|@@ -99,14 +101,22 @@ At least one extraction tool must be installed.> 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.-**For EPUB:**+**EPUB:**| Tool | Install | Quality ||------|---------|---------|| `ebooklib` + `beautifulsoup4` | `pip3 install ebooklib beautifulsoup4` | ⭐⭐⭐ Best || stdlib `zipfile` | built-in — no install needed | ⭐⭐ Always available |-The extraction script tries tools in order and uses the first available. If nothing is found, it tells you exactly which command to run.+**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 | — |---diff --git a/SKILL.md b/SKILL.mdindex f6f89e1..990acf1 100644--- a/SKILL.md+++ b/SKILL.md@@ -202,6 +202,35 @@ Wait for the user to confirm before proceeding. If they say "analyze only", swit---+## Step 2.6 — REPL-style access for large books (> 50k tokens)++Inspired by the Recursive Language Model (RLM) paradigm: treat `full_text.txt` as a queryable corpus, not a single read. Loading the whole file into context burns budget you will need later for generation.++For books over ~50k tokens, prefer programmatic probes over `Read(full_text.txt)` without bounds:++```bash+# Size check before any Read+wc -w "$FULL_TEXT_PATH"++# Find chapter offsets without loading the whole file+grep -n -E "^\s*(Chapter|CHAPTER)\s+[0-9]+" "$FULL_TEXT_PATH" | head -40++# Pull only the chapter you need (lines start..end inclusive)+sed -n '<start>,<end>p' "$FULL_TEXT_PATH"++# Verify a framework is actually mentioned before claiming it in SKILL.md+grep -c -i "westrum\|dora" "$FULL_TEXT_PATH"++# Targeted Read with offset/limit avoids dumping the full file+# Read(file_path=full_text.txt, offset=<line>, limit=<lines>)+```++Use this approach for Step 3 (structure analysis), Step 7 (per-chapter summaries), and Step 8 (glossary / patterns extraction). On books under 50k tokens, a single `Read` is fine.++Why this matters: a 200-page book is ~75k tokens. Re-reading it once per chapter (28 passes) costs ~2M input tokens; using grep + sed to pull only relevant slices keeps generation cost proportional to the output, not the source.++---+## Step 3 — Analyze book structureRead the first 8,000 characters of the extracted `full_text.txt` to identify:diff --git a/scripts/extract.py b/scripts/extract.pyindex 3e855bc..da9b005 100644--- a/scripts/extract.py+++ b/scripts/extract.py@@ -552,9 +552,14 @@ def detect_structure(text: str) -> dict:)chapters_found = [l.strip() for l in lines if chapter_pattern.match(l)]- # Look for ToC indicators- toc_keywords = ["table of contents", "contents", "índice", "sumário"]- has_toc = any(kw in text[:5000].lower() for kw in toc_keywords)+ # Look for ToC indicators in the first ~30k chars (front matter is often well past 5k:+ # copyright pages, praise, dedications, forewords). Require the keyword to appear on+ # its own line to avoid false positives like "the contents of this book are...".+ toc_pattern = re.compile(+ r"^\s*(?:table of contents|contents|índice|sumário)\s*$",+ re.IGNORECASE | re.MULTILINE,+ )+ has_toc = bool(toc_pattern.search(text[:30000]))return {"chapters_detected": len(chapters_found),@@ -800,6 +805,11 @@ def main():print(f" Tokens : ~{tokens // 1000}K")print(f" Chapters: {structure['chapters_detected']} detected")print(f" ToC : {'yes' if structure['has_toc'] else 'not detected'}")+ if not structure["has_toc"]:+ print(+ " WARN : No table of contents detected — chapter mapping in Step 3 "+ "will rely on heading scan only, which may miss or duplicate sections."+ )print(f"\n Text -> {OUTPUT_TEXT}")print(f" Meta -> {OUTPUT_META}")