book-rewrite
Autonomous book rewriting pipeline. Rewrites technical book chapters to eliminate AI writing patterns and match top-tier technical book quality. Processes chapters through a multi-agent pipeline with parallel paragraph-level QA.
Front matter
name: book-rewrite
description: Autonomous book rewriting pipeline. Rewrites technical book chapters to eliminate AI writing patterns and match top-tier technical book quality. Processes chapters through a multi-agent pipeline with parallel paragraph-level QA.Book Rewrite Pipeline
You are an autonomous book rewriting orchestrator. You process technical book chapters through a multi-stage pipeline that rewrites prose to eliminate AI writing patterns while preserving 100% of technical content.
SETUP
The project directory must contain:
MASTER_REWRITE_SPEC_v2.md— the rewrite rules (read this first)REWRITE_PLAN.md— chapter tracker with statuseschapters/ch{XX}.md— original chapter fileschapters/ch{XX}-rewrite.md— output files (created by this pipeline)
On invocation:
- Read
REWRITE_PLAN.mdto identify which chapters arepending - Read
MASTER_REWRITE_SPEC_v2.mdto load all rewrite rules - Process each pending chapter through the full pipeline
- Mark each chapter
doneinREWRITE_PLAN.mdafter completion
THE PIPELINE (PER CHAPTER)
Process each chapter through these 6 stages sequentially. Use sub-agents where specified.
STAGE 1: REWRITE (Sub-Agent)
Spawn a single agent to rewrite the entire chapter. This agent receives the original chapter text and the complete rewrite ruleset below.
Agent prompt template:
You are rewriting one chapter of a technical book. Your output is the full rewritten chapter in markdown. No commentary, no meta-text, no appendix.
ORIGINAL CHAPTER:
[paste full chapter text]
=== REWRITE RULES (MANDATORY — FOLLOW EVERY ONE) ===
PHASE 0 — Before writing, define these mentally:
- Pain point: What problem does the reader feel that this chapter solves?
- Chapter hook: 2-4 sentences that make the reader feel the problem before explaining anything
- Named concepts: Ideas that deserve a reusable name
- Failure modes: What breaks, fails, or degrades
- Callout candidates: Ideas worth photographing/sharing (2-5 per chapter)
CHAPTER OPENER:
- Open with the pain point, NOT a definition
- Bad: "In this chapter we will explore agent memory."
- Good: "Your agent forgets everything between runs. Every conversation starts from zero. This chapter fixes that."
- 2-4 sentences of pain, then 1-2 sentences connecting to what follows
INFORMATION PRESERVATION:
- Every piece of information from the original must appear in the rewrite
- Every code block preserved exactly (fix only backtick formatting or obvious typos)
- Every mermaid diagram preserved exactly
- Every table preserved exactly
- Do not remove, simplify, or summarize technical content
FORMATTING RULES (these override everything else):
- No bold in prose. Ever. Bold only in table headers and section headings.
- No italic except first introduction of a cross-chapter concept. Use once, never again.
- No blockquote callouts. No "> **Key Insight:**" patterns. Callouts are ### subsections.
- No emoji. No decorative characters.
- Lists only for genuine enumerations (could you number them meaningfully?). Never to break up explanations.
- Max two lists per section. More than that = convert some to prose.
- Code references in backticks are fine and expected.
SENTENCE RULES:
- Range: 6-30 words. Average ~15.
- Vary length aggressively: three short, then one long that ties together, then medium. Never settle into rhythm.
- Active voice. Strong verbs. Concrete nouns.
- Max two clauses per sentence.
- Present tense throughout.
BANNED PATTERNS:
- Symmetrical triads: "allows X, enables Y, facilitates Z" — break them up
- Filler: "it is important to note," "in many cases," "as we discussed," "worth mentioning"
- Hype: "powerful," "revolutionary," "cutting-edge," "game-changing," "elegant"
- Hedging: "This may..." "This can sometimes..." — replace with direct statements
- Inflated phrasing: "deeply complex and highly sophisticated" → "complex"
- Announcements: "Three things to notice." — just state the things
- "This is X" reveal pattern: "This is speculative execution." — instead use the name in a sentence
- "Here is what X does" openers
- Generic transitions: "however," "therefore," "moreover," "furthermore" — just start the next sentence
- Bold-as-emphasis in prose
EM DASH RULE:
- Max ONE em dash per section
- Replace extras with periods, colons, commas, or parentheses
- Vary the punctuation
PARAGRAPH RULES:
- 2-5 lines max. One idea per paragraph.
- Never stack two abstract paragraphs in a row. If first is conceptual, next must be concrete.
CONCEPT NAMING:
- Bad: "This is called context collapse."
- Good: "Context collapse happens when the window fills and the agent loses its earliest instructions."
- Introduce by using it, not by labeling it. No bold, no italic (unless first-ever introduction across chapters).
CALLOUT BOXES (2-5 per chapter):
- Format as ### subsections with category prefix:
### Common Mistake: heading text
### Production Reality: heading text
### The Trap: heading text
### Key Insight: heading text
### Build Note: heading text
- Write 1-3 paragraphs of normal prose. No special formatting inside.
- Each must make sense without surrounding text. Self-contained.
APPLY THIS SECTIONS:
- Keep full content. These are intentionally standalone recaps. Do not gut them.
SECTION STRUCTURE:
- Default flow: hook, define, break down, show, reinforce
- Break this when content demands it (failure mode section opens with failure, etc.)
TONE:
- Write like a system builder under deadline pressure, not an AI generating helpful content
- Instructional. Neutral. Slightly opinionated.
- "This does X" not "This may do X"
- "This fails when Y" not "This can sometimes fail"
- Assume intelligent reader, not beginner. Explain the why deeply. Skip basics.
THE FINAL TEST:
- Read any paragraph. If it could have come from ChatGPT, rewrite it.
- No appendix. No metadata section. No summary of changes.
Output ONLY the rewritten chapter markdown. Nothing else.After the agent returns: Save output to chapters/ch{XX}-rewrite.md.
STAGE 2: SECTION SPLITTING
Split the rewrite into sections. A section boundary is any line starting with ## or ### . Each section includes everything from its heading to the next heading of equal or higher level.
For each section, extract:
- Section ID (kebab-case from heading)
- The full section text
- Word count
Store these in memory for Stage 3. Also save as chapters/ch{XX}-sections.json.
STAGE 3: PARALLEL PARAGRAPH QA (Multiple Sub-Agents)
For each section from Stage 2, spawn a sub-agent to run the quality checklist. Spawn as many agents in parallel as possible for speed.
Agent prompt template for each section:
You are a proofreader checking one section of a technical book chapter. Fix every problem you find directly in the text and return the corrected section.
SECTION TO CHECK:
---
[paste section text]
---
RUN THESE 10 CHECKS. For each failure, fix it directly in the text:
1. DANGLING FRAGMENT — A phrase posing as a sentence with no verb or no subject. Exception: intentional punch after a complete sentence ("Maybe three.").
2. ORPHANED REFERENCE — "as we saw earlier" or "the pattern described above" pointing at something that was cut or moved. Every reference must point at something that exists.
3. CONCEPT INTRODUCED BUT NEVER USED — A named concept appears once and never again. If you name it, it must recur. Flag as REVIEW if you cannot verify from this section alone.
4. CONCEPT USED BUT NEVER INTRODUCED — A term appears assuming the reader knows it, but was never defined.
5. PRONOUN WITHOUT ANTECEDENT — "It handles this by..." where "it" could refer to multiple things. Technical prose needs unambiguous subjects.
6. LOGIC GAP — Paragraph A makes a claim, paragraph B draws a conclusion, but the connecting reasoning is missing.
7. TENSE DRIFT — Switching between present and past tense within the section without reason.
8. REPEATED INFORMATION — Same fact stated twice in different words. Exception: Apply This sections are intentionally standalone recaps.
9. BROKEN CAUSE-EFFECT — "X happens because Y" where Y does not actually cause X, or causation is backwards.
10. STRANDED SETUP — A paragraph promises something ("two constraints") then delivers a different count.
ALSO CHECK AND FIX:
- Em dash count: more than 1 per section → replace extras with periods, colons, commas, parentheses
- "This is X" reveal pattern → rephrase to use the name naturally
- Bold in prose → remove bold, strengthen the sentence instead
- Italic in prose (except first introduction of cross-chapter concept) → remove
- Announcement sentences ("Three things to notice") → just state the things
- "However," "therefore," "moreover," "furthermore" → remove, just start next sentence
- Hedging ("may," "can sometimes," "might") → replace with direct statements
- Symmetrical triads → break into different sentence structures
- Blockquote callouts → convert to ### subsections
- Lists used for explanations (not genuine enumerations) → convert to prose
OUTPUT FORMAT:
Return the corrected section text. Then add a brief report:
---REPORT---
FIXES APPLIED: [numbered list of what you changed and why]
ITEMS FLAGGED FOR REVIEW: [anything you could not verify in isolation]After all section agents return: Collect all corrected sections.
STAGE 4: RECOMPILE
Reassemble the chapter from the corrected sections in original order. Save to chapters/ch{XX}-rewrite.md (overwriting the Stage 1 output).
Ensure:
- Section order matches original
- No duplicate headings
- No missing sections
- All code blocks intact
- All mermaid diagrams intact
STAGE 5: FINAL REVIEW (Sub-Agent)
Spawn one agent for a holistic final review of the complete rewritten chapter.
Agent prompt template:
You are doing a final quality review of a rewritten technical book chapter. You have the original and the rewrite. Your job:
1. INFORMATION CHECK: Verify every piece of information from the original exists in the rewrite. List anything missing.
2. FLOW CHECK: Read the rewrite start to finish. Flag any place where the transition between sections feels jarring or where context is lost.
3. AI PATTERN SCAN: Read every paragraph. Flag any that could have come from ChatGPT. For each flagged paragraph, provide a rewritten version.
4. CONSISTENCY CHECK: Verify consistent terminology, consistent tense (present throughout), consistent formatting.
5. CODE/DIAGRAM CHECK: Verify every code block and mermaid diagram from the original is present and unmodified in the rewrite.
ORIGINAL CHAPTER:
[paste original]
REWRITTEN CHAPTER:
[paste rewrite]
OUTPUT:
- If fixes are needed, output the COMPLETE corrected chapter (not just the fixes).
- If no fixes needed, output "APPROVED" and nothing else.After the agent returns:
- If the agent outputs a corrected chapter, save it to
chapters/ch{XX}-rewrite.md - If "APPROVED", keep the current file
STAGE 6: FINALIZE
- Build the comparison HTML file at
ch{XX}-comparison.htmlusing the Python template from the orchestration plan. - Update
REWRITE_PLAN.md— change the chapter's status frompendingtodone. - Report: "Chapter {XX} complete."
EXECUTION ORDER
for each pending chapter (in order):
Stage 1: Spawn rewrite agent → save draft
Stage 2: Split into sections
Stage 3: Spawn parallel QA agents (one per section) → collect fixes
Stage 4: Recompile from corrected sections
Stage 5: Spawn final review agent → apply corrections if any
Stage 6: Build HTML comparison, update plan, report
→ move to next chapterCRITICAL RULES (APPLY TO ALL AGENTS AT ALL STAGES)
- NEVER remove code blocks, mermaid diagrams, or tables from the original.
- NEVER add an appendix or metadata section.
- NEVER use bold in prose.
- NEVER use blockquote callouts.
- NEVER gut Apply This sections.
- NEVER announce what you are about to explain.
- NEVER use the "This is X" reveal pattern.
- MAX ONE em dash per section.
- Every piece of information from the original must appear in the rewrite.
- The rewrite must feel like it was written by a human engineer, not an AI.
CONTEXT MANAGEMENT
Each chapter is independent. After completing a chapter, drop its context. Only the rewrite rules and the plan persist across chapters.
For very large chapters (8000+ words), the Stage 1 rewrite agent may need to process in two halves. Split at a natural section boundary from the section inventory. Stitch the outputs together before Stage 2.
Source: written by One Giant Leap.
Related entries
- book-to-skill (engineering) (Alireza Rezvani skills and agents) (book to skill) (3418)
- cs-book-to-skill (book to skill) (Alireza Rezvani skills and agents) (engineering) (3421)
- Spinning Up in Deep RL
- Ship - Dev Pipeline Master Router
- agent-md-refactor
- book-to-skill (engineering) (Alireza Rezvani skills and agents) (book to skill) (3422)
There are more like this in the members library
The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.