hermes-offline-dict
A Hermes Agent plugin that lets the agent look words
up in dictionaries on your own machine, without internet access. It reads the two open formats
offline dictionaries are published in:
- dictd (the format behind the DICT protocol, RFC 2229): a
name.indexfile and the definitions
inname.dictorname.dict.dz. FreeDict, GCIDE (the GNU Collaborative International Dictionary
of English), WordNet, the Jargon File and many Linuxdict-*packages ship this way. - StarDict:
name.ifo,name.idx(or.idx.gz),name.dict.dz(or.dict) and an optional
name.synof alternate spellings, versions 2.4.2 and 3.0.0 (including 64-bit offsets).
FreeDict alone publishes about 300 bilingual dictionaries in both formats.
Useful for translating, checking a word or a spelling, or answering from a dictionary you trust
instead of a web search, also when the agent has no network.
This plugin is not affiliated with the DICT Development Group, StarDict, FreeDict or GNU. It reads
the files with Python's standard library only.
Tools
| Tool | What it does |
|---|---|
dict_list | Lists the configured dictionaries: id, format, name, number of distinct headwords and of entries (definitions) and, when the dictionary gives them, its URL, author and a short description. |
dict_define | Returns every definition of a word in one dictionary or all of them, as plain text. Matching ignores case. When no headword matches exactly, headwords that differ only in accents, punctuation or spaces are returned and marked "match": "loose". When nothing matches, suggestions lists headwords one typing slip away or starting with the word. Long results come back in parts (next_offset). |
dict_match | Finds headwords without reading definitions, like the DICT protocol's MATCH: prefix (default), exact, substring, suffix, word (every word of the query is a whole word of the headword) and lev (one letter added, removed or changed, or two neighbouring letters swapped). |
The tools are offered to the model only while at least one path is configured.
How a headword is compared follows each dictionary's own rules. In StarDict and in a dictd
dictionary marked 00-database-allchars, every character counts (c++ is not c). In other dictd
dictionaries only letters, digits and spaces count, as dictd itself compares them: FreeDict
indexes aaron's rod as aarons rod, and the query aaron's rod finds it as an exact match.
Definitions are returned as text. StarDict's HTML, Pango, XDXF and KingSoft markup is reduced to
plain text with list numbers and nesting kept; plain-text fields, phonetics (shown as /.../) and
WordNet text are returned as written. Sound, pictures and resource files are not returned; their
place is marked, for example [sound not shown].
Install
hermes plugins install offline-dict --enable
No dependencies: the plugin uses only the Python standard library (gzip, zlib, struct,
html.parser, unicodedata).
Get some dictionaries
On Debian and Ubuntu, dictd packages install their files under /usr/share/dictd:
sudo apt install dict-gcide dict-wn dict-freedict-eng-tur
FreeDict also offers each dictionary as a download in both formats, listed in
freedict-database.json:
mkdir -p ~/dictionaries && cd ~/dictionaries
curl -LO https://download.freedict.org/dictionaries/eng-tur/0.3/freedict-eng-tur-0.3.dictd.tar.xz
tar -xJf freedict-eng-tur-0.3.dictd.tar.xz # creates eng-tur/ with eng-tur.index and eng-tur.dict.dz
StarDict dictionaries you already have (for example under ~/.stardict/dic or GoldenDict's
folders) work as they are. The dictionaries' own licenses apply to their content; FreeDict's are
listed in each archive's COPYING file.
Configure
plugins:
entries:
offline-dict:
settings:
paths: # dictionary files and/or folders holding them
- /usr/share/dictd
- ~/dictionaries
max_chars: 12000 # optional; characters per dict_define call (1000-100000)
A path can be a dictionary's .index or .ifo file or any other part of it (such as
eng-tur.dict.dz), or a folder, which is scanned together with its direct subfolders (StarDict
keeps one dictionary per folder). Each dictionary's id is its file name without the suffix, for
example eng-tur. If two dictionaries share a name, the first one wins and the second is reported
under problems. Missing paths, missing parts and unreadable dictionaries are reported the same way
and do not hide the others.
What it does on your machine (disclosure)
- Reads only the dictionaries you configure. For each one it opens its own files:
.indexand
.dict(.dz)for dictd,.ifo,.idx(.gz),.dict(.dz)and.syn(.dz)for StarDict. Folders are
listed only to find.indexand.ifofiles. - No network. Lookups are local. The test suite checks this by refusing to open any socket
while all three tools run. - Writes nothing. Files are opened for each call and closed again; nothing is kept between
calls. The tests check that every file is closed and that no file in the dictionary folders
changes. - No credentials, no shell commands, no background work.
- Bounded reading. An index larger than 256 MB (after unpacking) and a single definition larger
than 4 MB are refused rather than loaded. Onedict_definecall reads at most 200 definitions. - Content is third-party text. Definitions are returned to the model as the dictionary's authors
wrote them. Markup is reduced to plain text, but the words are not filtered. Use dictionaries from
sources you trust.
Limits
- Every call reads the index files again (nothing is cached), so a lookup takes time in proportion
to the size of the dictionaries it looks in. Measured on an Apple M4 with Python 3.14: about
0.7 s in FreeDict's German-English dictionary alone (517,534 entries), and about 1.4 s across five
dictionaries (FreeDict English-Turkish, French-English and German-English, GCIDE, WordNet), 1.9 s
when nothing matches and suggestions are collected. Passdictionaryto look in one only. - A
.dict.dzwritten by plaingzipinstead ofdictzip(no chunk table) still works, but each
definition is read by unpacking the file from the start, which is slow for large dictionaries. - Text only: sound and pictures in StarDict dictionaries are not returned.
- Regular-expression and Soundex matching (two of dictd's optional MATCH strategies) are not offered.
- A dictd index line with an empty headword cannot be looked up and is skipped. FreeDict's
German-English dictd index has six: symbols such as$and§, whose only characters the index
dropped.dictditself cannot reach them either; the StarDict edition of the same dictionary can.
Tested with
The plugin was run against these real dictionaries:
| Dictionary | Format | Entries | Headwords |
|---|---|---|---|
| FreeDict English-Turkish 0.3 | dictd / StarDict | 36,589 / 36,589 | 34,330 / 34,405 |
| FreeDict French-English 0.4.1 | dictd / StarDict | 8,505 / 8,505 | 8,249 / 8,417 |
| FreeDict German-English 1.9-fd1 | dictd / StarDict | 517,533 / 517,534 | 382,832 / 385,444 |
GCIDE 0.54 (Debian dict-gcide) | dictd | 126,277 | 177,010 |
WordNet 3.0 (Debian dict-wn) | dictd | 147,306 | 147,306 |
The dictd and StarDict editions of each FreeDict dictionary give the same number of entries
(German-English: one fewer in dictd, the one only reachable through an empty headword, see Limits). Their headword counts
differ because the dictd indexes drop punctuation (aaron's rod is aarons rod). In each of the
six FreeDict files, 300 randomly chosen headwords are each found as an exact match with non-empty
text; in all eight files, so are the first 25 headwords starting with "a" (the real_world test).
Development
python -m pip install pytest
python -m pytest -c tests/pytest.ini tests
OFFLINE_DICT_REAL=/usr/share/dictd:~/dictionaries python -m pytest -c tests/pytest.ini tests -k real_world
hermes plugins validate .
The tests write dictionaries in the real layouts: dictd indexes with dictd's base-64 offsets, in
UTF-8 and Latin-1, with a fourth "original headword" column and special 00-database-* entries in
both spellings converters use; definitions as plain .dict, as dictzip (a gzip file with an RA
chunk table, the deflate stream fully flushed after each chunk as dictzip writes it) and as plain
gzip; and StarDict sets in versions 2.4.2 and 3.0.0 with and without sametypesequence, a gzipped
index, 64-bit offsets and a .syn file. Broken dictionaries are there too: an index pointing past
the end of its data, a text file that is not an index, a wrong StarDict header or version, missing
parts and an oversized definition.
OFFLINE_DICT_REAL (one or more paths, separated like PATH) adds a test against real
dictionaries: for each one it takes up to 25 headwords starting with "a" and checks that each is
found as an exact match with non-empty text.
License
MIT
README from the reviewed commit 3f301ca; it updates when the author re-pins.

nftpoetrist