# Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine — Complete AI & LLM Reference Corpus (`llms-full.txt`)
- Repository: https://github.com/mohan-n-swamy/ops-playbook-public
- Web Discovery URL: https://mohan-n-swamy.github.io/repos/ops-playbook-public/
- License: MIT
- Keywords: sop, operations-manual, paged-media, print-css, documentation-generator, training-manual, design-system, html-to-pdf, open-source
---
## File: `AI-README.md` — AI-README.md
---
repo: "mohan-n-swamy/ops-playbook-public"
title: "Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine"
license: "MIT"
keywords: [sop, operations-manual, paged-media, print-css, documentation-generator, training-manual, design-system, html-to-pdf, open-source]
capabilities:
- "Single-source multi-edition TOC & Amazon KDP 6x9 trim/bleed/gutter engine (`build/toc.py`)."
- "Directive-aware Markdown + `source:` provenance parser (`build/md.py`)."
- "Mechanical number, contact, and verbatim-quote provenance verifier (`build/fact_gate.py`)."
- "Deprecated-claim firewall (`build/conflict_gate.py`) and source-nuance completeness gate (`build/coverage_gate.py`)."
- "Finished-PDF PyMuPDF box-breakout & ink-collision gate (`build/overlap_gate.py`, `build/pdf_gate.py`) and EPUB3 dark-mode/accessibility auditor (`build/audit_epub.py`)."
when_to_use:
- "A docs-as-code operations manual compiler and mechanical preflight suite that enforces word-for-word source number provenance, blocks deprecated SOP claims, slices role-specific editions from one TOC, and inspects finished PDFs and EPUBs for ink collisions, bleed errors, and dark-mode contrast defects."
- "Operations manuals and technical books rot when numbers drift from underlying SOPs, deprecated policies sneak back into edits, or print/EPUB builds ship with clipped footers, overlapping boxes, and unreadable dark-mode CSS."
inputs_required:
- "PLAYBOOK_TOC_CSV: Path to the master CSV defining chapters, role tracks, and numbered sub-topics"
- "EDITION_TARGET: Edition key (`hub`, `field`, or `full`) to build or audit"
- "KDP_TRIM_SIZE: Trim width x height in inches for Amazon KDP print geometry"
- "KDP_DPI_MIN: Minimum embedded image resolution enforced during print preflight"
- "FOOTER_BAND_PT: Footer band height in points reserved at the bottom of every PDF page"
- "PLAYBOOK_FOOTER_WORDS: Comma-separated wordmark tokens permitted inside the reserved PDF footer band"
quickstart:
- "python3 bin/playbook-demo.py # run TOC + fact_gate + conflict_gate + coverage_gate on starter 3-chapter playbook"
- "pytest -q tests/ # run all 6 gate & broken-fixture self-test suites (incl. PyMuPDF overlap_gate)"
---
# Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine — Machine-Readable Agent Guide
A docs-as-code operations manual compiler and mechanical preflight suite that enforces word-for-word source number provenance, blocks deprecated SOP claims, slices role-specific editions from one TOC, and inspects finished PDFs and EPUBs for ink collisions, bleed errors, and dark-mode contrast defects.
Operations manuals and technical books rot when numbers drift from underlying SOPs, deprecated policies sneak back into edits, or print/EPUB builds ship with clipped footers, overlapping boxes, and unreadable dark-mode CSS.
Key modules and entry points in this repository:
- `build/toc.py`: Single-source chapter/track/edition parser and KDP 6x9 trim/bleed/gutter calculator
- `build/md.py`: Markdown block, `::: directive`, and heading `source:` parser
- `build/fact_gate.py`: Provenance verifier checking cited paths, locators, digits, and quotes
- `build/conflict_gate.py`: Banned-claim table scanner against `docs/source-conflicts.md`
- `build/coverage_gate.py`: Source-to-chapter completeness audit gate against `docs/coverage.tsv`
- `build/overlap_gate.py`: PyMuPDF (`fitz`) R1–R4 box-breakout, ink-overlap, off-page, and footer-clipping gate
- `build/audit_epub.py`: EPUB3 dark-mode luminance, curly-quote, accessibility metadata, and spine auditor
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
When a human asks an AI coding agent to deploy or adapt `ops-playbook-public` into their stack:
1. Edit `content/reference/toc.csv` and `PARTS` in `build/toc.py` to define your organization's role tracks and editions.
2. Place canonical SOP markdown files in `content/sources/` and author chapters in `content/book/chNN.md` with `source:` lines under each heading.
3. Wire `python3 build/fact_gate.py`, `conflict_gate.py`, and `overlap_gate.py` into CI so no unverified claim or layout collision can merge.
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
---
## File: `.env.example` — Environment Contract (.env.example)
```ini
# Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine — Environment Contract
# Copy to .env and set values for your organization.
# Path to the master CSV defining chapters, role tracks, and numbered sub-topics
PLAYBOOK_TOC_CSV=./content/reference/toc.csv
# Edition key (`hub`, `field`, or `full`) to build or audit
EDITION_TARGET=full
# Trim width x height in inches for Amazon KDP print geometry
KDP_TRIM_SIZE=6.0x9.0
# Minimum embedded image resolution enforced during print preflight
KDP_DPI_MIN=300
# Footer band height in points reserved at the bottom of every PDF page
FOOTER_BAND_PT=34.0
# Comma-separated wordmark tokens permitted inside the reserved PDF footer band
PLAYBOOK_FOOTER_WORDS=ISO,CERTIFIED,OPERATIONS,PLAYBOOK
```
---
## File: `AGENTS.md` — AGENTS.md
# AGENTS.md — Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine
Read this file first before modifying `ops-playbook-public`.
## Purpose
A docs-as-code operations manual compiler and mechanical preflight suite that enforces word-for-word source number provenance, blocks deprecated SOP claims, slices role-specific editions from one TOC, and inspects finished PDFs and EPUBs for ink collisions, bleed errors, and dark-mode contrast defects.
## Commands
```bash
python3 bin/playbook-demo.py # run TOC + fact_gate + conflict_gate + coverage_gate on starter 3-chapter playbook
pytest -q tests/ # run all 6 gate & broken-fixture self-test suites (incl. PyMuPDF overlap_gate)
```
## Module Map
- `build/toc.py`: Single-source chapter/track/edition parser and KDP 6x9 trim/bleed/gutter calculator
- `build/md.py`: Markdown block, `::: directive`, and heading `source:` parser
- `build/fact_gate.py`: Provenance verifier checking cited paths, locators, digits, and quotes
- `build/conflict_gate.py`: Banned-claim table scanner against `docs/source-conflicts.md`
- `build/coverage_gate.py`: Source-to-chapter completeness audit gate against `docs/coverage.tsv`
- `build/overlap_gate.py`: PyMuPDF (`fitz`) R1–R4 box-breakout, ink-overlap, off-page, and footer-clipping gate
- `build/pdf_gate.py`: PyMuPDF (`fitz`) finished-PDF word-box footer-collision and off-page preflight gate
- `build/audit_epub.py`: EPUB3 dark-mode luminance, curly-quote, accessibility metadata, and spine auditor
## Invariants
1. Keep all organization names, credentials, domains, and thresholds in `.env` or external config files. Never hardcode company names, host IPs, or secrets in source files.
2. Deterministic business logic belongs in code and lookup tables, not inside LLM prompts.
3. Update `docs/HLD.md`, `docs/LLD.md`, and `.env.example` in the same commit whenever an interface or environment variable changes.
4. Run the repository smoke check and secret scan before opening a pull request.
---
## File: `docs/PRD.md` — Product Requirements Document (docs/PRD.md)
# Product Requirements Document — Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine
A docs-as-code operations manual compiler and mechanical preflight suite that enforces word-for-word source number provenance, blocks deprecated SOP claims, slices role-specific editions from one TOC, and inspects finished PDFs and EPUBs for ink collisions, bleed errors, and dark-mode contrast defects.
## 1. Problem
Operations manuals and technical books rot when numbers drift from underlying SOPs, deprecated policies sneak back into edits, or print/EPUB builds ship with clipped footers, overlapping boxes, and unreadable dark-mode CSS.
## 2. Users and Jobs-to-be-Done
| Persona | Job-to-be-Done |
|---|---|
| Operations Excellence / Training Lead | Publish role-specific print and mobile EPUB handbooks (`hub`, `field`, `full`) guaranteed to match current SOP numbers |
| Technical Author / Indie Publisher | Validate Amazon KDP 6x9 trim/bleed/gutter geometry, PDF ink-overlap rules, and EPUB3 dark-mode legibility in CI |
| AI Documentation Engineer | Use `fact_gate.py` and `conflict_gate.py` as deterministic guardrails around LLM-drafted handbook chapters |
## 3. Core Capabilities
- Single-source multi-edition TOC & Amazon KDP 6x9 trim/bleed/gutter engine (`build/toc.py`).
- Directive-aware Markdown + `source:` provenance parser (`build/md.py`).
- Mechanical number, contact, and verbatim-quote provenance verifier (`build/fact_gate.py`).
- Deprecated-claim firewall (`build/conflict_gate.py`) and source-nuance completeness gate (`build/coverage_gate.py`).
- Finished-PDF PyMuPDF box-breakout & ink-collision gate (`build/overlap_gate.py`, `build/pdf_gate.py`) and EPUB3 dark-mode/accessibility auditor (`build/audit_epub.py`).
## 4. Configurable Inputs
Adopters configure the system for their own organization without editing core application logic:
| Variable | Default / Example | Purpose |
|---|---|---|
| `PLAYBOOK_TOC_CSV` | `./content/reference/toc.csv` | Path to the master CSV defining chapters, role tracks, and numbered sub-topics |
| `EDITION_TARGET` | `full` | Edition key (`hub`, `field`, or `full`) to build or audit |
| `KDP_TRIM_SIZE` | `6.0x9.0` | Trim width x height in inches for Amazon KDP print geometry |
| `KDP_DPI_MIN` | `300` | Minimum embedded image resolution enforced during print preflight |
| `FOOTER_BAND_PT` | `34.0` | Footer band height in points reserved at the bottom of every PDF page |
| `PLAYBOOK_FOOTER_WORDS` | `ISO,CERTIFIED,OPERATIONS,PLAYBOOK` | Comma-separated wordmark tokens permitted inside the reserved PDF footer band |
## 5. Phasing and Stability Exit Criteria
1. **Phase 1 (Local Synthetic Run):** Clone the repository, copy `.env.example` to `.env`, and run the quickstart commands against synthetic seed data. Exit criterion: smoke checks pass with zero external credentials.
2. **Phase 2 (Read-Only Shadow Wiring):** Connect read-only credentials or webhook listeners in shadow/dry-run mode. Exit criterion: 100 consecutive events or queries reconcile cleanly against source records.
3. **Phase 3 (Production Cutover):** Enable live writes, alerts, or routing behind bounded retry and idempotency guards.
## 6. Non-Goals
- Shipping organization-specific business rules hardcoded in application source.
- Storing credentials, personal customer records, or tenant URLs inside version control.
- Replacing deterministic validation or arithmetic with unconstrained model prompts.
---
## File: `docs/PR-FAQ.md` — Working-Backwards PR-FAQ (docs/PR-FAQ.md)
# Working-Backwards PR-FAQ — Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine
**Release Summary:** `ops-playbook-public` gives engineering and operations teams a self-hosted, open-source implementation of Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine that configures via `.env` and runs on standard infrastructure in minutes.
## Press Release
Operations and engineering teams often rebuild the same internal workflows behind closed doors or pay per-seat SaaS markups for rigid tools that cannot match their field reality. `ops-playbook-public` open-sources a battle-tested implementation of Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine, stripped of all single-company assumptions and packaged with clear adapter boundaries, synthetic demo data, and machine-readable agent documentation.
Any team can fork `ops-playbook-public`, supply their own `.env` inputs and taxonomy config, and deploy locally or in production with Docker, Python, or Node. AI coding assistants such as Claude Code, Codex, and Cursor can read `AI-README.md` and `llms.txt` to wire custom ERP, CRM, or warehouse adapters in a single session.
## External Adopter FAQ
**Q1: How long does it take to run locally after cloning?**
Under five minutes. Copy `.env.example` to `.env` and run the quickstart commands in `README.md`. Synthetic fixtures let you inspect the workflow before connecting live credentials.
**Q2: Do I need to rewrite source files to use my own company name, channels, or rules?**
No. Organization names, endpoints, thresholds, and credentials sit in `.env` and declarative config files. External system specifics live behind narrow adapter modules documented in `docs/LLD.md`.
**Q3: What license governs this repository?**
MIT License. You can fork, modify, self-host, and use it commercially without restriction.
## Internal Engineering & Security FAQ
**Q4: How do we prevent tenant or employer data from ever entering a public fork?**
The repository starts from a clean git history, excludes raw exports and binary dumps, validates every commit through `gitleaks`, and ships only synthetic fixtures.
**Q5: What happens when an upstream API or model provider is slow or unavailable?**
Inbound webhooks persist raw payloads before processing, outbound writes carry idempotency keys with bounded exponential backoff, and model-backed paths fail open to deterministic rules or explicit human queues.
---
## File: `docs/HLD.md` — High-Level Design (docs/HLD.md)
# High-Level Design (HLD) — Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine
A docs-as-code operations manual compiler and mechanical preflight suite that enforces word-for-word source number provenance, blocks deprecated SOP claims, slices role-specific editions from one TOC, and inspects finished PDFs and EPUBs for ink collisions, bleed errors, and dark-mode contrast defects.
## 1. System Topology
```mermaid
flowchart LR
SOP["Canonical SOPs (content/sources/)"] --> Ch["Chapters (chNN.md + source: lines)"]
TOC["toc.csv (Tracks & Editions)"] --> Ch
Ch --> Fact["fact_gate + conflict_gate + coverage_gate"]
Fact --> Build["PDF / EPUB3 Renderer"]
Build --> ArtifactGates["overlap_gate + pdf_gate + audit_epub"]
```
## 2. Architectural Decisions and Rejected Alternatives
| Decision | Why It Holds | Rejected Alternative |
|---|---|---|
| Gate the finished PDF/EPUB, not just Markdown | CSS clipping, font ascender collisions, and dark-mode ink bugs only exist in the rendered artifact. | Trusting HTML/Markdown linters alone |
| Every gate ships a `--selftest` broken fixture | A gate that has never been seen to fail silently rots when layouts change. | Unit-testing only the happy path |
| Derive editions from one `toc.csv` | Shared safety chapters stay identical across `hub`, `field`, and `full` editions with zero copy-paste. | Maintaining separate branches per role handbook |
## 3. Data Flow and Failure Boundaries
1. **Configuration Boundary:** Startup validates `.env` variables and declarative config schemas before accepting traffic or running scheduled jobs.
2. **Adapter Boundary:** External services (databases, chat channels, HRMS, warehouses, or LLM providers) sit behind explicit adapter modules so failures stay isolated and testable with local mocks.
3. **Observability and Audit:** State transitions and job executions emit structured logs and deterministic status records rather than mutating state silently.
## 4. Scaling Notes
- **1x to 10x load:** Single-node Docker Compose or process supervisor handles standard team workloads with indexed database queries and bounded worker concurrency.
- **First bottleneck at 10x+:** High-frequency webhook or batch ingestion queues; mitigate by separating the stateless HTTP receiver from background worker processes sharing Redis or PostgreSQL locks.
---
## File: `docs/LLD.md` — Low-Level Design & Runbook (docs/LLD.md)
# Low-Level Design (LLD) & Operations Runbook — Ops Playbook Compiler — Source-Verified Print, KDP & EPUB3 Preflight Engine
This document defines the module responsibilities, environment contract, and operational procedures for `ops-playbook-public`.
## 1. Module and File Inventory
| Path | Responsibility |
|---|---|
| `build/toc.py` | Single-source chapter/track/edition parser and KDP 6x9 trim/bleed/gutter calculator |
| `build/md.py` | Markdown block, `::: directive`, and heading `source:` parser |
| `build/fact_gate.py` | Provenance verifier checking cited paths, locators, digits, and quotes |
| `build/conflict_gate.py` | Banned-claim table scanner against `docs/source-conflicts.md` |
| `build/coverage_gate.py` | Source-to-chapter completeness audit gate against `docs/coverage.tsv` |
| `build/overlap_gate.py` | PyMuPDF (`fitz`) R1–R4 box-breakout, ink-overlap, off-page, and footer-clipping gate |
| `build/audit_epub.py` | EPUB3 dark-mode luminance, curly-quote, accessibility metadata, and spine auditor |
## 2. Environment Variable Contract
| Variable | Default / Example | Required | Description |
|---|---|---|---|
| `PLAYBOOK_TOC_CSV` | `./content/reference/toc.csv` | Yes | Path to the master CSV defining chapters, role tracks, and numbered sub-topics |
| `EDITION_TARGET` | `full` | Yes | Edition key (`hub`, `field`, or `full`) to build or audit |
| `KDP_TRIM_SIZE` | `6.0x9.0` | No | Trim width x height in inches for Amazon KDP print geometry |
| `KDP_DPI_MIN` | `300` | No | Minimum embedded image resolution enforced during print preflight |
| `FOOTER_BAND_PT` | `34.0` | No | Footer band height in points reserved at the bottom of every PDF page |
| `PLAYBOOK_FOOTER_WORDS` | `ISO,CERTIFIED,OPERATIONS,PLAYBOOK` | No | Comma-separated wordmark tokens permitted inside the reserved PDF footer band |
## 3. Extension Recipe
1. Edit `content/reference/toc.csv` and `PARTS` in `build/toc.py` to define your organization's role tracks and editions.
2. Place canonical SOP markdown files in `content/sources/` and author chapters in `content/book/chNN.md` with `source:` lines under each heading.
3. Wire `python3 build/fact_gate.py`, `conflict_gate.py`, and `overlap_gate.py` into CI so no unverified claim or layout collision can merge.
## 4. Operations Runbook
### 1. Verify starter playbook end-to-end
```bash
python3 bin/playbook-demo.py
```
### 2. Run all broken-fixture gate self-tests
```bash
pytest -q tests/
```
### 3. Print parsed multi-track TOC map
```bash
python3 build/toc.py
```
---
## File: `docs/RESEARCH-2026.md` — 2026 Research & Landscape Notes (docs/RESEARCH-2026.md)
# 2026 Research & Landscape — Operations Playbook & Print/EPUB Preflight Compilers
## 1. The Gap in Docs-as-Code Toolchains (2026)
Tools such as **MdBook**, **Quarto**, **Typst**, **WeasyPrint**, and **Pandoc** turn Markdown into HTML, PDF, or EPUB, but assume two things that fail in regulated field operations manuals:
1. **Unverified Numbers & Stale Policy Drift:** When an LLM or technical writer drafts a 120-page handbook from 40 scattered SOP docs, a single wrong temperature (`24 hours` instead of `6 hours at 8C`) or misquoted policy causes real-world compliance failures.
2. **Silent Print/EPUB Rendering Defects:** DOM linters cannot see a CSS callout box that clips into a running footer on page 71 of a headless-Chrome/Typst PDF, or hardcoded `#1A1917` text that turns invisible in Apple Books / Kindle dark mode.
## 2. How `ops-playbook-public` Solves Both
- **Source-Provenance Grammar (`build/md.py` & `build/fact_gate.py`):** Every `##` / `###` section declares `source: path/to/sop.md "exact locator"`. `fact_gate.py` verifies the file exists, the locator phrase exists, and every number in the section appears in its cited source.
- **Banned-Claim Register (`build/conflict_gate.py`):** Blocks deprecated rules recorded in `docs/source-conflicts.md` from ever reappearing in prose while ignoring reviewer HTML comments.
- **Finished-Artifact Geometry & Theme Gates (`overlap_gate.py`, `pdf_gate.py`, `audit_epub.py`):** Inspects the rendered PDF via PyMuPDF (`fitz`) word-box and vector extraction for ink collisions and box breakouts, and audits EPUB3 packages for WCAG/schema accessibility metadata and dark-theme luminance safety.