1---2name: oma-hwp-23description: 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---56# HWP Skill - HWP / HWPX / HWPML to Markdown Conversion78## Scheduling910### Goal11Convert 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.1213### Intent signature14- 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.1718### When to use19- Converting Korean HWP documents (`.hwp`, `.hwpx`, `.hwpml`) to Markdown20- Preparing Korean government/enterprise documents for LLM context or RAG21- Extracting structured content (tables, headings, lists, images) from HWP22- User says "convert this HWP", "parse hwpx", "HWP to markdown", "한글 파일"2324### When NOT to use25- 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 (kordoc itself supports `generate` / `fill` / `seal` / `patch` / `redact` / `lint` / `validate` / `render` subcommands; run `bunx kordoc@latest <subcommand>` directly if needed)28- Already-text files -> use Read tool directly2930### Expected inputs31- `input_path`: `.hwp`, `.hwpx`, or `.hwpml` file path32- `output_path` or `output_dir`: optional explicit output target33- `format`: optional output format — `markdown` (default), `json` (structured AST), or `chunks` (RAG-oriented structural chunk JSON with heading breadcrumbs and standalone table chunks)34- `page_range`: optional page or section range35- `kordoc_version`: optional pinned kordoc version3637### Expected outputs38- Markdown output next to the input file or in the requested directory39- Optional JSON or RAG-chunks output when requested40- Post-processed Markdown with flattened GFM tables and stripped Private Use Area glyphs by default41- A short report with output path, detected source format, and conversion issues4243### Dependencies44- `bun` and `bunx`45- `bunx kordoc@latest` or configured pinned kordoc version46- `resources/flatten-tables.ts` for Markdown cleanup47- Local filesystem access to input and output paths4849### Control-flow features50- Branches by file extension, output target, format, page range, encryption/DRM state, and post-processing requirements51- Calls external CLI tools through `bunx` and `bun run`52- Reads local HWP-family files and writes local Markdown or JSON output53- Routes non-HWP inputs to other skills instead of stretching this skill's scope5455## Structural Flow5657### Entry581. 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.6263### Scenes641. **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.6970### Transitions71- 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`.7677### Failure and recovery78| 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 this skill's `resources/` directory (its `node_modules` is gitignored and absent on fresh clones) |8788### Exit89- 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.9293## Logical Operations9495### Actions96| 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 |106107### Tools and instruments108- `kordoc`: primary HWP-family conversion CLI109- `flatten-tables.ts`: post-processing for GFM tables and Hancom PUA cleanup110- `bun` / `bunx`: runtime and CLI executor111112### Canonical command path113```bash114bunx kordoc@latest "{input_path}" -o "{output_path}"115# fresh clone: run `bun install` in {skill_dir}/resources/ first (node_modules is gitignored)116bun "{skill_dir}/resources/flatten-tables.ts" "{output_path}"117# {skill_dir} = this skill's directory: .agents/skills/oma-hwp (project mode) or ~/.agents/skills/oma-hwp (global mode)118```119120For batch conversion, use an explicit output directory:121```bash122bunx kordoc@latest "{input_pattern}" -d "{output_dir}"123```124125### Resource scope126| Scope | Resource target |127|-------|-----------------|128| `LOCAL_FS` | Input HWP-family files and generated outputs |129| `PROCESS` | `bunx kordoc` and `bun run` subprocesses |130| `MEMORY` | Format decisions, validation notes, and final report |131132### Preconditions133- Input file exists and is readable.134- Output location is writable or can be created.135- `bun` is installed.136- `kordoc` can parse the document or fail with a reportable error.137138### Effects and side effects139- Creates Markdown or JSON output files.140- May flatten merged-cell tables, trading cell fidelity for Markdown compatibility.141- Strips Private Use Area characters by default because they render as blanks without Hancom fonts.142- Does not intentionally modify the source HWP-family document.143144### Guardrails1451. Always pass `@latest` or an explicit pinned version to avoid stale `bunx` cache.1462. Always pass an explicit output target when the user expects a file.1473. Do not add custom security defenses around kordoc's ZIP, XML, SSRF, or XSS defenses.1484. Report missing tables, garbled text, empty output, encrypted segments, and best-effort DRM extraction.1495. Keep full CLI details in `resources/execution-protocol.md` and troubleshooting branches in `resources/troubleshooting.md`.150151### Supported Formats152| Format | Extension | Notes |153|--------|-----------|-------|154| HWP 5.x binary | `.hwp` | Full support (incl. DRM-locked via kordoc's rhwp-algorithm port) |155| HWPX | `.hwpx` | Full support incl. nested tables, merged cells |156| HWPML | `.hwp` (XML variant) | Auto-detected by signature |157158> 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`.159160## References161- Execution protocol: `resources/execution-protocol.md`162- Troubleshooting: `resources/troubleshooting.md`163- 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.164- Upstream: https://github.com/chrisryugj/kordoc165- Related: `../oma-pdf/SKILL.md` (use for `.pdf` inputs)