Architecture

Architecture

00 // INDEX

IN THIS SECTION

Aphrodite works on one thing: the output a tool call appends to the model's context. Every section documents a part of that work.

Architecture

IN THIS DOCUMENT

Crimson marks the heading currently in view; every entry is one of the document's own headings.

Flow traces of every runtime path in Aphrodite:

  • the CCR compression proxy with its dual loopback listeners
  • the Hermes plugin (Python shim → C-ABI dylib → shared core crate)
  • the CI/release pipeline
  • and the data model underneath.

Two runtime worlds run in separate processes with separate state: the proxy binary (HTTP response compression) and the Hermes plugin (hook-level interception).

The plugin is a pure loader - directives are embedded in the binary and materialized into ~/.hermes/aphrodite/directives/ at startup, and the dylib/binary live in the canonical runtime home ~/.hermes/aphrodite/binaries/ with layout self-heal.

#FileWhat it traces
0101-startup.mdProcess startup: config resolution, bind-before-spawn of the :9797 cache / :9798 token listeners, CCR store init, config reload watcher, and plugin register() (dylib probe/load, layout self-heal, directives materialize, proxy launch).
0202-chat-compression.mdCore value path: chat response → classify → EMA-tuned threshold → BLAKE3 → store → <<<CCR:...>>> marker + preview; the tool_calls-not-compressed branch; proxy vs FFI pipeline separation.
0303-retrieve.md/retrieve (inline → backend, filter, pagination, byte-exact round-trip) plus the recursive resolver resolve::expand (nested markers, depth limit, cycle-safe, no write-back).
0404-hook-ffi.mdHermes → Python ctypes → C-ABI → core hooks; FFI declarations via the generated _bindings.py; the pre_llm_call → flow::build_turn_context choke point.
0505-ccr-lifecycle.mdState machine of a CCR entry (created → stored → previewed → {retrieved / decayed / evicted / expired} → GC) plus the EMA threshold state.
0606-sse-streaming.mdtext/event-stream detection → timeout-free client → chunk passthrough (no compression, no cache) → mid-stream byte/error accounting.
0707-config-resolution.mdenv > TOML > default precedence across the proxy and FFI config loaders; live vs inert/reserved keys; config reload scope.
0808-dylib-loading.mdLoad-once-per-process contract: candidate resolution → presence-only _ensure_binaries (no downloads) → subprocess probe → direct CDLL; restart to pick up a new build.
0909-release-ci.mdTag push → Build.yml (release-once → 4-target matrix → Finalize) + Publish.yml (Test + packaging guard → crates.io chain; aphrodite/aphrodite-hermes publish on tag, headroom-core dispatch-only).
1010-component.mdTop-level component diagram: crates + Python shim + proxies + store backends + Hermes host + canonical runtime home, with the C-ABI and HTTP boundaries labeled.
1111-data-model.mdClass diagram: AphroditeState, AppState, MarkerEntry, ToolEvent, SplitEvent, CcrStore trait + backends, directives.

Cross-cutting notes

  • The HTTP proxy path and the Hermes FFI path are two separate compression pipelines. The proxy classifies via proxy_detect_content_type and builds previews via proxy_build_preview; the staged transform pipeline (transforms::detect, stage2, struct_extract) runs only on the hook path. They share the BLAKE3 compute_key and the marker wire format, but nothing else.
  • Two marker layouts exist for the same <<<CCR:hash|type|size>>> token: the FFI path renders the marker line first, the proxy path renders it last.
  • flow::build_turn_context is the single directive choke point that all pre_llm_call entry points converge on, so directive injection cannot fork between paths.
  • The proxy and the plugin run in separate processes: each carries its own AppState / AphroditeState, its own inline store, and its own CCR backend - the dylib is loaded once per process, so a session restart starts a fresh plugin-side store.