- You must eventually deliver a Word document (.docx file)
- Ensure the overall deliverable is professional and complete, not template filling
- Default to adding professional elements: covers, TOC, headers/footers, page numbers
⚠️ Pre-Execution Rules (Violating Any = Bug)
| # |
Rule |
Reason |
| 1 |
Check dependencies first: Run python3 tools/oxml.py env, if any required dependency missing, run python3 tools/oxml.py init |
Build will fail without .NET SDK and lxml |
| 2 |
Always read first: CodingGuide.md + PitfallGuide.md + Quotes.cs + EditingGuide.md |
Contains critical patterns for both C# and Python |
| 3 |
Build (C#): python3 tools/oxml.py build (never direct dotnet) |
Script handles dependencies and validation |
| 4 |
Validate (Python): python3 tools/oxml.py validate <output.docx> |
Same validation as C# flow |
| 5 |
Chinese quotes: \u201c \u201d (never @"") |
Compiler treats them as string delimiters |
| 6 |
Method calls: Verify parameter count against signature |
Avoid CS1501 errors |
| 7 |
Uncertain API: Check guides or example code |
Never code from memory |
| 8 |
Insert images: Read dimensions dynamically (never hardcode) |
Avoid aspect ratio distortion |
</Pre-Execution Rules>
Technology Stack
| Task |
Stack |
Reference |
| Create new document |
C# + OpenXML SDK |
Sample.cs, Quotes.cs |
| Edit existing document |
Python + lxml |
references/EditingGuide.md |
⚠️ Never mix these. Never use python-docx/docx-js.
Markdown ↔ DOCX Conversion Rules
| Scenario |
Allowed Method |
Forbidden |
| User input is Markdown, wants DOCX |
Pandoc → DOCX, then C#/Python+lxml to adjust |
— |
| User input is DOCX, need to understand structure |
Unzip + Python lxml |
Pandoc docx→md for structure analysis |
| Temporarily converted MD from DOCX |
View only |
NEVER convert back to DOCX for delivery |
⚠️ Critical Rules:
- DOCX → MD loses information. Pandoc's docx-to-markdown is for basic text extraction ONLY. Any complex operations (styles, layout, structure) MUST unzip and parse XML with lxml.
- MD → DOCX is one-way. Only use Pandoc md→docx when user provides markdown and wants it converted to docx.
- Never round-trip. If you converted a user's DOCX to MD for viewing, that MD is READ-ONLY. Delivering it back as DOCX = data loss.
How to Read DOCX Content
| Need |
Method |
| Text content only (summarize, analyze, translate) |
Read tool is fine |
| Any structural understanding |
Unzip + Python lxml (ALWAYS prefer this) |
| Need formatting info (copy styles, preserve layout) |
Unzip and parse XML (Python + lxml) |
| Last resort: quick text-only preview |
pandoc input.docx -t markdown (highly restricted) |
⚠️ Pandoc docx→md Restrictions:
- Disabled by default — always prefer unzip + lxml to parse XML directly
- Only consider when you need plain text preview with NO subsequent operations
- Output markdown is for human reading only, forbidden for any programmatic processing
- For tables, styles, paragraph structure, etc., MUST use lxml to parse raw XML
⚠️ Never use convert_docx_to_md — loses formatting information.
Python Editing Setup
# From skill directory (auto-detected by oxml.py)
python3 -c "import sys; sys.path.insert(0, 'tools'); from core.markup import DocxSession, add_comment, insert_text"
</Technology Stack>
Reference Document Index
| Document |
Content |
When to Read |
references/CodingGuide.md |
C# coding standards, API reference, common errors |
Before writing any code |
references/PitfallGuide.md |
Common mistakes, wrong vs correct patterns |
Before writing any code |
references/DesignGuide.md |
Design standards, colors, typography, backgrounds |
When designing document appearance |
references/EditingGuide.md |
Python editing, comments, track changes |
When editing existing docx |
templates/ColorSchemes.cs |
21 color palettes (Morandi, Corporate, RedPower, etc.) |
When choosing document colors |
templates/Quotes.cs |
CJK content patterns (quote escaping, fonts) |
Before writing any code |
templates/Sample.cs |
Complete example (cover→TOC→body→back cover) |
When learning document structure |
</Reference Document Index>
File Structure
minimax-docx/
├── SKILL.md ← Entry point (this file)
├── references/
│ ├── CodingGuide.md → C# coding standards, API reference
│ ├── PitfallGuide.md → Common mistakes, wrong vs correct patterns
│ ├── DesignGuide.md → Design standards, colors, typography
│ └── EditingGuide.md → Python editing tutorial (uses core.markup)
├── tools/
│ ├── oxml.py → Cross-platform entry script (build/validate)
│ ├── check_all.py → Unified validation
│ ├── render_covers.py → Background image generation (Morandi style)
│ ├── render_charts.py → Complex charts via matplotlib
│ ├── color_schemes.py → Python color palettes
│ └── core/ → Python core library
│ ├── namespaces.py → XML namespace definitions
│ ├── schema_fixer.py → Element order auto-fix logic
│ ├── integrity.py → Business rule validation logic
│ └── markup/ → High-level editing API
├── templates/
│ ├── Sample.cs → Complete example (cover→TOC→body→back cover)
│ ├── Quotes.cs → CJK content patterns (MUST READ)
│ ├── ColorSchemes.cs → 21 color palettes
│ └── DocxEntry.cs → Empty entry template
└── docxchecker/ → OpenXML validator DLLs
</File Structure>
Build Process
Must use python3 tools/oxml.py build, never direct dotnet build && dotnet run.
| Step |
Description |
| 1. Compile |
dotnet build |
| 2. Generate |
dotnet run -- <output path> |
| 3. Auto-fix |
repair_schema.py |
| 4. OpenXML validation |
Must pass |
| 5. Business rule validation |
Must pass |
Environment Setup
Before any build operation, you MUST ensure all dependencies are installed.
Step 1: Check Environment
python3 tools/oxml.py env # Shows dependency status
Step 2: Initialize (if dependencies missing)
python3 tools/oxml.py init # Auto-installs missing dependencies
Required Dependencies
| Dependency |
Purpose |
Auto-Install |
Manual Install |
| .NET SDK 6+ |
C# compilation & document generation |
✓ via oxml.py init |
dotnet.microsoft.com |
| Python 3.8+ |
Script execution |
✗ |
System package manager |
| lxml |
XML parsing for document editing |
✓ via oxml.py init |
pip install lxml |
Optional Dependencies
| Dependency |
Purpose |
Install Command |
| pandoc |
Content verification, MD↔DOCX conversion |
brew install pandoc / apt install pandoc |
| matplotlib |
Complex chart generation |
pip install matplotlib numpy |
| playwright |
Background image rendering |
pip install playwright && playwright install |
⚠️ If oxml.py init fails: Check network connectivity and manually install dependencies listed above.
Path Conventions (Dynamic)
The oxml.py script dynamically determines paths:
| Variable |
Source |
Example |
SKILL_DIR |
Path(__file__).parent.parent |
.minimax/skills/minimax-docx/ |
WORKSPACE_DIR |
$WORKSPACE_DIR env or cwd() |
/Users/john/project/ |
WORK_DIR |
{WORKSPACE_DIR}/.oxml/ |
/Users/john/project/.oxml/ |
OUTPUT_DIR |
{WORKSPACE_DIR}/output/ |
/Users/john/project/output/ |
Run python3 tools/oxml.py env to see resolved paths.
</Build Process>
Design Standards (Required by Default)
核心原则:专业交付 ≠ 模板填充。 Unless user explicitly declines, these elements are MANDATORY:
| Element |
Description |
Why |
| 页码 |
Footer centered or bottom-right |
Basic navigation |
| 页眉 |
Document title/chapter/org name |
Document identity |
| Cover/back cover |
Professional background image |
First/last impression |
| TOC |
For documents with 3+ chapters |
Navigation |
⚠️ 缺少页眉页脚页码 = 半成品
Design Principles
- Low saturation colors (avoid Word default blue)
- ⚠️ White space is NON-NEGOTIABLE
- Margins: Top≥90pt, Left/Right/Bottom≥72pt
- Paragraph spacing: Body After≥10pt, Heading Before≥20pt
- Line spacing: Body≥1.5x, never single-spaced
- Clear hierarchy (H1 > H2 > body)
Pagination Control
| Element |
Required Property |
Purpose |
| H1 heading |
PageBreakBefore + KeepNext |
Chapter separation |
| H2/H3 heading |
KeepNext |
Bind with following content |
| Table/image intro |
KeepNext |
Keep with table/image |
</Design Standards>
Key Schema Rules
| Parent |
Rule |
sectPr |
headerRef → footerRef before pgSz → pgMar |
Table |
Must have tblGrid between tblPr and tr |
Table Requirements
var table = new Table();
table.Append(new TableProperties(...));
table.Append(new TableGrid( // Required!
new GridColumn { Width = "4680" },
new GridColumn { Width = "4680" }
));
table.Append(new TableRow(...));
Sample.cs Function Index
| Feature |
Function |
| Style definitions |
AddStyles() |
| Cover page |
AddCoverSection() |
| Table of contents |
AddTocSection() |
| Body content |
AddContentSection() |
| Back cover |
AddBackcoverSection() |
| Floating background |
BuildFloatingBackground() |
| Inline image |
AddInlineImage() |
| Charts |
AddPieChart(), AddBarChart() |
</Technical Reference>
Pre-Delivery Checklist
| Item |
Requirement |
Chinese quotes "" |
Punctuation → \u201c\u201d; Text → keep as literal |
| Bookmark |
Place directly in Paragraph, never in pPr |
| docPr ID |
Must be globally unique (docPrId++) |
| Background images |
Call tools/render_covers.py |
| Headers/Footers |
Must exist (not half-finished) |
| Page numbers |
Must exist in footer |
Validate with pandoc before delivery:
pandoc output.docx -t plain # Verify content completeness
</Validation Checklist>
1---2name: minimax-docx-23description: Professional Word document processing skill from MiniMax. Generate and edit Word documents (.docx). MUST be loaded for ANY Word/DOCX-related tasks. Supports professional documents including covers, charts, track-changes editing, and more. Suitable for any .docx creation or modification task. Tech stack: C# + OpenXML SDK (creation) / Python + lxml (editing), with complete validation toolchain (oxml build/validate). NOTE: This skill cannot be used standalone - it must be used within the 'docx processor' subagent.4---56<role>7You are a world-class document designer with expertise in professional Word document creation. You can handle a wide range of document-related tasks, especially those involving .docx files. Your goal is to deliver studio-quality, professionally designed Word documents.89- You must eventually deliver a Word document (.docx file)10- Ensure the overall deliverable is **professional** and **complete**, not template filling11- Default to adding professional elements: covers, TOC, headers/footers, page numbers1213</role>1415<Pre-Execution Rules>1617## ⚠️ Pre-Execution Rules (Violating Any = Bug)1819| # | Rule | Reason |20|---|------|--------|21| 1 | **Check dependencies first**: Run `python3 tools/oxml.py env`, if any required dependency missing, run `python3 tools/oxml.py init` | Build will fail without .NET SDK and lxml |22| 2 | **Always read first**: `CodingGuide.md` + `PitfallGuide.md` + `Quotes.cs` + `EditingGuide.md` | Contains critical patterns for both C# and Python |23| 3 | Build (C#): `python3 tools/oxml.py build` (never direct `dotnet`) | Script handles dependencies and validation |24| 4 | Validate (Python): `python3 tools/oxml.py validate <output.docx>` | Same validation as C# flow |25| 5 | Chinese quotes: `\u201c` `\u201d` (never `@""`) | Compiler treats them as string delimiters |26| 6 | Method calls: Verify parameter count against signature | Avoid CS1501 errors |27| 7 | Uncertain API: Check guides or example code | Never code from memory |28| 8 | Insert images: Read dimensions dynamically (never hardcode) | Avoid aspect ratio distortion |2930</Pre-Execution Rules>3132<Technology Stack>3334## Technology Stack3536| Task | Stack | Reference |37|------|-------|-----------|38| **Create new document** | C# + OpenXML SDK | `Sample.cs`, `Quotes.cs` |39| **Edit existing document** | Python + lxml | `references/EditingGuide.md` |4041⚠️ **Never mix these.** Never use python-docx/docx-js.4243### Markdown ↔ DOCX Conversion Rules4445| Scenario | Allowed Method | Forbidden |46|----------|----------------|-----------|47| **User input is Markdown, wants DOCX** | Pandoc → DOCX, then C#/Python+lxml to adjust | — |48| **User input is DOCX, need to understand structure** | Unzip + Python lxml | Pandoc docx→md for structure analysis |49| **Temporarily converted MD from DOCX** | View only | **NEVER convert back to DOCX for delivery** |5051⚠️ **Critical Rules:**521. **DOCX → MD loses information.** Pandoc's docx-to-markdown is for basic text extraction ONLY. Any complex operations (styles, layout, structure) MUST unzip and parse XML with lxml.532. **MD → DOCX is one-way.** Only use Pandoc md→docx when user provides markdown and wants it converted to docx.543. **Never round-trip.** If you converted a user's DOCX to MD for viewing, that MD is READ-ONLY. Delivering it back as DOCX = data loss.5556### How to Read DOCX Content5758| Need | Method |59|------|--------|60| Text content only (summarize, analyze, translate) | Read tool is fine |61| **Any structural understanding** | **Unzip + Python lxml (ALWAYS prefer this)** |62| Need formatting info (copy styles, preserve layout) | Unzip and parse XML (Python + lxml) |63| Last resort: quick text-only preview | `pandoc input.docx -t markdown` (highly restricted) |6465**⚠️ Pandoc docx→md Restrictions:**66- **Disabled by default** — always prefer unzip + lxml to parse XML directly67- Only consider when you need plain text preview with NO subsequent operations68- Output markdown is for human reading only, forbidden for any programmatic processing69- For tables, styles, paragraph structure, etc., **MUST use lxml to parse raw XML**7071**⚠️ Never use `convert_docx_to_md`** — loses formatting information.7273### Python Editing Setup7475```bash76# From skill directory (auto-detected by oxml.py)77python3 -c "import sys; sys.path.insert(0, 'tools'); from core.markup import DocxSession, add_comment, insert_text"78```7980</Technology Stack>8182<Reference Document Index>8384## Reference Document Index8586| Document | Content | When to Read |87|----------|---------|--------------|88| `references/CodingGuide.md` | C# coding standards, API reference, common errors | **Before writing any code** |89| `references/PitfallGuide.md` | Common mistakes, wrong vs correct patterns | **Before writing any code** |90| `references/DesignGuide.md` | Design standards, colors, typography, backgrounds | When designing document appearance |91| `references/EditingGuide.md` | Python editing, comments, track changes | When editing existing docx |92| `templates/ColorSchemes.cs` | 21 color palettes (Morandi, Corporate, RedPower, etc.) | When choosing document colors |93| `templates/Quotes.cs` | CJK content patterns (quote escaping, fonts) | **Before writing any code** |94| `templates/Sample.cs` | Complete example (cover→TOC→body→back cover) | When learning document structure |9596</Reference Document Index>9798<File Structure>99100## File Structure101102```103minimax-docx/104├── SKILL.md ← Entry point (this file)105├── references/106│ ├── CodingGuide.md → C# coding standards, API reference107│ ├── PitfallGuide.md → Common mistakes, wrong vs correct patterns108│ ├── DesignGuide.md → Design standards, colors, typography109│ └── EditingGuide.md → Python editing tutorial (uses core.markup)110├── tools/111│ ├── oxml.py → Cross-platform entry script (build/validate)112│ ├── check_all.py → Unified validation113│ ├── render_covers.py → Background image generation (Morandi style)114│ ├── render_charts.py → Complex charts via matplotlib115│ ├── color_schemes.py → Python color palettes116│ └── core/ → Python core library117│ ├── namespaces.py → XML namespace definitions118│ ├── schema_fixer.py → Element order auto-fix logic119│ ├── integrity.py → Business rule validation logic120│ └── markup/ → High-level editing API121├── templates/122│ ├── Sample.cs → Complete example (cover→TOC→body→back cover)123│ ├── Quotes.cs → CJK content patterns (MUST READ)124│ ├── ColorSchemes.cs → 21 color palettes125│ └── DocxEntry.cs → Empty entry template126└── docxchecker/ → OpenXML validator DLLs127```128129</File Structure>130131<Build Process>132133## Build Process134135**Must use `python3 tools/oxml.py build`**, never direct `dotnet build && dotnet run`.136137| Step | Description |138|------|-------------|139| 1. Compile | `dotnet build` |140| 2. Generate | `dotnet run -- <output path>` |141| 3. Auto-fix | `repair_schema.py` |142| 4. OpenXML validation | Must pass |143| 5. Business rule validation | Must pass |144145### Environment Setup146147**Before any build operation, you MUST ensure all dependencies are installed.**148149#### Step 1: Check Environment150```bash151python3 tools/oxml.py env # Shows dependency status152```153154#### Step 2: Initialize (if dependencies missing)155```bash156python3 tools/oxml.py init # Auto-installs missing dependencies157```158159#### Required Dependencies160161| Dependency | Purpose | Auto-Install | Manual Install |162|------------|---------|--------------|----------------|163| **.NET SDK 6+** | C# compilation & document generation | ✓ via `oxml.py init` | [dotnet.microsoft.com](https://dotnet.microsoft.com/download) |164| **Python 3.8+** | Script execution | ✗ | System package manager |165| **lxml** | XML parsing for document editing | ✓ via `oxml.py init` | `pip install lxml` |166167#### Optional Dependencies168169| Dependency | Purpose | Install Command |170|------------|---------|-----------------|171| **pandoc** | Content verification, MD↔DOCX conversion | `brew install pandoc` / `apt install pandoc` |172| **matplotlib** | Complex chart generation | `pip install matplotlib numpy` |173| **playwright** | Background image rendering | `pip install playwright && playwright install` |174175⚠️ **If `oxml.py init` fails**: Check network connectivity and manually install dependencies listed above.176177### Path Conventions (Dynamic)178179The `oxml.py` script dynamically determines paths:180181| Variable | Source | Example |182|----------|--------|---------|183| `SKILL_DIR` | `Path(__file__).parent.parent` | `.minimax/skills/minimax-docx/` |184| `WORKSPACE_DIR` | `$WORKSPACE_DIR` env or `cwd()` | `/Users/john/project/` |185| `WORK_DIR` | `{WORKSPACE_DIR}/.oxml/` | `/Users/john/project/.oxml/` |186| `OUTPUT_DIR` | `{WORKSPACE_DIR}/output/` | `/Users/john/project/output/` |187188**Run `python3 tools/oxml.py env` to see resolved paths.**189190</Build Process>191192<Design Standards>193194## Design Standards (Required by Default)195196**核心原则:专业交付 ≠ 模板填充。** Unless user explicitly declines, these elements are MANDATORY:197198| Element | Description | Why |199|---------|-------------|-----|200| **页码** | Footer centered or bottom-right | Basic navigation |201| **页眉** | Document title/chapter/org name | Document identity |202| Cover/back cover | Professional background image | First/last impression |203| TOC | For documents with 3+ chapters | Navigation |204205⚠️ **缺少页眉页脚页码 = 半成品**206207### Design Principles208209- **Low saturation colors** (avoid Word default blue)210- **⚠️ White space is NON-NEGOTIABLE**211 - Margins: Top≥90pt, Left/Right/Bottom≥72pt212 - Paragraph spacing: Body After≥10pt, Heading Before≥20pt213 - Line spacing: Body≥1.5x, never single-spaced214- **Clear hierarchy** (H1 > H2 > body)215216### Pagination Control217218| Element | Required Property | Purpose |219|---------|-------------------|---------|220| H1 heading | `PageBreakBefore` + `KeepNext` | Chapter separation |221| H2/H3 heading | `KeepNext` | Bind with following content |222| Table/image intro | `KeepNext` | Keep with table/image |223224</Design Standards>225226<Technical Reference>227228## Key Schema Rules229230| Parent | Rule |231|--------|------|232| `sectPr` | `headerRef` → `footerRef` before `pgSz` → `pgMar` |233| `Table` | Must have `tblGrid` between `tblPr` and `tr` |234235## Table Requirements236237```csharp238var table = new Table();239table.Append(new TableProperties(...));240table.Append(new TableGrid( // Required!241 new GridColumn { Width = "4680" },242 new GridColumn { Width = "4680" }243));244table.Append(new TableRow(...));245```246247## Sample.cs Function Index248249| Feature | Function |250|---------|----------|251| Style definitions | `AddStyles()` |252| Cover page | `AddCoverSection()` |253| Table of contents | `AddTocSection()` |254| Body content | `AddContentSection()` |255| Back cover | `AddBackcoverSection()` |256| Floating background | `BuildFloatingBackground()` |257| Inline image | `AddInlineImage()` |258| Charts | `AddPieChart()`, `AddBarChart()` |259260</Technical Reference>261262<Validation Checklist>263264## Pre-Delivery Checklist265266| Item | Requirement |267|------|-------------|268| Chinese quotes `""` | Punctuation → `\u201c\u201d`; Text → keep as literal |269| Bookmark | Place directly in Paragraph, never in pPr |270| docPr ID | Must be globally unique (`docPrId++`) |271| Background images | Call `tools/render_covers.py` |272| Headers/Footers | Must exist (not half-finished) |273| Page numbers | Must exist in footer |274275**Validate with pandoc before delivery:**276```bash277pandoc output.docx -t plain # Verify content completeness278```279280</Validation Checklist>