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