Preface¶
When working on long-form text or ebook-related tasks in DeepSeek Harness (DSH), models can typically only handle “a chunk of HTML” or “a few chapter files,” whereas EPUB is itself a container with mandatory constraints: inside the ZIP, mimetype must be first and uncompressed, and inside the OPF, the spine and nav must be consistent with each other. Using a general-purpose ZIP library to bundle things on the fly often doesn’t immediately throw errors—instead, the common problems are that readers refuse to open the file, or chapter boundaries are misidentified yet the file still opens—making debugging costly.
The following introduces the community plugin dsh-tool-epub (maintainer yuehancn, GitHub: yuehancn/dsh-tool-epub). It provides four tools within the DSH process, separating “first understand the structure” from “then modify/build.” ZIP reading/writing and XML parsing are implemented in-house, with no dependence on epubjs or jszip, and externalDependency is set to none. The plugin is categorized under “Model Inference” in the SkillHub directory; it is essentially an EPUB toolkit for agents to call, not a standalone reasoning model.
What Is This¶
dsh-tool-epub is a self-built tool plugin for DeepSeek Harness: it performs read-only health checks on existing .epub files, assembles compliant EPUB 3 from chapters or a single large HTML, or splits an EPUB back into per-chapter files according to spine order. The README states it was built and tested on dsh 0.2.0-rc.2 (preview); the apply(ctx) plugin spec is stable, but if you use a newer dsh version, you should verify compatibility yourself. The version in package.json is 1.0.0, licensed under MIT.
Why EPUB Needs Specialized Tools¶
EPUB is not a Word file with a changed extension; it is a combination of ZIP + OCF + OPF + XHTML. The error-prone parts are usually in the judgment phase:
- The spine (reading order) and nav (table of contents) each declare chapters; when the two disagree, most “the book is broken” complaints originate here.
- Splitting chapters from a large HTML relies on inferring heading hierarchy; when the inference is wrong, chapters may silently become misaligned.
- Most ZIP libraries compress all entries by default; once
mimetypeis compressed, strict readers will outright refuse the file.
The plugin design separates epub_inspect into an independent read-only tool, without forcing it as a prerequisite step for epub_build: “what does this book look like now” and “what kind of book do I want to build” are two independent decisions.
The Four Tools¶
epub_status¶
Call this before long-running tasks to see what this plugin supports (read, build, split), as well as externalDependency: none; it also returns the maximum chapter count and per-call time budget, so you don’t hit a ceiling halfway through.
epub_inspect(path)¶
Read-only, no writes; it can return the following without unpacking to disk:
| Return Item | Description |
|---|---|
title / creator / language / identifier |
OPF metadata |
epubVersion |
Usually 3.0 |
entryCount |
Number of ZIP entries |
chapters[] |
Per-chapter records in spine order, including words and bytes |
toc[] |
Nav table-of-contents tree |
totalWords |
Total word count of the book |
images[] |
Referenced images |
warnings[] |
List of structural issues |
warnings will explicitly list issues such as: mimetype is compressed or not in first position; a file declared in the spine does not exist in the ZIP; a nav href is dangling; a spine document is unreachable in the table of contents; linear="no"; missing properties="nav", etc.
epub_build(outputName, …)¶
Generates EPUB 3, with two possible paths (choose one):
| Method | Parameters | Use Case |
|---|---|---|
| Explicit chapters | chapters: [{title, html}, …] |
Boundaries are known |
| Auto-inference | html: "<a large HTML>" + splitLevel |
Split by heading hierarchy |
outputName is required (e.g., my-book.epub). Optional parameters: title, language, author, identifier (if not provided, a stable URN is generated from the content), splitLevel (default auto or h1–h6), coverImagePath. The return value includes splitRule, explaining how boundaries were split; word-count statistics in build and inspect use the same basis (including injected <h1>).
epub_split(path, …)¶
Splits an EPUB into per-chapter files in spine order and writes a manifest.
| Parameter | Description |
|---|---|
path |
Required, .epub path |
outputDir |
Defaults to configuration |
format |
html (default) or txt |
prefix |
Filename prefix, default is a slug, supports Chinese |
includeToc |
Whether to additionally write an index.html table-of-contents page |
txt and word-count statistics share the same tag-stripping logic; chapter filenames are zero-padded to three digits according to spine (-001, -002), so lexicographic order matches reading order.
Installation and Activation¶
One-line installation (command from the project README):
dsh plugin --profile desktop add github:yuehancn/dsh-tool-epub
Supported profiles: desktop, web. After installation, restart dsh to see the above capabilities in the tool list.
Configuration¶
Plugin configuration can be overridden in ~/.dsh/profiles/<profile>/cordis.patch.yml, for example:
# ~/.dsh/profiles/<profile>/cordis.patch.yml
- id: tool-epub
config:
outputDir: C:/Users/you/Documents/epub-output
defaultTitle: Untitled
defaultLanguage: zh-CN
defaultAuthor: Your Name
maxChapters: 500
timeoutMs: 60000
| Field | Default | Description |
|---|---|---|
outputDir |
epub-output |
Output directory |
defaultTitle |
Untitled |
Fallback when no title is provided |
defaultLanguage |
en |
BCP 47; for Chinese books, set zh-CN |
defaultAuthor |
"" |
Author written into the generated book |
maxChapters |
500 |
Refuses to build if exceeded |
timeoutMs |
60000 |
Per-call time budget |
status / inspect / build / split |
true |
Can turn individual tools off as needed |
Typical Usage Patterns¶
- For an existing book:
epub_inspect(path="book.epub"), then decide whether to modify spine/nav or repackage based onwarnings,chapters[], andtoc[]. - From a known chapter list:
epub_build(outputName="my-book.epub", title="…", chapters=[{title, html}, …]). - From a full-page HTML:
epub_build(..., html="…", splitLevel="auto"), then check whether the returnedsplitRulematches expectations. - Export for editing:
epub_split(path="book.epub", format="html"), producing spine-ordered chapter files under the configuredoutputDir.
Before long-running tasks, you can first call epub_status to confirm the chapter limit and timeout budget.
Security and Runtime Environment¶
The README states: hrefs are normalized via resolvePath with zip-slip protection; ../ in outputName is sanitized; no network access, no execution of scripts inside books—only text and XML parsing; same input yields byte-identical EPUB (fixed timestamps and identifier strategy), facilitating diff comparison.
Applicability and Notes: The plugin reads and writes to paths you specify under the permissions of the current dsh process; before installation, it is recommended to read the source repository and the MIT license. The DSH ecosystem emphasizes “everything is a plugin”; the SkillHub plugin directory is a community site with no official affiliation with DeepSeek or High-Flyer.
Conclusion¶
dsh-tool-epub brings EPUB’s “health check, assembly, and disassembly” into the DSH tool surface, emphasizing spine/nav consistency and explainable chapter-splitting rules. It is suitable for scenarios where you need to process EPUB 3 within agent workflows while maintaining zero additional npm ebook dependencies.
- Directory page: https://www.skillhub.cn/plugins/yuehancn/dsh-tool-epub
- GitHub: https://github.com/yuehancn/dsh-tool-epub