Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

docs(architecture): document the crate layering chain

Steven Enamakelb92677f10684
diff --git a/gitbooks/developing/architecture.md b/gitbooks/developing/architecture.md
index 8499111341..daf03c1faa 100644
--- a/gitbooks/developing/architecture.md
+++ b/gitbooks/developing/architecture.md
@@ -16,20 +16,61 @@ OpenHuman is a cross-platform communication and automation platform: a Rust core
| Path | Contents |
| --------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **`app/`** | pnpm workspace **`openhuman-app`**: Vite/React UI (`app/src/`), Vitest and WDIO tests. The Tauri shell itself is the Rust crate `crates/openhuman-app/` (below). |
-| **`crates/openhuman-app/`** | Thin Tauri v2 desktop host (Cargo package `openhuman-app`). Built from its own manifest and lockfile, excluded from the root workspace; hosts the core as an in-process tokio task (`src/core_process.rs`). |
+| **`crates/openhuman-app/`** | Thin Tauri v2 desktop host (Cargo package `openhuman-app`). Built from its own manifest and lockfile, excluded from the root workspace; depends on `openhuman-rpc` only and hosts the core as an in-process tokio task (`src/core_process.rs`, `openhuman_rpc::host::desktop`). |
| **`crates/openhuman-core/`** | Cargo package **`openhuman`**: library **`openhuman_core`**, with no `tinyhumans-sdk` dependency — the hosted backend is reached through the `backend::transport::BackendTransport` port, except hosted memory, which `vendor/tinymemory`'s own HTTP client calls (see `memory/engine.rs`). Flat domain modules directly under `src/` (`agent`, `backend`, `channels`, `config`, `cron`, `desktop`, `flows`, `hooks`, `hosting`, `inference`, `integrations`, `mcp`, `media`, `memory`, `modules`, `platform`, `runtime`, `sandbox`, `search`, `security`, `skills`, `threads`, `tools`, `util`, `voice`, `web3`, `web_chat`, …). `src/core/` holds the CLI (`cli.rs`), dispatch, controller registry (`all.rs`), event bus (`bus.rs`), `runtime/` (`CoreBuilder`/`CoreRuntime`) and `subsystem/`. There is no `src/rpc/` or `src/embed/` inside this crate any more. |
| **`crates/openhuman-rpc/`** | Shared JSON-RPC contracts: `RpcOutcome`, `unwrap_rpc`, `apply_log_envelope`, `StructuredRpcError`. The `http-client` feature (default on; off for root-workspace consumers) adds `post_json_rpc`, `bearer_header`, `redact_url_for_log`, `HttpRpcResponse`. Used by the Tauri shell (`core_rpc.rs` → `relay_http_rpc`) and the TUI (envelope decoding). The core does **not** depend on this crate and does not re-export it: the controller contract (`Outcome`, `ControllerSchema`, `StructuredRpcError`, params rules, in-process dispatch) lives in `crates/openhuman-core/src/core/`, and this crate sits above it. Behind `server` it also owns the `http_host` static-directory file server and registers its controllers as a core extension. |
-| **`crates/openhuman-embed/`** | Typed library facade (`openhuman_embed::{Harness, Core, CoreBuilder, DomainSet, ServiceSet, HostKind}`) for embedding the core in another product; forwards the core's feature gates. Installs no backend transport itself. |
+| **`crates/openhuman-embed/`** | Typed library facade (`Runtime`/`RuntimeBuilder` → `Agent`, host presets, `embed::process`, and the `config` / `artifacts` / `chat_surface` / `modules` facades) for embedding the core in another product; forwards the core's feature gates. Installs no backend transport itself. |
| **`crates/openhuman-tinyhumans/`** | The TinyHumans layer above embed: `SdkBackendTransport` (the only crate that depends on the vendored `tinyhumans-sdk`), `install()` for hosts that boot the core themselves, a `RuntimeBuilder` that boots an embed runtime connected, the hosted RPC proxies (`hosted/`, all on the SDK's typed clients through one `hosted::client::HostedClient`: billing, team and usage, referral, announcements, webhook tunnels, managed Telegram/Discord linking, and backend-brokered OAuth — registered into the core's controller registry as an extension, some sharing the core's `auth` / `channels` / `webhooks` namespaces), and the host-side login/session owner (`session/`). A user without a TinyHumans account gets the core's `BACKEND_UNAVAILABLE:` sentinel from these without a request. |
-| **`crates/openhuman-cli/`** | The `openhuman-core` binary (installs the tinyhumans transport, then `run_core_from_args`), the developer/benchmark bins, and every root `tests/*.rs` / `examples/*.rs` target. |
-| **`crates/openhuman-tui/`** | Standalone ratatui terminal frontend. Boots the core in-process via `CoreBuilder` (`DomainSet::full()`, `ServiceSet::none()`), no HTTP. |
+| **`crates/openhuman-cli/`** | The `openhuman-core` binary (`openhuman_rpc::host::cli`), the ops bins, and every root `tests/*.rs` / `examples/*.rs` target (which reach the core through dev-dependencies). |
+| **`crates/openhuman-tui/`** | Standalone ratatui terminal frontend. Boots the core in-process via `openhuman_rpc::host::tui` (every domain, no background services), no HTTP. |
| **`Cargo.toml`** (root) | Virtual workspace for `openhuman-core`, `openhuman-embed`, `openhuman-rpc`, `openhuman-tinyhumans`, `openhuman-cli`, and `openhuman-tui` (`cargo build -p openhuman-cli --bin openhuman-core` builds the standalone CLI/server); `vendor/`, `worktrees/`, `crates/openhuman-app`, `app/src-tauri-mobile`, and `packages/tauri-plugin-ptt` are excluded. Holds the `[patch]` tables for vendored crates. There is no sidecar: the desktop bundle links the core in-process (`app/package.json` `core:stage` is a documented no-op). |
| **`crates/openhuman-core/src/skills/`** | Skill metadata and run orchestration (`ops_create`, `ops_discover`, `ops_install`, `ops_parse`, `catalog/`, `registry`, `runtime/`, `schemas/`, `types`, `bundled/`, `webhooks/`). The legacy QuickJS / `rquickjs` skill execution runtime was removed; skills contribute metadata + tool descriptors that get injected into agent prompts, while tool execution flows through native Rust handlers and Node-backed helpers via `runtime::node` (Cargo feature `runtime-node`). |
| **`gitbooks/`** | This book (public product and contributor documentation). |
| **`docs/`** | Internal maintainer documentation (test-coverage matrix, release smoke checklist, library benchmarking notes). |
| **`vendor/`** | Recursive git submodules for the `tiny*` crate family (`tinyagents`, `tinyflows`, `tinychannels`, `tinyjuice`, `tinymemory`, `tinymcp`, `tinybus`, `tinybox`, `tinycomputer`, `tinyruntime`, `tinydocs`, `tinysearch`, `tinyskills`, `tinyvoice`, `tinywallet`, `tinyhosts`, `tinyconnectors`, `tinyhumans-sdk`) plus `motosan-ai-oauth`. |
-The desktop app **WebView** loads the UI from `app/`; RPC, agents and skills run in the **`openhuman_core`** core, hosted in-process as a tokio task by the Tauri shell (`crates/openhuman-app/src/core_process.rs`, `run_server_embedded_with_ready`) and reachable over loopback HTTP. The renderer's `coreRpcClient` `fetch()`es `http://127.0.0.1:<port>/rpc` directly; the `relay_http_rpc` Tauri command (backed by `openhuman_rpc::post_json_rpc`) is only the fallback for non-loopback plain-`http://` runtimes that the webview would block as mixed content. The standalone `openhuman-core serve` binary is the CLI/debug path.
+The desktop app **WebView** loads the UI from `app/`; RPC, agents and skills run in the **`openhuman_core`** core, hosted in-process as a tokio task by the Tauri shell (`crates/openhuman-app/src/core_process.rs`, `openhuman_rpc::host::desktop`) and reachable over loopback HTTP. The renderer's `coreRpcClient` `fetch()`es `http://127.0.0.1:<port>/rpc` directly; the `relay_http_rpc` Tauri command (backed by `openhuman_rpc::post_json_rpc`) is only the fallback for non-loopback plain-`http://` runtimes that the webview would block as mixed content. The standalone `openhuman-core serve` binary is the CLI/debug path.
+
+### Crate layering
+
+The Rust crates form a strict chain. Each crate's normal dependencies name only
+the layer directly below it, and the three hosts name `openhuman-rpc` alone:
+
+```text
+ openhuman-app openhuman-cli openhuman-tui
+ (desktop shell) (openhuman-core) (terminal UI)
+ \ | /
+ +-------------------+-------------------+
+ |
+ v
+ openhuman-rpc host::{desktop, cli, tui},
+ | JSON-RPC server + client,
+ | session store
+ v
+ openhuman-tinyhumans SDK transport, hosted
+ | proxies, session owner
+ v
+ openhuman-embed Runtime/RuntimeBuilder,
+ | process helpers, facades
+ v
+ openhuman-core domains, registry, ports
+```
+
+- **Hosts boot through `openhuman_rpc::host`.** `host::desktop` is the shell's
+ embedded server, `host::cli` the `openhuman-core` binary (and the shell's
+ `core` / `mcp` subcommands), `host::tui` the terminal UI's runtime. Each one
+ connects the TinyHumans layer and builds an embed `Runtime`; there is one per
+ process.
+- **Hosts reach the core only through the curated facade** rpc re-exports
+ (`openhuman_rpc::embed`, `openhuman_rpc::tinyhumans`). The layers above embed
+ use embed's doc-hidden `__host` list for the server and transport internals;
+ hosts never do.
+- **Enforced in CI.** `scripts/ci/check-crate-chain.mjs` (part of
+ `pnpm rust:layout`) fails on any other normal-dependency edge and on a host
+ `src/` naming `__host`, `core_host` or `openhuman_core::`.
+ `scripts/ci/check-feature-forwarding.mjs` checks that every gate travels the
+ same chain. Dev-dependencies are exempt, so the root tests still reach into
+ the core.
---
diff --git a/gitbooks/developing/architecture/tauri-shell.md b/gitbooks/developing/architecture/tauri-shell.md
index f0f9f52cc2..ce1c1368c2 100644
--- a/gitbooks/developing/architecture/tauri-shell.md
+++ b/gitbooks/developing/architecture/tauri-shell.md
@@ -9,6 +9,44 @@ icon: desktop
`crates/openhuman-app/` is the desktop host for OpenHuman: Tauri v2 and WebView, IPC commands, window management, and the bridge to the embedded `openhuman-core` Rust runtime over core JSON-RPC. It does **not** duplicate the full domain stack; that lives in `crates/openhuman-core` (library `openhuman_core`; the `openhuman-core` binary is `crates/openhuman-cli/src/main.rs`).
+### Where the shell sits
+
+The shell is one of three hosts on top of a strict crate chain, and
+`openhuman-rpc` is the only OpenHuman crate in its `Cargo.toml`:
+
+```text
+ openhuman-app (this crate)
+ | [dependencies] openhuman-rpc (http-client, server, jev + the product gates)
+ v
+ openhuman-rpc ----------> host::desktop / host::cli, server, client
+ | re-exports `embed` and `tinyhumans`
+ v
+ openhuman-tinyhumans ---> SDK transport, session owner (`session/` uses it)
+ |
+ v
+ openhuman-embed --------> Runtime, process helpers (tokio runtime, logging,
+ | Sentry options), config/artifacts/modules facades
+ v
+ openhuman-core
+```
+
+| Shell code | Goes through |
+| --- | --- |
+| Embedded server (`core_process.rs`) | `openhuman_rpc::host::desktop(DesktopOptions { port, rpc_token, .. }, shutdown, ready_tx)` |
+| `OpenHuman core …` / `mcp` subcommands (`lib.rs::run_core_from_args`) | `openhuman_rpc::host::cli(args)` |
+| Tauri async runtime sizing (`lib.rs::run`) | `openhuman_rpc::embed::process::tokio_runtime()` |
+| Sentry client (`lib.rs::run`) | `openhuman_rpc::embed::process::sentry::client_options` (the shared `before_send` chain; fallback user id from `session::peek_user_id`) |
+| File logging (`file_logging.rs`), data reset log handle | `openhuman_rpc::embed::process::{init_for_embedded, log_directory, shutdown_file_guard}` |
+| Config / workspace paths, artifacts, bundled modules | `openhuman_rpc::embed::{config, artifacts, modules}` |
+| Session owner (`session/`) | `openhuman_rpc::tinyhumans` |
+| Compile-time asserts | `openhuman_rpc::embed::{VOICE_COMPILED_IN, HTTP_SERVER_COMPILED_IN}` |
+
+`scripts/ci/check-crate-chain.mjs` fails if the shell's manifest names
+another OpenHuman crate or its `src/` names `__host`, `core_host` or
+`openhuman_core::`. One embed runtime exists per process: when the shell
+restarts its embedded server, `CoreProcessHandle` waits for the old task (and
+the runtime it owns) to drop before it spawns the next one.
+
## Responsibilities
1. **Web UI**. Load the Vite build from `app/dist` (or dev server on port 1420).
@@ -90,7 +128,7 @@ React (fetch)
The renderer talks to the local core **directly over HTTP**: `app/src/services/coreRpcClient.ts` invokes `core_rpc_url` / `core_rpc_token` once, then issues plain `fetch()` calls. The `relay_http_rpc` Tauri command is a host-side fallback used only when the RPC URL is **not** a trustworthy origin for the secure `tauri://localhost` webview (e.g. a self-hosted runtime on a LAN IP, blocked as mixed content, #3865). In that case the Rust host delegates to `openhuman_rpc::post_json_rpc` from the shared `crates/openhuman-rpc` crate (feature `http-client`): 30 s timeout, redirects disabled when a bearer is present, status + body mirrored back verbatim as `HttpRpcResponse`. The shell adds only the gateway transport guard (`validate_remote_transport`, feature `gateways`) before delegating.
-`CoreProcessHandle` in `core_process.rs` owns the embedded server task (started via `openhuman_rpc::server::run_server_embedded_with_ready` with a per-launch random bearer token) and handles stale-listener/port-conflict recovery.
+`CoreProcessHandle` in `core_process.rs` owns the embedded server task (started via `openhuman_rpc::host::desktop` with a per-launch random bearer token) and handles stale-listener/port-conflict recovery.
### Window and tray behavior
@@ -166,8 +204,8 @@ install's data, and *this* machine's audio, so routing them to a remote gateway
wrong rather than incomplete.
Gated by the shell-local `gateways` Cargo feature (default on). That gate is unrelated to
-the feature-forwarding rules in `AGENTS.md`, which govern which `openhuman_core` gates the
-shell forwards; nothing here belongs in `scripts/ci/product-features.txt`.
+the feature-forwarding rules in `AGENTS.md`, which govern which core gates the shell
+forwards on its `openhuman-rpc` dependency; nothing here belongs in `scripts/ci/product-features.txt`.
Frontend: **`app/src/services/gatewayService.ts`**, surfaced in Settings → Core connection
(`components/settings/panels/core/GatewaySection.tsx`).
@@ -308,7 +346,7 @@ The Tauri crate **does not** embed a duplicate Socket.io server or Telegram clie
### `CoreProcessHandle` (`core_process.rs`)
-- Runs the core's HTTP/JSON-RPC server as a **tokio task inside the Tauri host** via `openhuman_rpc::server::run_server_embedded_with_ready`: no sidecar binary.
+- Runs the core's HTTP/JSON-RPC server as a **tokio task inside the Tauri host** via `openhuman_rpc::host::desktop`: no sidecar binary. The runtime the task builds is dropped when the task ends; `shutdown` and the startup-timeout abort wait for that before a respawn, because a process holds one embed runtime at a time.
- Generates a per-launch 256-bit hex bearer token (`generate_rpc_token`) and hands it to the embedded server; the renderer reads it via the `core_rpc_token` command.
- Stale-listener policy (#1130): if the core port is already occupied, probes whether the listener is an old OpenHuman core (terminate + respawn) or something foreign (surface the conflict). `OPENHUMAN_CORE_REUSE_EXISTING=1` opts back into attach-to-existing for debugging.
- Managed as Tauri state in `lib.rs` (`app.manage(core_handle)`).