Book Fix — Remediation Prompt Generator + Executor
Purpose
Take the findings from a /book-audit and convert them into a one-shot, end-to-end remediation prompt that another agent (or this one) can execute to bring the book to GREEN. Or, if the user prefers, execute the fix in place.
The output prompt MUST follow the structure established by fix-on-the-verge.md and fix-reframation.md:
- Header — RED/YELLOW status declared, rationale, what's distinctive about this book's defects.
- INPUTS — PDF path, target MD files, scratch dirs, archive dir.
- OPERATING PRINCIPLES — verbatim only, PDF is source of truth, no fabrication.
- ISSUES TO FIX — numbered, each with: file path, problem, current (wrong) text, PDF source (correct) text inlined, fix instructions, verification grep commands.
- EXECUTION ORDER — strict dependency-ordered sequence.
- ACCEPTANCE CRITERIA — checkbox list of every condition that must hold post-fix.
- DELIVERABLES — what the executing agent must return.
- OUT OF SCOPE — explicitly excluded items (summaries, vector store re-upload, translations).
Invocation
$ARGUMENTS should specify:
<book-slug>— Required.--audit <path>— Path to the prior/book-auditreport. Default: most recent file underdocs/build/audits/<book-slug>-*.md.--mode <generate|execute|both>— Default:generate(write the prompt without executing).generate— writedocs/build/prompts/fix-<book-slug>.mdand stop.execute— read existing fix prompt and execute every issue.both— generate and execute back-to-back.
--archive-dir <path>— Where to pre-archive the current MD before edits. Default:corpus/alan_hirsch/_archive/<book-slug>-<YYYY-MM-DD>-<reason>/.
Process
Generate mode
- Read the audit report. Extract every numbered Sample with its findings, severity, and suggested fix.
- Group findings by class. The exemplar prompts use these stable issue groupings (renumber as needed for the new book):
- CRITICAL correctness — fabricated content, rewritten paragraphs, placeholder text, content rewrites.
- Notes-chapter restoration — missing footnote prefixes, mislabeled chapters, missing chapter blocks, fabricated quotations.
- Multi-paragraph blockquote continuation drops.
- Alternate-line content drops in long-form quotations.
- Heading hierarchy collapse (book-wide pass).
- Footnote-syntax standardization (bracketed
[N], caret^N, Markdown[^N]). - Page-header / page-footer bleed.
- Kerning artifacts (letter-spaced caps, joined words).
- Stray spaces / italic markup loss.
- Misplaced section dividers.
- Frontmatter integrity (canonical_title, opening_excerpt, content_sha256, word_count).
- Comprehensive un-audited-chapter sweep.
- Inline verbatim PDF source text for every CRITICAL fix. Run
grepagainst the source PDF text to copy the exact original passage. This is non-negotiable — the executing agent cannot restore content it cannot see. - Provide verification commands for every issue using
grep -c,grep -nE, or Python one-liners. Each issue must have a binary pass/fail check. - Write the prompt to
docs/build/prompts/fix-<book-slug>.md. - Render a summary to the user listing every issue number with its one-line description.
Execute mode
- Read the prompt. Verify it exists at
docs/build/prompts/fix-<book-slug>.md. - Pre-archive the current MD to
corpus/alan_hirsch/_archive/<book-slug>-<YYYY-MM-DD>-pre-fix/. - Extract PDF reference text to
/tmp/<book-slug>-fix/source.txt. - Walk the issues in execution order as specified by the prompt. For each:
- Apply the fix using
EditorWritetools. - Run the verification command immediately after.
- If verification fails, do not advance — investigate and re-apply.
- Apply the fix using
- After all issues are fixed:
- Re-run universal sweeps: trailing whitespace, kerning artifacts, word-joining, page-header bleed.
- Recompute frontmatter
content_sha256,word_count,char_count,estimated_reading_timefor every edited file. - Update
book.jsontotals.
- Run final acceptance verification. Walk every checkbox in the prompt's Acceptance Criteria; report PASS/FAIL per item.
- Recommend the next skill. If all PASS, advance to
/book-frontmatter(Phase 02 schema validation) or directly to/book-ingest(Phase 03).
Operating Principles
- The PDF is the source of truth. Every restoration must be character-faithful to the PDF.
- Inline verbatim source text in the prompt. The executing agent cannot restore what it cannot see; do not write "look up the original passage" — copy it.
- Provide verification commands for every fix. Every issue gets a
grep -cor equivalent that returns 0 or 1, not "review the diff". - Issue ordering matters. Fabrication fixes first (so the body is correct before structural passes run), Notes rebuild before footnote-syntax standardization (so refs can match definitions), heading hierarchy book-wide before per-chapter spot fixes.
- No speculative restoration. If the PDF is unclear, leave a
<!-- TODO: verify against print PDF p.NN -->and document it in the deliverables. Do not invent text. - Pre-archive every time. The current MD may contain hand-edits; preserve them under
_archive/before any sed/script run.
Anti-patterns
- ❌ Writing a fix prompt without inlining the verbatim PDF source text for fabrication fixes.
- ❌ Issuing fixes in non-dependency order (e.g., footnote-syntax conversion before Notes-chapter rebuild).
- ❌ Running automated sweeps (sed across all files) before the critical correctness fixes — sweeps may collide with hand edits or paraphrase content the script can't distinguish.
- ❌ Marking the book GREEN without re-running
/book-auditagainst the post-fix MD.
References
- docs/build/prompts/fix-on-the-verge.md — RED-status exemplar with 20 issues.
- docs/build/prompts/fix-reframation.md — RED-status exemplar with 17 issues, footnote-syntax pivot.
- docs/build/prompts/fix-fast-forward-to-mission.md — YELLOW-status exemplar with 13 issues.