builder-api.md
Language Markdown6.9 KB163 lines
# build_sop.py: API referenceThe helper script `scripts/build_sop.py` takes a Python dict and produces a styled Meridian SOP .docx. Use it as the default path; only drop down to raw python-docx when the content needs layout the builder doesn't cover.## Top-level dict```python{"title": "Mockup File Naming Convention", # required, str"owner": "Matt Guerra", # required, str: full name"initials": "MG", # required, str: 2 or 3 letters"category": "Operations", # required, str"effective_date": "04/2026", # required, str: MM/YYYY with slash"folder_context": "07 - Mockup Artwork Files", # optional, str: appears on line 2 of title bar"draft": False, # optional, bool: prepends DRAFT_"template": False, # optional, bool: inserts _TEMPLATE before date"output_path": "/path/to/output_dir", # optional, str: directory or full path"sections": [ ... ], # required, list[dict]: see below}```If `output_path` is a directory, the file is saved inside it using the canonical filename. If it's a full path with a different filename, the builder overrides with the canonical filename (`force_filename: False` to disable).## Section typesEach section in `sections` is a dict with a `type` and content fields.### Required content sections```python{"type": "purpose", "text": "This SOP defines ..."}# Renders Heading 1 "Purpose" + body paragraph{"type": "scope", "text": "This SOP applies to all team members who ..."}# Renders Heading 1 "Scope & Responsibility" + body paragraph```### Heading sections```python{"type": "h1", "text": "Folder Structure"}{"type": "h2", "text": "1.1 Folder Creation & Numbering"}{"type": "h3", "text": "Components"}```### Body content```python{"type": "body", "text": "All mockup design files must follow this format..."}# Arial 11pt black, normal paragraph{"type": "accent_subhead", "text": "Versioning"}# Arial Bold 12pt Meridian navy, for in-section topic labels{"type": "bullet", "text": "Start at v1 for every new job."}# Bulleted list item, Arial 11pt{"type": "numbered", "text": "Open the Shared Drive in your browser."}# Numbered list item, Arial 11pt{"type": "code", "text": "07 - Mockup Artwork Files\n├── [COMPANY-ID]_[COMPANY NAME]\n└── ..."}# Multi-line monospace blue code/path block{"type": "warning", "text": "Do not use 00 for functional folders; it's for SOPs & How-To's only."}# Bold red callout{"type": "blank"}# Inserts a blank paragraph for spacing```### Tables```python{"type": "format_spec", "text": "Mockup_v[#]_[MM/YYYY]_[Initials]"}# 1-cell light-blue table with the format pattern in monospace blue bold{"type": "components_table", "rows": [["Component", "Value", "Description"],["Mockup", "Always \"Mockup\"", "Fixed document type prefix."],["v[#]", "v1, v2, v3...", "Version number."],["[MM/YYYY]", "04/2026", "Month and year of creation."],["[Initials]", "MG, MI, RM, etc.", "Initials of the team member."],]}# 3-col table. First row is the header. Second column rendered in code style.{"type": "examples_table", "rows": [["Folder", "Sub DIR", "File Name(s)"],["NORTHWIND ACADEMY", "H4A", "Mockup_v1_04/2026_RG"],["NORTHWIND ACADEMY", "", "Mockup_v2_04/2026_RG"],]}# 3-col table. First row is the header. Last column rendered in code style.{"type": "note", "text": "Note: This naming convention applies to files inside the 07 - Mockup Artwork Files folder only."}# 1-cell light-yellow note box, italic gray text{"type": "quick_ref", "text": "Mockup Format:\nMockup_v[#]_[MM/YYYY]_[Initials]\nFirst version: Mockup_v1_04/2026_RG\nRevision: Mockup_v2_04/2026_RG\nApproved final: Mockup_v3_FINAL_04/2026_RG"}# 1-cell light-blue reference card, multi-line monospace blue```## Driver exampleA complete driver script the model would write to use the builder:```pythonimport syssys.path.insert(0, "/path/to/sop-author/scripts")from build_sop import build_sopspec = {"title": "Mockup Handoff","owner": "Matt Guerra","initials": "MG","category": "Operations","effective_date": "05/2026","folder_context": "02 - Operations Client Facing > Mockup Handoffs","output_path": "/path/to/output_dir","sections": [{"type": "purpose", "text": "This SOP defines the procedure for handing off approved client mockups from the Design team to Client Success."},{"type": "scope", "text": "Applies to all Display Consultants and CS Associates handling client mockup approvals."},{"type": "h1", "text": "Process"},{"type": "h2", "text": "1. Mockup Finalization (Design)"},{"type": "numbered", "text": "Move the approved mockup file to the client's order folder under 03 - Orders Artwork Files."},{"type": "numbered", "text": "Rename the file to include _FINAL before the date."},{"type": "numbered", "text": "Add a comment in the client's CRM record noting the file is ready."},{"type": "h2", "text": "2. Handoff Notification (Design → CS)"},{"type": "numbered", "text": "Post in #handoffs with the order number, client name, and the file path."},{"type": "numbered", "text": "Tag the CS Associate assigned to the order."},{"type": "h2", "text": "3. CS Confirmation"},{"type": "numbered", "text": "CS opens the file, spot-checks against the approval thread."},{"type": "numbered", "text": "If clean: send to the client via the standard delivery email."},{"type": "numbered", "text": "If issues: return to Design with specifics. Do not edit Design's file."},{"type": "h1", "text": "Best Practices"},{"type": "accent_subhead", "text": "Speed vs. Accuracy"},{"type": "bullet", "text": "Same-day handoff is the goal, but CS confirmation can take up to 24h on high-volume days."},{"type": "bullet", "text": "Never skip the CS spot-check. The CS Associate is the last set of eyes before the client."},{"type": "h1", "text": "Quick Reference Card"},{"type": "quick_ref", "text": "1. Design finalizes file → renames _FINAL → moves to order folder.\n2. Design posts in #handoffs, tags CS.\n3. CS spot-checks.\n4. CS sends to client (or returns to Design)."},],}out = build_sop(spec)print(f"Saved: {out}")```## Validating an existing SOP```bashpython3 scripts/build_sop.py --validate /path/to/some_sop.docx```Prints a PASS/FAIL/WARN for each check. Exits 0 if no FAILs.## Things the builder does NOT do- It does not infer SOP type from the content; you must pick the type and pass the right section list.- It does not edit an existing SOP in place; it always builds from scratch (using the template asset for style inheritance).- It does not check that the user's content is good. Garbage in → formatted garbage out.- It does not upload to Drive.