$npx -y skills add thvroyal/kimi-skills --skill kimi-docxGenerate and edit Word documents (.docx). Supports professional documents including covers, charts, track-changes editing, and more. Suitable for any .docx creation or modification task.
| 1 | # Part 1: Goals |
| 2 | |
| 3 | ## ⚠️ When to Unzip vs Read |
| 4 | |
| 5 | **To preserve ANY formatting from the source document, MUST unzip and parse XML.** |
| 6 | |
| 7 | Read tool returns plain text only — fonts, colors, alignment, borders, styles are lost. |
| 8 | |
| 9 | | Need | Method | |
| 10 | |------|--------| |
| 11 | | Text content only (summarize, analyze, translate) | Read tool is fine | |
| 12 | | Formatting info (copy styles, preserve layout, template filling) | Unzip and parse XML | |
| 13 | | Structure + comments/track changes | `pandoc input.docx -t markdown` | |
| 14 | |
| 15 | ## Core Principles |
| 16 | |
| 17 | 1. **Preserve formatting** — When editing existing documents, retain original formatting. Clone and modify, never recreate. |
| 18 | |
| 19 | 2. **Correct feature implementation** — Comments need multi-file sync. Track Changes need revision marks. Use the right structure. |
| 20 | |
| 21 | **Never use python-docx/docx-js as fallback.** These libraries produce lower quality output than direct XML manipulation. |
| 22 | |
| 23 | ## Source Principle |
| 24 | |
| 25 | **Template provided = Act as form-filler, not designer.** |
| 26 | - Format is the user's decision |
| 27 | - Task: replace placeholders, not redesign |
| 28 | - Like filling a PDF form—do not redesign |
| 29 | |
| 30 | **No template = Act as designer.** Design freely based on scenario. |
| 31 | |
| 32 | For .doc (legacy format), first convert with `libreoffice --headless --convert-to docx`. |
| 33 | |
| 34 | --- |
| 35 | |
| 36 | # Part 2: Execution |
| 37 | |
| 38 | ## File Structure |
| 39 | |
| 40 | ``` |
| 41 | docx/ |
| 42 | ├── SKILL.md ← This file (entry point + reference) |
| 43 | ├── references/ |
| 44 | │ └── EditingGuide.md → Complete Python editing tutorial (comments, track changes, 5-file sync) |
| 45 | ├── scripts/ |
| 46 | │ ├── docx → Unified entry (the only script to call) |
| 47 | │ ├── fix_element_order.py → Auto-fix XML element ordering |
| 48 | │ ├── validate_docx.py → Business rule validation |
| 49 | │ ├── generate_backgrounds.py → Morandi style backgrounds |
| 50 | │ ├── generate_inkwash_backgrounds.py → Ink-wash style backgrounds |
| 51 | │ └── generate_chart.py → matplotlib (only for heatmaps/3D/radar; simple charts must use native) |
| 52 | ├── assets/ |
| 53 | │ └── templates/ |
| 54 | │ ├── KimiDocx.csproj → Project file template (for creating new docs) |
| 55 | │ ├── Program.cs → Program entry template |
| 56 | │ ├── Example.cs → Complete example (cover+TOC+charts+back cover) |
| 57 | │ ├── CJKExample.cs → CJK content patterns (quote escaping, fonts) |
| 58 | │ └── xml/ → XML templates for comments infrastructure |
| 59 | └── validator/ → OpenXML validator (pre-compiled binary, AI does not modify) |
| 60 | ``` |
| 61 | |
| 62 | **Creating new documents**: Use C# SDK with `./scripts/docx build` → See `Example.cs` for patterns, `CJKExample.cs` for CJK content |
| 63 | **Editing existing documents**: Use Python + lxml → See `references/EditingGuide.md` for complete tutorial |
| 64 | |
| 65 | ⚠️ **Do NOT mix these approaches.** C# SDK for creation, Python for editing. Never use python-docx/docx-js. |
| 66 | |
| 67 | ## Environment Setup |
| 68 | |
| 69 | First time, execute in the SKILL directory: |
| 70 | |
| 71 | ```bash |
| 72 | cd /app/.kimi/skills/kimi-docx/ |
| 73 | ./scripts/docx init |
| 74 | ``` |
| 75 | |
| 76 | **Fixed Path Conventions** (cannot be changed): |
| 77 | |
| 78 | | Path | Purpose | |
| 79 | |------|---------| |
| 80 | | `/app/.kimi/skills/kimi-docx/` | SKILL directory, where commands are executed | |
| 81 | | `/tmp/docx-work/` | Working directory, edit `Program.cs` here | |
| 82 | | `/mnt/okcomputer/output/` | Output directory, final deliverables | |
| 83 | | `/mnt/okcomputer/upload/` | User upload location (input files) | |
| 84 | |
| 85 | **Script Commands** (`./scripts/docx <cmd>`): |
| 86 | |
| 87 | | Command | Purpose | |
| 88 | |---------|---------| |
| 89 | | `env` | Show environment status (no changes) | |
| 90 | | `init` | Setup dependencies + workspace | |
| 91 | | `build [out]` | Compile, run, validate (default: output/output.docx) | |
| 92 | | `validate FILE` | Validate existing docx | |
| 93 | |
| 94 | The script automatically handles: |
| 95 | - Detects dotnet/python3 (required), pandoc/playwright/matplotlib (optional) |
| 96 | - Installed → use directly; Not installed → auto-install; Broken → repair |
| 97 | - Initializes working directory, copies template files |
| 98 | |
| 99 | ## Build Process |
| 100 | |
| 101 | **Must use `./scripts/docx build`**, do not execute `dotnet build && dotnet run` separately (skips validation). |
| 102 | |
| 103 | ### Program.cs Output Path Convention (Critical) |
| 104 | |
| 105 | **Program.cs must get output path from command line arguments**, otherwise build script cannot find the generated file: |
| 106 | |
| 107 | ```csharp |
| 108 | // Correct - get output path from command line arguments |
| 109 | string outputFile = args.Length > 0 ? args[0] : "/mnt/okcomputer/output/output.docx"; |
| 110 | |
| 111 | // Wrong - hardcoded path causes build failure |
| 112 | string outputFile = "my_document.docx"; // Script can't find file! |
| 113 | ``` |
| 114 | |
| 115 | | Step | Action | Notes | |
| 116 | |------|--------|-------| |
| 117 | | 1. Compile | `dotnet build` | Provides fix suggestions on failure | |
| 118 | | 2. Generate | `dotnet run -- <output path>` | Path passed via command line args | |
| 119 | | 3. Auto-fix | `fix_element_order.py` | Fixes XML element ordering issues | |
| 120 | | 4. OpenXML validation | `validator/` | Mand |