Office DOCX
Use the bundled scripts in this skill package to produce editable .docx
files. The builder writes deterministic OOXML with real Word numbering,
tables, images with alt text, comments, and tracked changes. The skill
activation metadata includes Skill directory; treat that as SKILL_DIR and
run scripts from SKILL_DIR/scripts/.
Workflow
- Decide the document archetype: brief, proposal, SOP, form, checklist,
report, memo, or reference guide.
- Create a JSON spec in the working directory. Use semantic blocks:
heading, paragraph, bullet_list, numbered_list, table, callout,
image, comment, revision, and page_break.
- For a new document, run:
python3 "$SKILL_DIR/scripts/check_env.py"
python3 "$SKILL_DIR/scripts/build_docx.py" --spec spec.json --out output.docx
python3 "$SKILL_DIR/scripts/inspect_docx.py" --verify output.docx
python3 "$SKILL_DIR/scripts/a11y_audit.py" output.docx
- To append to an existing document, use a spec containing only the new
blocks, then run:
python3 "$SKILL_DIR/scripts/append_docx.py" --input existing.docx --spec append.json --out output.docx
python3 "$SKILL_DIR/scripts/inspect_docx.py" --verify output.docx
- To convert a Markdown draft directly:
python3 "$SKILL_DIR/scripts/markdown_to_docx.py" --markdown draft.md --out output.docx
python3 "$SKILL_DIR/scripts/inspect_docx.py" --verify output.docx
- For Google Docs-targeted output, sanitize before render/import:
python3 "$SKILL_DIR/scripts/google_docs_title_sanitize.py" output.docx --out sanitized.docx
python3 "$SKILL_DIR/scripts/google_docs_title_sanitize.py" sanitized.docx --check
Use sanitized.docx for preview rendering and native Google Docs import.
- For redline/comment work, use
comment blocks or revision blocks:
{"type": "comment", "target": "This sentence needs support.", "comment": "Add source."}
{"type": "revision", "delete": "old wording", "insert": "new wording"}
- For delivery cleanup, use the focused helpers:
python3 "$SKILL_DIR/scripts/comments_strip.py" commented.docx --out no-comments.docx
python3 "$SKILL_DIR/scripts/comments_extract.py" commented.docx
python3 "$SKILL_DIR/scripts/add_tracked_replacements.py" --input input.docx --spec replacements.json --out redlined.docx
python3 "$SKILL_DIR/scripts/accept_tracked_changes.py" redlined.docx --mode accept --out accepted.docx
python3 "$SKILL_DIR/scripts/redact_docx.py" input.docx redacted.docx --emails --phones
python3 "$SKILL_DIR/scripts/privacy_scrub_metadata.py" input.docx --out scrubbed.docx
python3 "$SKILL_DIR/scripts/compare_docx.py" before.docx after.docx
- For advanced Word structure tasks, use the focused OOXML helpers:
python3 "$SKILL_DIR/scripts/insert_toc.py" input.docx --out with-toc.docx
python3 "$SKILL_DIR/scripts/fields_report.py" with-toc.docx
python3 "$SKILL_DIR/scripts/insert_note.py" input.docx --kind footnote --text "Source note" --out with-note.docx
python3 "$SKILL_DIR/scripts/watermark_add.py" input.docx --text "DRAFT" --out watermarked.docx
python3 "$SKILL_DIR/scripts/watermark_audit_remove.py" watermarked.docx
python3 "$SKILL_DIR/scripts/set_protection.py" input.docx --mode readOnly --out protected.docx
python3 "$SKILL_DIR/scripts/content_controls.py" input.docx --spec controls.json --out form.docx
python3 "$SKILL_DIR/scripts/internal_nav.py" input.docx --spec nav.json --out linked.docx
python3 "$SKILL_DIR/scripts/merge_docx_append.py" --input a.docx --input b.docx --out merged.docx
python3 "$SKILL_DIR/scripts/docx_table_to_csv.py" input.docx --out-dir tables
- If visual QA matters and LibreOffice is available, render previews:
python3 "$SKILL_DIR/scripts/render_preview.py" output.docx
- Deliver the
.docx path or attach it with send_attachment.
Spec Shape
{
"title": "Document title",
"subtitle": "Optional subtitle",
"blocks": [
{"type": "heading", "level": 1, "text": "Section"},
{"type": "paragraph", "text": "Body copy."},
{"type": "bullet_list", "items": ["Point one", {"text": "Point two", "comment": "Verify"}]},
{"type": "image", "path": "chart.png", "alt": "Revenue trend chart", "caption": "Figure 1. Revenue trend", "width_inches": 5.5, "height_inches": 3.2},
{"type": "revision", "delete": "Old sentence.", "insert": "Improved sentence."},
{"type": "table", "headers": ["Metric", "Value"], "rows": [["ARR", "$1.2M"]]}
]
}
Quality Bar
- Keep documents editable: use semantic headings, real Word lists, comments,
tracked changes, images with alt text, and real tables.
- Run
a11y_audit.py before delivery; fix hard issues such as fake bullets,
missing image alt text, empty documents, and structural defects.
- Do not overuse tables for normal prose.
- Avoid dense walls of text unless the document type demands it.
- For Google Docs-targeted output, keep the title simple and native-looking and
run
google_docs_title_sanitize.py --check.
- When editing existing DOCX packages, preserve package structure: append body
content before the final
w:sectPr, keep existing headers/relationships, and
let watermark helpers allocate a new header part instead of replacing one.
- If preview rendering fails because LibreOffice or a PDF-to-PNG renderer is
missing, state exactly which verification passed; do not imply visual QA
passed.
1---2name: office-docx3description: Use when the user asks to create, edit, inspect, polish, verify, or deliver Word `.docx` documents, Google Docs-targeted drafts, business briefs, forms, reports, tables, checklists, redraft-ready document sections, or PDF/Word source-to-DOCX transformations.4---5
6# Office DOCX
7
8Use the bundled scripts in this skill package to produce editable `.docx`
9files. The builder writes deterministic OOXML with real Word numbering,
10tables, images with alt text, comments, and tracked changes. The skill
11activation metadata includes `Skill directory`; treat that as `SKILL_DIR` and
12run scripts from `SKILL_DIR/scripts/`.
13
14## Workflow
15
161. Decide the document archetype: brief, proposal, SOP, form, checklist,
17 report, memo, or reference guide.
182. Create a JSON spec in the working directory. Use semantic blocks:
19 `heading`, `paragraph`, `bullet_list`, `numbered_list`, `table`, `callout`,
20 `image`, `comment`, `revision`, and `page_break`.
213. For a new document, run:
22
23```bash
24python3 "$SKILL_DIR/scripts/check_env.py"
25python3 "$SKILL_DIR/scripts/build_docx.py" --spec spec.json --out output.docx
26python3 "$SKILL_DIR/scripts/inspect_docx.py" --verify output.docx
27python3 "$SKILL_DIR/scripts/a11y_audit.py" output.docx
28```
29
304. To append to an existing document, use a spec containing only the new
31 `blocks`, then run:
32
33```bash
34python3 "$SKILL_DIR/scripts/append_docx.py" --input existing.docx --spec append.json --out output.docx
35python3 "$SKILL_DIR/scripts/inspect_docx.py" --verify output.docx
36```
37
385. To convert a Markdown draft directly:
39
40```bash
41python3 "$SKILL_DIR/scripts/markdown_to_docx.py" --markdown draft.md --out output.docx
42python3 "$SKILL_DIR/scripts/inspect_docx.py" --verify output.docx
43```
44
456. For Google Docs-targeted output, sanitize before render/import:
46
47```bash
48python3 "$SKILL_DIR/scripts/google_docs_title_sanitize.py" output.docx --out sanitized.docx
49python3 "$SKILL_DIR/scripts/google_docs_title_sanitize.py" sanitized.docx --check
50```
51
52Use `sanitized.docx` for preview rendering and native Google Docs import.
53
547. For redline/comment work, use `comment` blocks or `revision` blocks:
55
56```json
57{"type": "comment", "target": "This sentence needs support.", "comment": "Add source."}
58{"type": "revision", "delete": "old wording", "insert": "new wording"}
59```
60
618. For delivery cleanup, use the focused helpers:
62
63```bash
64python3 "$SKILL_DIR/scripts/comments_strip.py" commented.docx --out no-comments.docx
65python3 "$SKILL_DIR/scripts/comments_extract.py" commented.docx
66python3 "$SKILL_DIR/scripts/add_tracked_replacements.py" --input input.docx --spec replacements.json --out redlined.docx
67python3 "$SKILL_DIR/scripts/accept_tracked_changes.py" redlined.docx --mode accept --out accepted.docx
68python3 "$SKILL_DIR/scripts/redact_docx.py" input.docx redacted.docx --emails --phones
69python3 "$SKILL_DIR/scripts/privacy_scrub_metadata.py" input.docx --out scrubbed.docx
70python3 "$SKILL_DIR/scripts/compare_docx.py" before.docx after.docx
71```
72
739. For advanced Word structure tasks, use the focused OOXML helpers:
74
75```bash
76python3 "$SKILL_DIR/scripts/insert_toc.py" input.docx --out with-toc.docx
77python3 "$SKILL_DIR/scripts/fields_report.py" with-toc.docx
78python3 "$SKILL_DIR/scripts/insert_note.py" input.docx --kind footnote --text "Source note" --out with-note.docx
79python3 "$SKILL_DIR/scripts/watermark_add.py" input.docx --text "DRAFT" --out watermarked.docx
80python3 "$SKILL_DIR/scripts/watermark_audit_remove.py" watermarked.docx
81python3 "$SKILL_DIR/scripts/set_protection.py" input.docx --mode readOnly --out protected.docx
82python3 "$SKILL_DIR/scripts/content_controls.py" input.docx --spec controls.json --out form.docx
83python3 "$SKILL_DIR/scripts/internal_nav.py" input.docx --spec nav.json --out linked.docx
84python3 "$SKILL_DIR/scripts/merge_docx_append.py" --input a.docx --input b.docx --out merged.docx
85python3 "$SKILL_DIR/scripts/docx_table_to_csv.py" input.docx --out-dir tables
86```
87
8810. If visual QA matters and LibreOffice is available, render previews:
89
90```bash
91python3 "$SKILL_DIR/scripts/render_preview.py" output.docx
92```
93
9411. Deliver the `.docx` path or attach it with `send_attachment`.
95
96## Spec Shape
97
98```json
99{
100 "title": "Document title",
101 "subtitle": "Optional subtitle",
102 "blocks": [
103 {"type": "heading", "level": 1, "text": "Section"},
104 {"type": "paragraph", "text": "Body copy."},
105 {"type": "bullet_list", "items": ["Point one", {"text": "Point two", "comment": "Verify"}]},
106 {"type": "image", "path": "chart.png", "alt": "Revenue trend chart", "caption": "Figure 1. Revenue trend", "width_inches": 5.5, "height_inches": 3.2},
107 {"type": "revision", "delete": "Old sentence.", "insert": "Improved sentence."},
108 {"type": "table", "headers": ["Metric", "Value"], "rows": [["ARR", "$1.2M"]]}
109 ]
110}
111```
112
113## Quality Bar
114
115- Keep documents editable: use semantic headings, real Word lists, comments,
116 tracked changes, images with alt text, and real tables.
117- Run `a11y_audit.py` before delivery; fix hard issues such as fake bullets,
118 missing image alt text, empty documents, and structural defects.
119- Do not overuse tables for normal prose.
120- Avoid dense walls of text unless the document type demands it.
121- For Google Docs-targeted output, keep the title simple and native-looking and
122 run `google_docs_title_sanitize.py --check`.
123- When editing existing DOCX packages, preserve package structure: append body
124 content before the final `w:sectPr`, keep existing headers/relationships, and
125 let watermark helpers allocate a new header part instead of replacing one.
126- If preview rendering fails because LibreOffice or a PDF-to-PNG renderer is
127 missing, state exactly which verification passed; do not imply visual QA
128 passed.