An AI skill that turns books into animated, narrated, interactive web experiences
JavaScript ai-agentsai-educationanimationclaudeclaude-codeclaude-skillsedtecheducationinteractive-textbookscormtext-to-video
fix(scripts): handle flat PDFs and non-ASCII console output
Nikolai Ivakhnenkodbd8a39a6397
diff --git a/.claude/skills/papermorph/SKILL.md b/.claude/skills/papermorph/SKILL.mdindex 2e4f163..a78cec2 100644--- a/.claude/skills/papermorph/SKILL.md+++ b/.claude/skills/papermorph/SKILL.md@@ -35,7 +35,7 @@ site/ static output; private sources stay outsideResolve intake, book map and pilot decisions with the user; reuse answers and approvals already given.1. **Intake.** Choose a slug; create `books/<book>/BOOK.md` from the template. Record readers, tone, primary language, scope and assets/guide. Ask for missing decisions together, with defaults.-2. **Split.** Run `uv run --with pymupdf SKILL/scripts/outline.py books/<book>/book.pdf`; use `--level N -o books/<book>/sections.json` at chapter depth. For a PDF without bookmarks, inspect `split_pages.py … --pages 1-12 --out books/<book>/pages`, then write the map from its contents (schema: `outline.py --help`). Match the map to the contents; extract chapter text with `split_pages.py … --sections books/<book>/sections.json --out books/<book>/pages --text-only`.+2. **Split.** Run `uv run --with pymupdf SKILL/scripts/outline.py books/<book>/book.pdf`; use `--level N -o books/<book>/sections.json` at chapter depth. For a PDF without usable chapter bookmarks, inspect `split_pages.py … --pages 1-12 --out books/<book>/pages`, then write the map from its contents (schema: `outline.py --help`). Match the map to the contents; extract chapter text with `split_pages.py … --sections books/<book>/sections.json --out books/<book>/pages --text-only`.3. **Book map.** Read contents and chapter openings; inspect more text where the scope is unclear. Create `chapters.md` with columns `# | Title | Unit | Minutes | Status` (planned, ready, user-approved); put colours and candidate recurring visual models in BOOK.md. Confirm the list and visual approach with the user.4. **Initialize.** Follow [site.md](references/site.md#start-a-book-folder) to copy the book engine, cover/contents and chapter skeleton before making the pilot.5. **Pilot.** Make chapter 1 through the chapter loop. Deliver it for the user's review and record approved conventions in BOOK.md. Implement helpers as needed; share one when another chapter uses it.diff --git a/.claude/skills/papermorph/references/review.md b/.claude/skills/papermorph/references/review.mdindex 1287a0e..2ec51de 100644--- a/.claude/skills/papermorph/references/review.md+++ b/.claude/skills/papermorph/references/review.md@@ -18,6 +18,7 @@ Make a brief judgment of:- a question card covering the object it asks about;- leftovers from the previous beat, half faded;- geometry contradicting the intended values, spacing or area;+- shapes inside circles or curves crossing the outline; check thin geometry on the full-size `chNN_bII_T.png`, not only on the sheet;- text too small to read at half size, or too much text at once;- inconsistent colours for the same idea.diff --git a/.claude/skills/papermorph/scripts/outline.py b/.claude/skills/papermorph/scripts/outline.pyindex 3855d3f..d376972 100644--- a/.claude/skills/papermorph/scripts/outline.py+++ b/.claude/skills/papermorph/scripts/outline.py@@ -12,8 +12,9 @@ page where the chapter itself begins. Pages before the first chapter becomeEvery PDF page lands in exactly one section, numbered by PDF page order (from 1),not by printed page numbers.-Without bookmarks, render the contents using split_pages.py book.pdf --pages 1-12,-then write sections.json from those pages. Its JSON array covers every PDF page once:+Without usable chapter bookmarks, render the contents using split_pages.py book.pdf+--pages 1-12, then write sections.json from those pages. Its JSON array covers every+PDF page once:[{"folder":"00_front","title":"Front matter","start":1,"end":12},{"folder":"ch01","title":"Chapter title","start":13,"end":40,"unit":"Part one"}, ...]Adjust boundaries to the actual PDF; start/end are inclusive PDF page numbers.@@ -25,8 +26,14 @@ from pathlib import Pathimport pymupdf+FLAT_PDF_HINT = ("Render contents with split_pages.py book.pdf --pages 1-12, "+ "then write sections.json from them (schema: outline.py --help).")+def main():+ # Captured output (a pipe) uses the system code page on Windows; bookmark titles may be any language.+ for stream in (sys.stdout, sys.stderr):+ stream.reconfigure(encoding="utf-8", errors="replace")ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)ap.add_argument("pdf", type=Path)ap.add_argument("--level", type=int, help="bookmark depth of chapters; omit to print the tree")@@ -36,11 +43,14 @@ def main():toc = doc.get_toc() # [level, title, page]n = len(doc)if not toc:- sys.exit("No bookmarks. Render contents with split_pages.py book.pdf --pages 1-12, then write sections.json from them.")+ sys.exit(f"No bookmarks. {FLAT_PDF_HINT}")if a.level is None:for lv, title, page in toc:print(f"{' ' * (lv - 1)}[{lv}] p{page} {title}")- print(f"\n{n} pages. Rerun with --level N (the depth whose entries are chapters).")+ if len(toc) < 2:+ print(f"\n{n} pages, one bookmark: it does not split the book into chapters. {FLAT_PDF_HINT}")+ else:+ print(f"\n{n} pages. Rerun with --level N (the depth whose entries are chapters).")returnchapters = [(i, t, p) for i, (lv, t, p) in enumerate(toc) if lv == a.level and p >= 1]@@ -81,6 +91,10 @@ def main():print(f"{len(sections)} sections, {sum(1 for s in sections if s['folder'].startswith('ch'))} chapters -> {a.output}")else:print(text)+ if len(chapters) < 2:+ sys.stdout.flush() # keep the hint after the result when both streams are captured+ print(f"One chapter at level {a.level}. If the book has more chapters, its bookmarks do not mark them. "+ f"{FLAT_PDF_HINT}", file=sys.stderr)if __name__ == "__main__":diff --git a/.claude/skills/papermorph/scripts/shot.py b/.claude/skills/papermorph/scripts/shot.pyindex 8dd135e..c0fff70 100644--- a/.claude/skills/papermorph/scripts/shot.py+++ b/.claude/skills/papermorph/scripts/shot.py@@ -53,9 +53,14 @@ async def main(a):if __name__ == "__main__":+ # Captured output (a pipe) uses the system code page on Windows; page errors may be any language.+ for stream in (sys.stdout, sys.stderr):+ stream.reconfigure(encoding="utf-8", errors="replace")ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)- ap.add_argument("chapter")- ap.add_argument("specs", nargs="*")+ ap.add_argument("chapter", help="chapter folder under --url, e.g. ch07")+ ap.add_argument("specs", nargs="*",+ help="moments as BEAT:TIME; BEAT is the index in BEATS from 0 (the player shows BEAT+1), "+ "TIME is seconds, open, mid or end; e.g. 3:end 5:4.5 (default: every beat at open and end)")ap.add_argument("--moments", nargs="*", default=[], choices=["mid"], help="extra moments for every beat")ap.add_argument("--url", default="http://localhost:8765/")ap.add_argument("--out", type=Path, default=Path("/tmp/animebook-shots"))diff --git a/.claude/skills/papermorph/scripts/split_pages.py b/.claude/skills/papermorph/scripts/split_pages.pyindex d52d7b5..81938ed 100644--- a/.claude/skills/papermorph/scripts/split_pages.py+++ b/.claude/skills/papermorph/scripts/split_pages.py@@ -19,12 +19,16 @@ never published with the site.import argparseimport jsonimport re+import sysfrom pathlib import Pathimport pymupdfdef main():+ # Captured output (a pipe) uses the system code page on Windows; section titles may be any language.+ for stream in (sys.stdout, sys.stderr):+ stream.reconfigure(encoding="utf-8", errors="replace")ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)ap.add_argument("pdf", type=Path)ap.add_argument("--sections", type=Path, default=Path("sections.json"))@@ -48,7 +52,7 @@ def main():ap.error("use --pages for a preview or --only for mapped sections")sections = [{"folder": "preview", "title": f"Pages {start}-{end}", "start": start, "end": end}]else:- sections = json.loads(a.sections.read_text(encoding="utf-8"))+ sections = json.loads(a.sections.read_text(encoding="utf-8-sig")) # PowerShell 5.1 writes a BOMnxt, seen = 1, set()for s in sections:f, st, en = s["folder"], s["start"], s["end"]