1---2name: oma-hwp3description: Convert HWP / HWPX / HWPML files to Markdown using kordoc. Extracts text, headings, tables, lists, images, footnotes, and hyperlinks. Use for Korean word processor files (Hangul), government documents, and AI-ready data preparation.4---5
6# HWP Skill - HWP / HWPX / HWPML to Markdown Conversion
7
8## Scheduling
9
10### Goal
11Convert Korean HWP-family documents into readable Markdown or structured JSON while preserving document structure for LLM context, RAG, government-document review, or enterprise document processing.
12
13### Intent signature
14- User asks to convert, parse, read, extract, or transform `.hwp`, `.hwpx`, or `.hwpml`.
15- User mentions Korean word processor files, Hangul documents, government forms, or "한글 파일".
16- User needs headings, tables, nested tables, lists, images, footnotes, or hyperlinks extracted from HWP-family files.
17
18### When to use
19- Converting Korean HWP documents (`.hwp`, `.hwpx`, `.hwpml`) to Markdown
20- Preparing Korean government/enterprise documents for LLM context or RAG
21- Extracting structured content (tables, headings, lists, images) from HWP
22- User says "convert this HWP", "parse hwpx", "HWP to markdown", "한글 파일"
23
24### When NOT to use
25- PDF files -> use `oma-pdf` (OCR + Tagged PDF specialization)
26- XLSX / DOCX files -> out of scope; run `bunx kordoc` directly if needed (note: `oma-docs` is the documentation-drift skill, not a converter)
27- Generating or editing HWP documents -> out of scope
28- Already-text files -> use Read tool directly
29
30### Expected inputs
31- `input_path`: `.hwp`, `.hwpx`, or `.hwpml` file path
32- `output_path` or `output_dir`: optional explicit output target
33- `format`: optional output format, default `markdown`
34- `page_range`: optional page or section range
35- `kordoc_version`: optional pinned kordoc version
36
37### Expected outputs
38- Markdown output next to the input file or in the requested directory
39- Optional JSON output when requested
40- Post-processed Markdown with flattened GFM tables and stripped Private Use Area glyphs by default
41- A short report with output path, detected source format, and conversion issues
42
43### Dependencies
44- `bun` and `bunx`
45- `bunx kordoc@latest` or configured pinned kordoc version
46- `resources/flatten-tables.ts` for Markdown cleanup
47- Local filesystem access to input and output paths
48
49### Control-flow features
50- Branches by file extension, output target, format, page range, encryption/DRM state, and post-processing requirements
51- Calls external CLI tools through `bunx` and `bun run`
52- Reads local HWP-family files and writes local Markdown or JSON output
53- Routes non-HWP inputs to other skills instead of stretching this skill's scope
54
55## Structural Flow
56
57### Entry
581. Confirm the input path exists.
592. Confirm the extension is `.hwp`, `.hwpx`, or `.hwpml`.
603. Resolve output path or directory and default filename.
614. Check that `bun` is available.
62
63### Scenes
641. **PREPARE**: Validate path, extension, size, output target, and requested format.
652. **ACQUIRE**: Detect source format and runtime availability.
663. **ACT**: Run `kordoc` with explicit output target and requested options.
674. **VERIFY**: Post-process Markdown and inspect structure for headings, tables, lists, images, and footnotes.
685. **FINALIZE**: Report output path, source format, and any conversion limitations.
69
70### Transitions
71- If the input is `.pdf`, stop and route to `oma-pdf`.
72- If the input is `.xlsx` or `.docx`, explain that this skill does not advertise those formats.
73- If `bun` is unavailable, stop and ask the user to install Bun.
74- If Markdown is produced, run `resources/flatten-tables.ts` unless the caller explicitly needs HTML tables or PUA glyphs preserved.
75- If output is empty or garbled, consult `resources/troubleshooting.md`.
76
77### Failure and recovery
78| Failure | Recovery |
79|---------|----------|
80| `bun` or `bunx` unavailable | Ask user to install Bun |
81| Unsupported or mismatched format | Check extension and magic bytes, then route or stop |
82| Encrypted or DRM-locked document | Report limitation and request an accessible copy when needed |
83| Empty Markdown output | Treat as possible scanned-image content and recommend OCR outside this skill |
84| Complex merged tables | Accept flattened Markdown or HTML fallback as best effort |
85| Stale kordoc cache | Use `bunx kordoc@latest` or configured pinned version |
86| `Cannot find module "turndown"` from `flatten-tables.ts` | Run `bun install` in `.agents/skills/oma-hwp/resources/` (its `node_modules` is gitignored and absent on fresh clones) |
87
88### Exit
89- Success: output file exists and structure is readable after post-processing.
90- Partial success: output exists with explicitly reported table, glyph, encryption, or fidelity limitations.
91- Failure: no reliable output is produced and the blocking cause is reported.
92
93## Logical Operations
94
95### Actions
96| Action | SSL primitive | Evidence |
97|--------|---------------|----------|
98| Validate file path and extension | `VALIDATE` | Input preflight in execution protocol |
99| Check runtime availability | `VALIDATE` | `bun --version` |
100| Select output target and format | `SELECT` | Output behavior and config |
101| Run converter | `CALL_TOOL` | `bunx kordoc@latest` |
102| Write output artifact | `WRITE` | Markdown or JSON output |
103| Flatten tables and strip PUA glyphs | `CALL_TOOL` | `resources/flatten-tables.ts` |
104| Inspect extraction quality | `VALIDATE` | Verification step |
105| Report result | `NOTIFY` | Final user-facing summary |
106
107### Tools and instruments
108- `kordoc`: primary HWP-family conversion CLI
109- `flatten-tables.ts`: post-processing for GFM tables and Hancom PUA cleanup
110- `bun` / `bunx`: runtime and CLI executor
111
112### Canonical command path
113```bash
114bunx kordoc@latest "{input_path}" -o "{output_path}"
115# fresh clone: run `bun install` in .agents/skills/oma-hwp/resources/ first (node_modules is gitignored)
116bun ".agents/skills/oma-hwp/resources/flatten-tables.ts" "{output_path}"
117```
118
119For batch conversion, use an explicit output directory:
120```bash
121bunx kordoc@latest "{input_pattern}" -d "{output_dir}"
122```
123
124### Resource scope
125| Scope | Resource target |
126|-------|-----------------|
127| `LOCAL_FS` | Input HWP-family files and generated outputs |
128| `PROCESS` | `bunx kordoc` and `bun run` subprocesses |
129| `MEMORY` | Format decisions, validation notes, and final report |
130
131### Preconditions
132- Input file exists and is readable.
133- Output location is writable or can be created.
134- `bun` is installed.
135- `kordoc` can parse the document or fail with a reportable error.
136
137### Effects and side effects
138- Creates Markdown or JSON output files.
139- May flatten merged-cell tables, trading cell fidelity for Markdown compatibility.
140- Strips Private Use Area characters by default because they render as blanks without Hancom fonts.
141- Does not intentionally modify the source HWP-family document.
142
143### Guardrails
1441. Always pass `@latest` or an explicit pinned version to avoid stale `bunx` cache.
1452. Always pass an explicit output target when the user expects a file.
1463. Do not add custom security defenses around kordoc's ZIP, XML, SSRF, or XSS defenses.
1474. Report missing tables, garbled text, empty output, encrypted segments, and best-effort DRM extraction.
1485. Keep full CLI details in `resources/execution-protocol.md` and troubleshooting branches in `resources/troubleshooting.md`.
149
150### Supported Formats
151| Format | Extension | Notes |
152|--------|-----------|-------|
153| HWP 5.x binary | `.hwp` | Full support (incl. DRM-locked via kordoc's rhwp-algorithm port) |
154| HWPX | `.hwpx` | Full support incl. nested tables, merged cells |
155| HWPML | `.hwp` (XML variant) | Auto-detected by signature |
156
157> kordoc also parses PDF / XLSX / DOCX. Those are intentionally outside this skill's scope; see "When NOT to use".
158
159## References
160- Execution protocol: `resources/execution-protocol.md`
161- Troubleshooting: `resources/troubleshooting.md`
162- Configuration: `config/hwp-config.yaml`
163- Upstream: https://github.com/chrisryugj/kordoc
164- Related: `../oma-pdf/SKILL.md` (use for `.pdf` inputs)