first commit
This commit is contained in:
136
README.md
Normal file
136
README.md
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
# HedgeDoc terminal client
|
||||||
|
|
||||||
|
A terminal client for HedgeDoc built on the real Joe's Own Editor, plus a
|
||||||
|
CLI that mirrors your notes into a tag-organized local folder.
|
||||||
|
|
||||||
|
hd_common/ hd_client.py + hd_core.py, shared by both packages below
|
||||||
|
hd-joe/ the editor: patched JOE <-> HedgeDoc realtime bridge,
|
||||||
|
plus joe_wrapper.py (see "The joe wrapper" below)
|
||||||
|
hd-cli/ the `hdc` command: ~/notes/<tag>/ mirror, hdc tag/untag
|
||||||
|
joe-patch/ the patch against joe 4.8 source
|
||||||
|
build.sh builds patched joe (clone, patch, configure, make)
|
||||||
|
install.sh installs it (backing up your original), links hdc/hd-joe
|
||||||
|
CHANGES-*.md per-version notes, worth reading for the "why"
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
./build.sh # patched joe -> joe-patch/build/joe-4.8/joe/joe
|
||||||
|
./install.sh # installs the joe wrapper, sets up a venv, links hdc +
|
||||||
|
# hd-joe on PATH, and enables continuous background sync
|
||||||
|
|
||||||
|
Then `hdc init <url> --dir ~/notes` (see `hd-cli/README.md`) -- the sync
|
||||||
|
service `install.sh` just enabled starts actually syncing as soon as
|
||||||
|
`~/notes/.hd/` exists. `hd-joe/README.md` for using `hd-joe` itself.
|
||||||
|
`install.sh --restore` undoes everything: original `joe` back, `hdc`/`hd-joe`
|
||||||
|
links removed, sync service disabled and removed.
|
||||||
|
|
||||||
|
## Continuous background sync
|
||||||
|
|
||||||
|
`install.sh` sets up a `systemd --user` service (`hdc-sync.service`,
|
||||||
|
`~/.config/systemd/user/hdc-sync.service`) running `hdc sync --watch`
|
||||||
|
continuously. Without it, a note created in the web UI only shows up
|
||||||
|
locally the next time you happen to run `hdc sync` by hand -- which
|
||||||
|
defeats the point of having a local mirror at all.
|
||||||
|
|
||||||
|
- `--notes-dir DIR` (default `~/notes`, matching `hdc`'s own default) and
|
||||||
|
`--sync-interval N` (default 30 seconds) control what the service does;
|
||||||
|
`--no-service` skips setting it up at all, if you'd rather run `hdc sync
|
||||||
|
--watch` yourself some other way (cron, tmux, a different init system).
|
||||||
|
- If `~/notes/.hd/` doesn't exist yet (you haven't run `hdc init`), the
|
||||||
|
service is written and enabled but not started -- `install.sh` tells you
|
||||||
|
the one command to run once you have.
|
||||||
|
- If your session has no reachable `systemd --user` bus at all (a bare SSH
|
||||||
|
connection with no login manager, some container/CI setups), `install.sh`
|
||||||
|
says so plainly, still writes the unit file, and gives you the exact
|
||||||
|
command to run once you do have a normal session -- it doesn't fail the
|
||||||
|
rest of the install over this.
|
||||||
|
- `Restart=on-failure` with rate-limiting (max 10 restarts per 5 minutes)
|
||||||
|
so a note-taking session interrupted by a network blip recovers on its
|
||||||
|
own, without either hammering the server or systemd giving up on the
|
||||||
|
unit permanently.
|
||||||
|
|
||||||
|
Manage it directly with the usual `systemctl --user` commands --
|
||||||
|
`status`/`stop`/`start`/`restart hdc-sync.service`, `journalctl --user -u
|
||||||
|
hdc-sync.service` for its log.
|
||||||
|
|
||||||
|
## The joe wrapper
|
||||||
|
|
||||||
|
`joe` itself, once installed, isn't the raw compiled binary -- it's a
|
||||||
|
small wrapper (`hd-joe/joe_wrapper.py`) that decides, on every invocation:
|
||||||
|
|
||||||
|
- **An existing hd-managed note** (anywhere under some `.hd/notes/`, found
|
||||||
|
by resolving whatever path you gave it) always routes to `hd-joe`,
|
||||||
|
regardless of where you're standing. This is a safety property, not just
|
||||||
|
convenience: without it, `joe` on a note's cache file would edit it
|
||||||
|
directly on disk, silently, with no connection to HedgeDoc at all --
|
||||||
|
invisible to anyone else, and overwritten by the next `hdc sync`.
|
||||||
|
- **A name that doesn't exist yet**, typed while your current directory is
|
||||||
|
itself inside an hd-managed folder, routes to `hd-joe`'s create-or-open
|
||||||
|
logic -- same as running `hd-joe <name>` directly.
|
||||||
|
- **Everything else** -- multiple files, any flag present, or a name/path
|
||||||
|
with no relation to any hd-managed folder -- goes straight to the real
|
||||||
|
patched `joe`, completely unmodified.
|
||||||
|
|
||||||
|
The real compiled binary stays at `joe-patch/build/joe-4.8/joe/joe` inside
|
||||||
|
the checkout; the wrapper execs it directly for the "everything else" case
|
||||||
|
rather than copying it elsewhere. `hd-joe` itself also always launches the
|
||||||
|
real binary directly (not through this wrapper), so there's no risk of the
|
||||||
|
two looping into each other.
|
||||||
|
|
||||||
|
## What works, and how well it's been tested
|
||||||
|
|
||||||
|
**Verified against a real HedgeDoc server:** editing a note from JOE with
|
||||||
|
live two-way sync. Specifically the edge cases that were broken and got
|
||||||
|
fixed -- inserting at the very start and very end of a document, continuous
|
||||||
|
fast typing, and cursor placement after an AI integration rewrites a block.
|
||||||
|
|
||||||
|
**Only tested against fake servers:** everything else -- all of `hd-cli`,
|
||||||
|
and `hd-joe <name>`'s folder discovery and note creation via `POST /new`.
|
||||||
|
|
||||||
|
That distinction matters more than it might sound. Three separate bugs in
|
||||||
|
this project reached the user because a hand-written fake server was more
|
||||||
|
forgiving than the real one -- it acked every operation instantly, had no
|
||||||
|
database-flush lag, and never broadcast to other clients. Each was found
|
||||||
|
and patched only after reality disagreed, never by inspection. Expect the
|
||||||
|
untested paths to break somewhere, most likely around login, `POST /new`,
|
||||||
|
or the tag format in notes that already exist. If you have a real instance
|
||||||
|
to point at, run the full test flow (linked from the changelogs) against
|
||||||
|
it before trusting any of this with notes you care about.
|
||||||
|
|
||||||
|
## Testing everything
|
||||||
|
|
||||||
|
./build.sh
|
||||||
|
|
||||||
|
cd hd-cli
|
||||||
|
for f in test_*.py; do python3 "$f"; done
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
cd hd-joe
|
||||||
|
export JOE_BIN="$PWD/../joe-patch/build/joe-4.8/joe/joe"
|
||||||
|
for f in test_*.py e2e_test.py ai_replace_test.py cursor_after_ai_test.py; do
|
||||||
|
python3 "$f"
|
||||||
|
done
|
||||||
|
cd ..
|
||||||
|
|
||||||
|
Each package's own README documents its tests individually, including
|
||||||
|
which ones need `JOE_BIN` set.
|
||||||
|
|
||||||
|
## Architecture, briefly
|
||||||
|
|
||||||
|
JOE (patched C) <--Unix socket--> hd_joe_agent.py <--Socket.IO/OT--> HedgeDoc
|
||||||
|
|
|
||||||
|
hd_core.py <--HTTP--> HedgeDoc (discovery, /new, tags)
|
||||||
|
|
|
||||||
|
hdc (CLI) <--> ~/notes/<tag>/
|
||||||
|
|
||||||
|
JOE owns the buffer and all normal editing; the patch only adds hooks
|
||||||
|
reporting local edits out and a poll applying remote ones in. The Python
|
||||||
|
agent owns the OT state machine: pending operations, transforms,
|
||||||
|
acknowledgements. `hd_core.py`, shared by both entry points, owns
|
||||||
|
everything that isn't live editing: folder discovery, note creation,
|
||||||
|
reconciliation, tag writing.
|
||||||
|
|
||||||
|
Design decisions and the reasoning behind them are in the manual (linked
|
||||||
|
from the changelogs); the changelogs themselves document each bug found,
|
||||||
|
what caused it, and how it was proven fixed -- including the ones found in
|
||||||
|
this repo's own test scaffolding, not just in the product code.
|
||||||
Reference in New Issue
Block a user