# hd_common Code shared between `../hd-cli/` and `../hd-joe/`. Not a package in its own right -- both entry points (`hd-cli/hdc`, `hd-joe/hd_joe_agent.py`) add this directory to `sys.path` at startup based on their own file location, so it works regardless of current directory or how you invoke them. Test files in both packages do the same. If you add a new entry point or test file here, copy that same bootstrap rather than assuming cwd: ```python sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "hd_common")) ``` ## Files | File | | | --- | --- | | `hd_client.py` | The OT engine: Socket.IO client, operation builders (`insert_operation`/`replace_operation`/`append_operation`, all careful to never emit a literal `0` component -- real HedgeDoc's `TextOperation.fromJSON` rejects those), transform, the pending-operation queue and its drain-before-exit logic. | | `hd_core.py` | Everything else: `.hd/` config and cookie storage, `/history`-based discovery, reconciliation (symlinks <-> tags), problem detection, tag writing (`write_tags`, frontmatter parsing matched exactly to HedgeDoc's `splitFrontmatter`), and hd-joe's folder-discovery/create-or-open logic (`find_hd_root`, `tag_from_cwd`, `create_note`, `resolve_or_create_note`). | ## Why this folder exists Until 0.7.19, both packages shipped their own copy of these two files. They drifted once already (0.7.18's consistency pass found hd-cli's copy missing the hd-joe integration functions hd-joe's copy already had) -- silently, since nothing checked. One copy in one place removes the possibility. ## Tests No tests live here directly -- both packages' test suites already cover this module thoroughly (hd-cli: `test_hd_core.py`, `test_hd_tags.py`, `test_hd_problems.py`, `test_hd_write.py`; hd-joe: `test_hd_create.py`, plus the pty-driven ones exercising `hd_client.py` against real JOE). Changing something here means running both packages' suites, not just one -- `../build.sh && ../install.sh` followed by the test commands in each package's own README, or see the top-level README's test-everything section.