A Claude subscription can't be used by the app, so let it use any cheap
vision model on OpenRouter instead (default google/gemini-3.1-flash-lite,
OPENROUTER_MODEL to change). The Anthropic API stays available as the
second choice. Both providers share the prompt and live behind one
{ name, model, transcribe } interface in server/providers.mjs; OpenRouter
retries 408/429/5xx and network errors and turns 401/402/404 into
messages the editor can show.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
4.1 KiB
AGENTS.md — theater-reader
A Node 22 server (server/) serving a no-build front end (public/, plain HTML/CSS/ES modules) and a JSON API for plays
kept on a volume. Page photos are transcribed by a vision model through OpenRouter (plain fetch, chosen when OPENROUTER_API_KEY is set) or the
Anthropic SDK (@anthropic-ai/sdk, the only dependency, used with ANTHROPIC_API_KEY).
UI language is Czech.
Layout
server/main.mjs: HTTP server, routing, static files, auth (x-upload-passwordheader vsUPLOAD_PASSWORD), daily page cap, background transcription job.server/store.mjs: plays on disk,DATA_DIR/plays/<id>/{meta.json,play.txt,img/NNN.jpg}. Atomic writes; per-play lock for meta updates.server/providers.mjs:makeProvider(env)returns{ name, model, transcribe(jpeg) }for OpenRouter or Anthropic. Errors becomePageErrors whose message is shown in the editor. OpenRouter retries 408/429/5xx and network errors itself.server/transcribe.mjs:splitPage→normalizeSpeakers→assembleturn the per-photo answers into one play file.server/prompt.mjsholds the prompt (shared by both providers), which teaches the markup below.public/: four pages:index.htmllibrary (library.js),read.htmlreader (reader.js),add.htmlupload (add.js: shrinks photos to ≤1.15 MP JPEG in the browser),edit.htmleditor (edit.js).api.jsholds the fetch and password helpers.parse.jsis the markup parser, shared with the server tests.seed/: plays copied into an empty data volume on first start.public/fonts/: self-hosted woff2 + OFL licences, made bytools/fetch_fonts.py(keep itsFAMILIESandFONTSinreader.jsin step).
API
GET /api/config, POST /api/login, GET|POST /api/plays, GET|PATCH|DELETE /api/plays/:id, GET|PUT /api/plays/:id/text,
GET|PUT /api/plays/:id/images/:n (raw image/jpeg body), POST /api/plays/:id/transcribe (202, then poll the meta's progress).
Everything that writes needs the password. Unpublished plays answer 404 without it. Transcription refuses once the text has been
edited by hand, so it can't overwrite corrections.
Run / test
- Dev port 3010 on loopback. Preview with
ssh -p 14922 -L 3010:localhost:3010 <host>.podman-compose --env-file <file> up -d --build(env file withUPLOAD_PASSWORD, and optionallyOPENROUTER_API_KEYorANTHROPIC_API_KEY, chmod 600, outside the repo). - Tests (parser, transcription assembly, API end to end with Claude stubbed):
podman run --rm -v "$PWD":/app:ro,Z -w /app docker.io/library/node:22-alpine npm test(runnpm ciin the same image first ifnode_modulesis missing). - To exercise the full UI without spending API credit, use
ANTHROPIC_API_KEY=dummyand pointANTHROPIC_BASE_URLat a stub server that returns a Messages response.
Play markup
One directive per line; blank lines are ignored.
| Line | Meaning |
|---|---|
=N |
start of original page N |
!N / !N-M |
page(s) missing from the original (shown as a notice) |
@Name |
new speech by Name |
>(text |
stage direction; a following > text (one leading space) continues it |
> text |
verse/song line (two or more spaces after >) |
#text |
scene description at the left margin |
~text |
centred line (scene title, "O p o n a") |
. |
blank line; also ends the current speech, so a following > is a standalone direction |
| anything else | dialogue; at the top of a page, or after a standalone direction, it continues the last speaker |
The text keeps the typescript's line breaks, spelling and missing spaces ("dobře.Ale"). The "running text" mode joins
hyphenated words (nepří- / jemné, also the typist's ne - / spokojenců) and adds the missing spaces. A dash that
really is punctuation at the end of a line must be typed as – (en dash), or it gets joined to the next word.
[?] after a word marks an uncertain reading. The editor lists them.
To add a missing page to a play, e.g. page 7 of the 1931 play, open it in the editor and replace !7 with =7 and the page's text.