1---
2name: oma-hwp
3description: Convert HWP / HWPX / HWPML files to Markdown using kordoc. Extracts
4 text, headings, tables, lists, images, footnotes, and hyperlinks. Use for
5 Korean word processor files (Hangul), government documents, and AI-ready data
6 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 (kordoc itself supports `generate` / `fill` / `seal` / `patch` / `redact` / `lint` / `validate` / `render` subcommands; run `bunx kordoc@latest <subcommand>` directly if needed)
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 — `markdown` (default), `json` (structured AST), or `chunks` (RAG-oriented structural chunk JSON with heading breadcrumbs and standalone table chunks)
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 or RAG-chunks 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 this skill's `resources/` directory (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 {skill_dir}/resources/ first (node_modules is gitignored)
119bun "{skill_dir}/resources/flatten-tables.ts" "{output_path}"
120# {skill_dir} = this skill's directory: .agents/skills/oma-hwp (project mode) or ~/.agents/skills/oma-hwp (global mode)
121```
122
123For batch conversion, use an explicit output directory:
124```bash
125bunx kordoc@latest "{input_pattern}" -d "{output_dir}"
126```
127
128### Resource scope
129| Scope | Resource target |
130|-------|-----------------|
131| `LOCAL_FS` | Input HWP-family files and generated outputs |
132| `PROCESS` | `bunx kordoc` and `bun run` subprocesses |
133| `MEMORY` | Format decisions, validation notes, and final report |
134
135### Preconditions
136- Input file exists and is readable.
137- Output location is writable or can be created.
138- `bun` is installed.
139- `kordoc` can parse the document or fail with a reportable error.
140
141### Effects and side effects
142- Creates Markdown or JSON output files.
143- May flatten merged-cell tables, trading cell fidelity for Markdown compatibility.
144- Strips Private Use Area characters by default because they render as blanks without Hancom fonts.
145- Does not intentionally modify the source HWP-family document.
146
147### Guardrails
1481. Always pass `@latest` or an explicit pinned version to avoid stale `bunx` cache.
1492. Always pass an explicit output target when the user expects a file.
1503. Do not add custom security defenses around kordoc's ZIP, XML, SSRF, or XSS defenses.
1514. Report missing tables, garbled text, empty output, encrypted segments, and best-effort DRM extraction.
1525. Keep full CLI details in `resources/execution-protocol.md` and troubleshooting branches in `resources/troubleshooting.md`.
153
154### Supported Formats
155| Format | Extension | Notes |
156|--------|-----------|-------|
157| HWP 5.x binary | `.hwp` | Full support (incl. DRM-locked via kordoc's rhwp-algorithm port) |
158| HWPX | `.hwpx` | Full support incl. nested tables, merged cells |
159| HWPML | `.hwp` (XML variant) | Auto-detected by signature |
160
161> kordoc also parses PDF / XLSX / DOCX and offers document-authoring subcommands (`generate`, `fill`, `seal`, `patch`, `redact`, `lint`, `validate`, `render`). All of those are intentionally outside this skill's scope; see "When NOT to use". Conversion-quality flags (`--dedupe-headers`, `--keep-empty-cols`, `--inline-images`) and the `chunks` format are documented in `resources/execution-protocol.md`.
162
163## References
164- Execution protocol: `resources/execution-protocol.md`
165- Troubleshooting: `resources/troubleshooting.md`
166- Configuration: read the `hwp:` section of `.agents/oma-config.yaml` first, then fall back to `config/hwp-config.yaml` for any key it does not set (`supported_formats` lives only in the skill config). User overrides belong in `.agents/oma-config.yaml`, since `oma update` overwrites the skill config.
167- Upstream: https://github.com/chrisryugj/kordoc
168- Related: `../oma-pdf/SKILL.md` (use for `.pdf` inputs)