This guide gives future agents a map of Hydra's runtime surfaces, code organization, and common workflows so fresh sessions can skip expensive rediscovery.
docs (browser UI) ⇆ service_router/router.py (Python orchestrator) ⇆ local services (ASR/TTS/LLM/MCP)
⇡ ⇣
NKN transport via Net module bridge-node/nkn_bridge.js (Node.js)
- The browser workspace toggles HTTP vs NKN for every request (
docs/js/main.js:144). - Python router supervises service processes, drives HTTP multiplexing, and owns relay state (
service_router/router.py:35). - Node bridge provides the raw NKN MultiClient connection used by the router's DM queue (
service_router/bridge-node/nkn_bridge.js:18).
| Path | Purpose | Highlights |
|---|---|---|
docs/ |
Front-end workspace + local HTTPS dev server | UI entrypoint (docs/index.html:5), SPA runtime (docs/js/main.js:1), TLS dev server (docs/server.py:53) |
docs/js/ |
Modular node graph runtime | Transport core (docs/js/net.js:8), graph layout (docs/js/graph.js:1), node wiring (docs/js/router.js:1) |
service_router/ |
Unified NKN router and config | Bootstrap & orchestration (service_router/router.py:35), config defaults (service_router/router_config.json:1) |
service_router/bridge-node/ |
Node-based NKN sidecar | MultiClient runner (service_router/bridge-node/nkn_bridge.js:18) |
- Self-bootstraps a private virtualenv and dependencies for resilience (
service_router/router.py:45). - Loads relay + endpoint targets from
router_config.jsonwith sensible localhost defaults (service_router/router.py:92). ServiceWatchdogclones and supervises external services—including Piper TTS, Whisper ASR, Ollama farm, and Hydra MCP—using a restart/backoff loop (service_router/router.py:327).- Automatically fetches service scripts into
.services/<name>/via git and tracks metadata (service_router/router.py:414). - Manages per-service HTTP worker pools, stream formatting, and QR helpers for presenting relay info through the terminal dashboard (
service_router/router.py:166).
- Accepts relay seed, identifier, and transport tuning via environment variables (
service_router/bridge-node/nkn_bridge.js:6). - Emits structured stdout events for ready status, probes, and DM payloads that the router consumes (
service_router/bridge-node/nkn_bridge.js:55). - Listens for JSON control messages on stdin to relay outbound DMs and enforces heartbeat-based self exits for hung connections (
service_router/bridge-node/nkn_bridge.js:73).
- Minimal HTML shell loads the node graph bundle, NKN SDK, and QR libraries (
docs/index.html:5). main.jswires together transport, graph rendering, node factories, and workspace synchronization in one place (docs/js/main.js:20).- Transport toggle button flips CFG state and reinitializes NKN clients as needed (
docs/js/main.js:144).
- Bootstraps a venv on first launch and installs
cryptographyautomatically (docs/server.py:53). - Generates self-signed certificates covering LAN/public IPs and optional SANs (
docs/server.py:162). - Supports Let’s Encrypt, Smallstep, and GCP Private CA options via CLI flags (
docs/server.py:100). - Serves
docs/config.json-defined roots and prints LAN/public URLs for quick device pairing (docs/server.py:148).
- Configuration & Storage:
CFGis persisted tolocalStorageand seeded with transport + wiring defaults (docs/js/config.js:9). UsesaveCFGto persist edits. - Transport Layer:
Netabstracts HTTP vs NKN for JSON, blob, and streaming requests, caching NKN seeds in storage and maintaining pending requests (docs/js/net.js:25). - Wire Router: User-created connections live in
CFG.wires;Routerhandles port registration, wiring UI, and payload fan-out (docs/js/router.js:23). - Graph Engine:
createGraphowns workspace canvas transforms, node lifecycle, link drawing, and relay state badges (docs/js/graph.js:18). - Node Registry:
NodeStorepersists per-node configuration and provides typed defaults for every node category (docs/js/nodeStore.js:9). - Workspace Sync: Generates QR codes, attaches modal listeners, and drives NKN workspace sharing flow (
docs/js/workspaceSync.js:35). - Utilities: Common helpers for logging, QR conversion, boolean toggles, and ASR prompt sanitization (
docs/js/utils.js:1). - Transport Toggle UI:
makeTransportButtonUpdaterrenders the status pill based on current transport state (docs/js/transport.js:3). - QR Scanner: Camera capture + jsQR integration for filling inputs from codes (
docs/js/qrScanner.js:21). - Sentence & Streaming Helpers: Handles NDJSON/Server-Sent Events and sentence stabilization for LLM streams (
docs/js/sentence.js:11). - Flows Library: Modal-based flow manager for saving, importing, editing, and loading named workspaces (
docs/js/flows.js:1).
| Node | Responsibilities | Source |
|---|---|---|
| LLM | Model discovery, NDJSON streaming, image/tool payload prep, relay state updates | docs/js/llm.js:11 |
| ASR | Model metadata, Web Audio capture, chunked uploads, sign-off filtering | docs/js/asr.js:20 |
| TTS | Model caching, audio queue, oscilloscope visualization | docs/js/tts.js:20 |
| NKN DM | Handshake state machine, inbox tracking, invite modal control | docs/js/nknDm.js:3 |
| MCP | Handles MCP connection lifecycle, resource/tool syncing, status rendering | docs/js/mcp.js:52 |
| Media Stream | Screenshots + audio capture, base64 packaging, remote playback | docs/js/mediaNode.js:24 |
| Orientation | Device orientation permissions, throttling, quaternion conversion | docs/js/orientation.js:20 |
| Location | Geolocation watch, geohash/latlon formatting, payload throttling | docs/js/location.js:76 |
Defaults (base URLs, auth slots, feature toggles) are centralized in NodeStore.defaultsByType for quick inspection (docs/js/nodeStore.js:9). When adding a new node type, mirror this pattern so NodeStore.ensure remains authoritative (docs/js/nodeStore.js:41).
- QR modal exposes current workspace state as a signed payload;
workspaceSyncensures QR dependencies are loaded before rendering (docs/js/workspaceSync.js:80). - Incoming
?sync=URLs are stripped and stored while forcing NKN transport to connect to the sender (docs/js/workspaceSync.js:134). - NKN messages fan through
Net.nknlisteners, so ensure the transport toggle is in sync before expecting share invitations (docs/js/net.js:119).
- Relay seeds, names, and service assignments are in
router_config.json:1. Rotateseed_hexvalues withgenerate_seed_hex()(service_router/router.py:122). - Targets map human names to local service URLs (
router_config.json:3). Update these to point at remote nodes if services move. - Bridge tuning (subclients, heartbeats) uses the
bridgesection; defaults matchnkn_bridge.jsexpectations (router_config.json:19).
python3 docs/server.py --cert-mode self
- First run builds
docs/venvand emits LAN/public URLs. Adjust SANs viadocs/config.json:1before launch.
python3 service_router/router.py --config router_config.json
- Spawns bridge sidecars + service watchdog; watch terminal for QR output and service status.
- Ensure required repos are reachable—
ServiceWatchdog.ensure_sources()needs git and network access (service_router/router.py:340).
(cd service_router/bridge-node && npm install)
package.jsonpinsnkn-sdk; reinstall if Node modules were pruned.
- Use the
Flowsbutton in the toolbar to open the modal library. - Save the current canvas, import/export JSON snapshots, or load flows back into the editor within the same modal (
docs/js/flows.js).
- NKN badge stays red: Confirm CDN
nkn.min.jsloads (browser console) and reinitialize transport via toggle (docs/js/main.js:147). - Workspace QR fails: Verify
QRCode.toCanvasis available;ensureQrReady()waits for CDN script but logs errors if missing (docs/js/workspaceSync.js:97). - Service won’t start: Inspect
.logs/<service>.logcreated byServiceWatchdogand checkstate.last_errorsnapshots (service_router/router.py:384). - Ollama health fallback: Router auto-frees ports and retries before falling back to “system” mode (
service_router/router.py:438). - Audio underruns: TTS node increments
underrunson empty buffers; adjust stream chunk sizes or model latency (docs/js/tts.js:128).
- CDN: NKN SDK 1.3.6, jsQR 1.4.0, QRCode 1.5.4 (
docs/index.html:13). - Python: requests, python-dotenv, qrcode (auto-installed) (
service_router/router.py:61). - Node: nkn-sdk (bridge) (
service_router/bridge-node/package.json).
- Maintain ASCII-friendly UI assets and avoid heavy dependencies to keep front-end lightweight.
- New nodes should expose ports via
Router.registerand persist configuration throughNodeStoreto participate in exports/imports (docs/js/router.js:23). - For additional backend services, extend
ServiceWatchdog.DEFINITIONSand map aliases inSERVICE_TARGETSto keep router lookups consistent (service_router/router.py:100).
Keep this guide updated when new node types, transports, or services land so future agents can onboard instantly.