# AI Skill: House-Style Word Memos (Markdown Master → .docx) Use this skill whenever the user wants a memo, letter, or report delivered as a Word document in a consistent house style — or when they mention "Word", "memo", "export", or "finalise the document". ## Why this skill exists AI assistants produce unreliable .docx output when they improvise the XML: documents that preview fine but will not open, lose all styling, or trigger Word's repair dialog. The cause is almost never the prose — it is silently invalid OOXML. Three rules decide whether Word accepts a file: 1. **Namespace prefixes.** Every WordprocessingML element needs `w:` (or `r:`). A single bare `` makes Word refuse the entire file — even though the XML is technically well-formed. 2. **Schema element order.** Word enforces it strictly: - `w:pPr`: pStyle → keepNext → pBdr → spacing → ind → jc → outlineLvl - `w:rPr`: rFonts → b → i → color → sz → szCs → u - `w:tcPr`: tcW → shd → vAlign - `w:tblPr`: tblW → tblBorders → tblLayout → tblCellMar - `w:sectPr`: headerReference → footerReference → pgSz → pgMar 3. **No duplicates.** One element of each kind per container (a single `w:spacing` per paragraph, etc.). Never hand-edit OOXML without re-validating afterwards. ## Workflow 1. Draft the content in **Markdown** (the master). Never author content in the docx directly — the master is the single source of truth; the docx is a mere derivative. Keep frontmatter/meta blocks out of the export unless the user asks for them. 2. Before building, ask the user in **one** round of questions: - Recipients (To), sender (From), date, status, subject line (Re)? - Confidentiality header (privileged & confidential / confidential / none)? - Portrait or landscape (wide tables)? 3. Generate the docx with the memo builder script (`python3 memo_builder.py `): - Fill the `MEMO` dict (title, to, from, date, status, re, header). - Adapt the house-style constants if the user's style differs. - Only formatting, never content changes: the master is adopted 1:1; the only additions are the title and the To/From/Date/Status/Re box. - If the builder is unavailable, rebuild it following the three rules above, plus: (a) a `Normal` style with `w:default="1"`, (b) a styles relationship in `word/_rels/document.xml.rels`, (c) well-formed `.rels` parts (a validation that only checks `*.xml` skips the `.rels` files!). 4. **Validate before delivering.** The validation must be completely green: well-formedness of all parts including `.rels`, schema element order (monotonic), namespace prefixes, no duplicates, ZIP integrity. Well-formed alone is NOT sufficient. 5. Name the file `yyyymmdd_Subject.docx` (or the user's convention) and deliver it as a real .docx (never let a cloud drive convert it to a native doc format). Prefer delivery via a connected cloud folder over chat-attached downloads — file transfers through the chat layer can corrupt binary files; the cloud route has proven reliable. Briefly confirm that only formatting was applied and the content matches the master. ## House style defaults (all configurable in the builder) A4, Arial throughout; substantive document title 18 pt bold (never "MEMORANDUM" as title); section headings 18 pt; sub-headings 14 pt; body and tables 10 pt; To/From/Date/Status/Re box with bold labels (no colons), light-blue label column, grey borders, bold Re line; confidentiality marking in the page header with a thin separator line; centred "Page x | y" footer; hyperlinks in blue underline; table header rows shaded and repeated across pages. ## Editing an existing Word document (special case) Edit the uploaded file directly (do not rebuild from scratch): unpack with Python's `zipfile`, modify `word/document.xml` with `xml.etree.ElementTree`, preserving the namespace prefixes, and repack. Only touch formatting XML; never overwrite existing text. Any in-content change goes in as tracked changes (`w:ins`/`w:del` with author and ISO date). New parts (e.g. `comments.xml`) must be registered in `[Content_Types].xml` and in the document's relationships — otherwise Word reports the file as corrupted.