Files
pack.gutendex/README.md
T
gabby 530e9968a4 gutendex: read a book aloud over a voice front end
read_book now checks the local library first: a book already saved (matched by
Project Gutenberg id, or by the name in the request) is read from disk with no
network at all, and a book resolved from the catalog is reused from disk rather
than re-downloaded.

When the request arrives from a front end that can stream a read-aloud (the
local voice gateway, or an LXMF/Sideband voice chat), the saved text is handed
to the scheduler's speech channel (ctx.speech) instead of being summarised: the
gateway streams it through Piper a chunk at a time until the user stops it, and
the position is kept in a bookmarks.json beside the saved books so a later
request resumes where the listener stopped. A text front end keeps the
saved-file summary, and the skill reports honestly when a book has no plain
text to read.

The skill asks ctx.speech.supports(source) on both the saved-library and the
fresh-download paths; the manifest/README describe the read-aloud and the
library-first behaviour.
2026-10-17 23:29:50 +00:00

83 lines
3.4 KiB
Markdown

# gutendex — a semif-agent skill pack
A self-contained [semif-agent](https://github.com/gabbymorgan/semif-agent) pack
for the [Gutendex](https://gutendex.com/) catalog of
[Project Gutenberg](https://www.gutenberg.org/) ebooks. It lets the agent:
- **`gutendex.find_books`** — find public-domain books by **author**, **title**,
or **genre** (author/title use Gutendex `search`; genre uses `topic`).
- **`gutendex.read_book`** — resolve a book by name or Project Gutenberg id and
read it. It checks the **local library first** (the books folder): a book
already saved — matched by id, or by the name in the request — is read from
disk with no network at all, and a book resolved from the catalog is reused
from disk rather than downloaded again. A book not in the library is
downloaded and saved as a `.txt` file. Over a **voice front end** (the local
voice gateway, or an LXMF/Sideband voice chat) it instead **reads the book
aloud**: the text is streamed through Piper one chunk at a time until the user
says "stop", and the position is kept in a `bookmarks.json` beside the saved
books so a later request **resumes** where the listener stopped. A book is far
too long to speak as a chat reply, so over a text front end it is saved to a
file and summarised.
Gutendex is a free public JSON API. This pack needs **no account, no
credentials, and no bridge** — the skill bodies make the HTTP requests directly
with the standard library.
## Layout
```
gutendex/
pack.json # the pack manifest
skills/gutendex/find_books/
skill.py manifest.json contract.json skill.test.py
skills/gutendex/read_book/
skill.py manifest.json contract.json skill.test.py
```
## Install
Packs are loaded from the `skill_packs` root(s) in the agent's config. Either:
- drop this `gutendex/` folder into the agent's `packs/` directory, or
- keep it as its own checkout and point the config at the parent directory:
```json
{ "skill_packs": ["packs", "/path/to/agent-packs"] }
```
(a root directory is scanned for `*/pack.json`, so a folder of pack
checkouts works directly).
The pack is enabled by default (`enabled_by_default: true`); toggle it with
`pack.gutendex.enabled` in the config.
## Configuration
Both skills declare contract variables the runner resolves from the tiered
config (`global → category → skill`) or asks for once on first fire. To avoid
the one-time prompt, set them in the config:
| Variable | Used by | Example |
| -------------------- | ---------------------- | ---------------------- |
| `gutendex_base_url` | both skills | `https://gutendex.com` |
| `output_dir` | `gutendex.read_book` | `/home/me/books` |
`read_book` writes the downloaded text to
`<output_dir>/gutenberg-<id>-<slug>.txt` and returns the path. A book's full
text is far longer than the agent's speakable result budget, so it is saved to a
file and summarised rather than dumped into the reply.
## Tests
Each leaf ships a hermetic mechanics test (stdlib `http.server` on loopback, no
external network):
```sh
cd skills/gutendex/find_books && python skill.test.py
cd skills/gutendex/read_book && python skill.test.py
```
`PYTHONPATH` must include the agent checkout so `semif_agent` is importable.
Passing these proves the mechanics only; a real run against Gutendex is the only
proof of the live integration.