Files
thd/hd-joe/README.md
2026-10-15 17:27:46 +02:00

72 lines
3.9 KiB
Markdown

# hd-joe
The Python side of the terminal editor. Owns the Socket.IO/OT connection to
HedgeDoc and drives a patched JOE over a private Unix socket.
Run `../install.sh` from the repo root first (builds patched JOE, sets up a
venv, links `hdc` and `hd-joe` onto your PATH). This README covers `hd-joe`
specifically once that's done; see the top-level README for the whole repo.
## Running
Two forms. The second needs an `hdc`-managed folder (see `../hd-cli/`); the
first works anywhere.
# Explicit: any server, any note, no hdc setup needed
hd-joe https://hedgedoc.example <note-id> --cookie 'connect.sid=...'
# From inside ~/notes/<tag>/ : reads .hd/config.json + cookies.json,
# opens "Project" if a symlink for it exists here, else creates it
# tagged with this directory's name
cd ~/notes/radio
hd-joe "Project"
Useful flags: `--debug` (verbose log), `--log PATH` (default
`~/.local/state/picocalc/hd-joe.log`), `--buffer PATH` (keep the working
file instead of a temp file), `--quiet`, `--joe PATH` (use a specific joe
binary instead of the one `install.sh` put on PATH).
## Files
| File | |
| --- | --- |
| `hd-joe` | Entry point (thin `sh` wrapper around `hd_joe_agent.py`). |
| `hd_joe_agent.py` | CLI, JOE subprocess management, the Unix-socket bridge, translating OT operations into JOE insert/delete commands. |
| `joe_wrapper.py` | Installed AT the `joe` name (see top-level README's "The joe wrapper") -- routes hd-managed notes here, everything else to the real binary. `decide()` is the pure, tested routing logic; `run()`/`main()` just `exec` whatever it returns. |
`hd_client.py` (the OT engine) and `hd_core.py` (folder discovery, note
creation, tag writing, reconciliation) live in `../hd_common/` — see
`../hd_common/README.md`. Both this package and `../hd-cli/` import them
from there; there's only one copy.
## Tests
No network or real server needed — they spin up fake HedgeDoc servers
locally. The pty-driven ones need a built `joe`:
JOE_BIN=/path/to/joe-4.8/joe/joe python3 e2e_test.py # BOF/EOF edits
ACK_DELAY=0.15 JOE_BIN=... python3 e2e_test.py # ...under latency
python3 ai_replace_test.py # AI block replace
JOE_BIN=... python3 cursor_after_ai_test.py # cursor after AI answer
JOE_BIN=... python3 test_hd_joe_create.py # hd-joe <name> create/open
JOE_BIN=... python3 test_hd_cache_refresh.py # cache updates after editing
JOE_BIN=... python3 test_hd_cache_live_refresh.py # ...and while still open
python3 test_hd_create.py # discovery/create logic
python3 test_joe_wrapper.py # joe-vs-hd-joe routing logic
JOE_BIN=... python3 test_joe_wrapper_exec.py # wrapper really execs real joe
JOE_BIN=... python3 test_joe_wrapper_hdjoe_exec.py # ...and really execs hd-joe
python3 test_disconnect_hook.py # connection-state hook fires correctly
python3 test_shadow_text_sync.py # _shadow_text stays in sync even on error
JOE_BIN=... HD_DRAIN_TIMEOUT=2.0 python3 test_offline_handling.py # offline: no cache poisoning, recovery file
JOE_BIN=... python3 test_real_disconnect_pty.py # real disconnect, JOE survives the M command
`fake_hedgedoc.py` is a standalone fake server for poking at things by hand.
**These fake servers have been wrong three times.** Each time, real HedgeDoc
did something the mock didn't: acked instantly (hid a rejected-operation
bug), had no DB-flush lag (hid a stale-content bug), never broadcast to
other clients (hid that whole category). They were patched after reality
disagreed, not before. Treat a green test suite as necessary, not
sufficient — and if you add coverage, make the fake stricter rather than
more convenient.