Skip to content

Turn any technical book PDF into a Claude Code skill — ready to study, reference, and use while you work.

docs: sync architecture, skill spec, and README with v1.3.0

Virgilio Borges807c7fab3567
diff --git a/README.md b/README.md
index 22d7d7a..5f0263b 100644
--- a/README.md
+++ b/README.md
@@ -277,10 +277,11 @@ python3 tools/discovery_tax.py --full-text /tmp/book_skill_work/full_text.txt --
> **Honest caveats:** (1) the discovery figures are a one-time cost and a *model*
> using the book's real ToC/chapter sizes — a well-tuned agent lands nearer the best
> case; the context-dump cost, by contrast, recurs on **every** turn. (2) The tool
-> needs explicit `Chapter N` / `Capítulo N` headings to segment a book; titles-only
-> or roman-numeral books (and EPUBs extracted without `ebooklib`) won't segment
-> cleanly. book-to-skill wins when you return to the knowledge repeatedly; for a
-> single one-off read, a plain PDF agent is fine.
+> needs recognizable chapter headings to segment a book — it detects Arabic,
+> Roman (`Chapter I` / line-initial `I.`), CJK, Korean (`제N장`), Thai, and
+> several European forms, but a titles-only book (or an EPUB extracted without
+> `ebooklib`) may not segment cleanly. book-to-skill wins when you return to the
+> knowledge repeatedly; for a single one-off read, a plain PDF agent is fine.
---
diff --git a/SKILL.md b/SKILL.md
index e224b8f..7ffd49c 100644
--- a/SKILL.md
+++ b/SKILL.md
@@ -185,9 +185,9 @@ Read `<tempdir>/book_skill_work/metadata.json` and present the user with an esti
Output (skill files generated/updated): ~<N>K tokens
Total: ~<N>K tokens
- Reference prices (as of 2025):
- Claude Sonnet 4.5 → ~$<X> USD
- Claude Haiku 4.5 → ~$<X> USD
+ Cost: multiply the token counts above by your model's current
+ input/output per-1M-token rates (prices and model names change often —
+ do not hardcode them; quote today's rate and label it as an estimate).
⏱ Estimated time: ~<N> minutes
@@ -201,7 +201,7 @@ Read `<tempdir>/book_skill_work/metadata.json` and present the user with an esti
- Input tokens ≈ `estimated_tokens` from metadata × 1.3 (prompts overhead per chapter pass)
- Output tokens ≈ chapters × per-chapter budget + 4,000 (SKILL.md) + 4,500 (glossary + patterns + cheatsheet)
- Per-chapter budget midpoint by `BOOK_TYPE` (DEPTH is decided later in Step 4 and can raise it): `text` ≈ 1,000, `technical` ≈ 1,800. If the user has already indicated reference-only vs deep study, use the matching row of the Step 7 matrix.
-- Price: Sonnet input=$3/MTok output=$15/MTok — Haiku input=$0.80/MTok output=$4/MTok
+- Cost: report the token counts and multiply by the user's current per-1M-token input/output rates. Do NOT hardcode dollar figures — model names and prices change; if you show one, label it an estimate and date it.
Wait for the user to confirm before proceeding. If they say "analyze only", switch to Mode 2.
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index 4294997..17a943d 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -6,12 +6,13 @@ document into clean text + metadata; the agent turns that into a structured skil
```
┌─────────────────────────── EXTRACTOR (Python, deterministic) ──┐
- documents │ scripts/extract.py → extractor/ │
- (pdf/epub/ │ ├─ utils.py CLI parse · multi-source resolve · runner │
- docx/...) │ ├─ config.py supported extensions · paths · deps map │
- │ │ ├─ dependencies.py optional-dep probing · --check report │
- ▼ │ └─ parsers/ pdf · epub · docx · html · rtf · calibre · │
- ───────────│ text (best tool first, stdlib fallback) │
+ documents │ scripts/extract.py (shim) → book_to_skill/ │
+ (pdf/epub/ │ ├─ cli.py · utils.py CLI parse · multi-source · runner │
+ docx/...) │ ├─ config.py supported extensions · paths · deps │
+ │ │ ├─ dependencies.py optional-dep probing · --check report │
+ ▼ │ ├─ sanitize.py strip invisible/zero-width Unicode │
+ ───────────│ └─ parsers/ pdf · epub · docx · html · rtf · │
+ │ calibre · text (best tool, fallback)│
│ output → <tempdir>/book_skill_work/ │
│ full_text.txt (all sources merged, source-marked) │
│ metadata.json (pages, words, tokens, chapters, ToC) │
@@ -60,17 +61,45 @@ document into clean text + metadata; the agent turns that into a structured skil
| Path | Responsibility |
|------|----------------|
-| `scripts/extract.py` | thin entrypoint wrapper |
-| `scripts/extractor/utils.py` | CLI parsing, multi-source resolution, chapter/ToC detection, runner |
-| `scripts/extractor/parsers/` | one module per format |
-| `scripts/extractor/dependencies.py` | optional-dependency probing + `--check` |
+| `scripts/extract.py` | thin entrypoint shim → `book_to_skill.cli` (kept so old invocations keep working) |
+| `book_to_skill/cli.py`, `utils.py` | CLI parsing, multi-source resolution, chapter/ToC detection, runner |
+| `book_to_skill/parsers/` | one module per format (`pdf`, `epub`, `docx`, `html`, `rtf`, `calibre`, `text`) |
+| `book_to_skill/config.py` | supported extensions, output paths, dependency map |
+| `book_to_skill/dependencies.py` | optional-dependency probing + `--check` |
+| `book_to_skill/sanitize.py` | strips zero-width / Unicode-tag-block characters from extracted text (see Security) |
| `tools/discovery_tax.py` | measures token cost vs context-dump / discovery loop |
-| `tools/validate_skill.py` | checks a generated SKILL.md against host rules (`--lens claude|copilot|amp`) |
+| `tools/validate_skill.py` | checks a generated SKILL.md against host rules (`--lens claude\|copilot\|amp`) |
+| `tools/scan_generated_skill.py` | advisory prompt-injection scan of a generated skill (see Security) |
| `SKILL.md` | the generator spec (Steps 0–10 + fold-in workflow) |
+## Security
+
+Untrusted documents flow into an agent's context and then into a generated skill
+that later loads into other agents — a document→context supply chain. The hardening
+is layered:
+
+- **Extraction sanitization** (`book_to_skill/sanitize.py`) — strips zero-width
+ (`U+200B/200C/200D/2060/FEFF`) and the Unicode tag block (`U+E0000–E007F`) from
+ every parser's output before metrics or `full_text.txt`, so invisible
+ document-borne instructions never reach the agent. Reports the removal count;
+ rejects a source with no visible content left.
+- **DOCX XXE / Billion-Laughs guard** (`parsers/docx.py`) — rejects any XML part
+ declaring a DTD or entities before parsing.
+- **Subprocess argument-injection** — file paths are absolutised before reaching
+ `pdftotext` / `pdfinfo` / `ebook-convert`, so a `-`-leading filename can't be read
+ as a flag.
+- **Generated-skill scan** (`tools/scan_generated_skill.py`) — an advisory step in
+ the generator (Step 9.5) that flags instruction-override phrases, model-control
+ tags, residual invisible Unicode, authority-widening frontmatter, and
+ exfiltration-shaped content across the generated `SKILL.md`, `chapters/*.md`,
+ `glossary.md`, `patterns.md`, and `cheatsheet.md`. Findings name only the rule and
+ file location — never the matched text.
+- **CI** — CodeQL, Bandit (gate on HIGH), Zizmor, and dependency CVE review on PRs.
+
## Extending
-- **New format** → add `parsers/<fmt>.py`, register its extension in `config.py`,
- wire dependency probing in `dependencies.py`, branch in `utils.extract_single_file`.
+- **New format** → add `book_to_skill/parsers/<fmt>.py`, register its extension in
+ `config.py`, wire dependency probing in `dependencies.py`, branch in
+ `utils.extract_single_file`.
- **New generation behavior** → edit the relevant Step in `SKILL.md`; keep it lean
and back the change with evidence (see CONTRIBUTING.md).