The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
docs(readme): add module documentation for core, backend, embed, and session
Steven Enamakel27954d4764e3
diff --git a/crates/openhuman-app/src/session/README.md b/crates/openhuman-app/src/session/README.mdnew file mode 100644index 0000000000..30f1f6843a--- /dev/null+++ b/crates/openhuman-app/src/session/README.md@@ -0,0 +1,93 @@+# session++The desktop shell's login glue. Login-token exchange, `GET /auth/me`, the+current-user cache and the credential handoff are implemented in+`crates/openhuman-tinyhumans` (`SessionManager`). This module gives that+manager a link to the core, exposes it to the renderer as Tauri commands, and+forwards its change events to the renderer as Tauri events.++## How it works++The core only holds a credential. It receives one through the+`auth.set_credential` RPC and never talks to the backend's auth endpoints.+Everything that does talk to them runs here, in the shell process.++```text+renderer session (shell) core+-------- --------------- ----+auth_login_with_token -> SessionHost.manager+ | POST /auth/login-token/consume (backend)+ | GET /auth/me (backend)+ | HttpCoreLink.invoke ----------> auth.set_credential+ v+ SessionEvent::Changed+ <- "auth://changed" ---- event forwarder task+ <- "auth://expired" ---- SessionEvent::Expired { source }+```++`install` runs during Tauri `setup()`, right after the `CoreProcessHandle` is+created. It builds a `SessionHost`, subscribes to the manager's broadcast+channel, registers the host as managed state, and spawns a task that emits+`auth://changed` (payload: `openhuman_tinyhumans::SessionState`) and+`auth://expired` (payload: `{ source }`) to the renderer.++The manager's backend requests carry `ClientHeaders` built from the product+identity, with `CARGO_PKG_VERSION` as both the core and Tauri version, since+the shell and core ship as one release.++`HttpCoreLink` implements `openhuman_tinyhumans::CoreLink` over the same path+the renderer uses. On every call it resolves `(url, token)` through+`crate::active_rpc_endpoint`, so a gateway switch or core restart is picked up+without rewiring. It builds the body with `openhuman_rpc::request_body`, sends+it with `core_rpc::post_json_rpc` (which refuses a bearer over plain HTTP off+loopback), and decodes with `openhuman_rpc::decode_response`.++## Layout++| File | What it does |+| --- | --- |+| `mod.rs` | `SessionHost`, `install`, the event names, and `peek_user_id`. |+| `link.rs` | `HttpCoreLink`, the `CoreLink` over the shell's RPC path. |+| `commands.rs` | The `auth_*` Tauri commands, each a one-line delegate to the manager. |++## Tauri commands++| Command | Behavior |+| --- | --- |+| `auth_login_with_token(token)` | Exchanges a one-time login token for a session JWT, validates it, installs it in the core. |+| `auth_store_session(token, user?)` | Installs a JWT (validated against the backend first) or the offline local token the renderer already holds. |+| `auth_logout()` | Clears the credential in the core. |+| `auth_state()` | The core's credential state plus the cached user. |+| `auth_current_user(force?)` | The `/auth/me` user, from cache unless `force` is true. |++All return `Result<_, String>`. The error string is+`openhuman_tinyhumans::SessionError`'s display text, which starts with a+stable `PREFIX:` so the frontend can classify it without parsing prose.++## Key types and entry points++- `SessionHost` (`mod.rs`) is managed Tauri state holding+ `Arc<SessionManager<HttpCoreLink>>`.+- `install(app, desktop)` (`mod.rs`) is called once from `lib.rs`.+- `peek_user_id()` (`mod.rs`) returns the signed-in user id synchronously; the+ Sentry `before_send` hook in `lib.rs` uses it to tag events.+- `AUTH_CHANGED_EVENT` and `AUTH_EXPIRED_EVENT` (`mod.rs`) are the event names.++## Boundaries++- Auth endpoints, token validation, caching and identity live in+ `crates/openhuman-tinyhumans` (`openhuman_tinyhumans::session`). Changes to+ login behavior belong there.+- Credential storage and what the core does with a credential (user-dir+ activation, gated services) belong to the core+ (`security::credentials`).+- `get_active_user_id` is a separate command in `lib.rs`, not part of this+ module.++## Tests++`commands_tests.rs` covers the command delegates.++```bash+cargo test --manifest-path crates/openhuman-app/Cargo.toml session::+```diff --git a/crates/openhuman-core/src/backend/README.md b/crates/openhuman-core/src/backend/README.mdindex 90afde10ba..c388504edf 100644--- a/crates/openhuman-core/src/backend/README.md+++ b/crates/openhuman-core/src/backend/README.md@@ -22,7 +22,7 @@ round trip with the SDK's route policy.```textdomain code (channels, voice, memory billing, ...)- | BackendClient::from_config(&config)?.authed_json(cred, method, path, body)+ | BackendClient::from_config(&cfg)?.authed_json(cred, method, path, body)vBackendClient backend/client.rs| endpoint checks (HTTPS or loopback; API key only to managed host)diff --git a/crates/openhuman-core/src/core/README.md b/crates/openhuman-core/src/core/README.mdindex 36c8858f01..43f7dd39c2 100644--- a/crates/openhuman-core/src/core/README.md+++ b/crates/openhuman-core/src/core/README.md@@ -104,7 +104,7 @@ namespace commands, the device tunnel, and `CoreRuntime::invoke`.invoke_method(method, params)|+-- schema_for_rpc_method(method) (built-in, internal, extensions)- | found: params_to_object -> validate_params -> try_invoke_registered_rpc+ | found: params_to_object -> validate_params -> try_invoke_registered_rpc| | group disabled under DomainSet -> treated as unknown| | else run handler inside CoreContext::scope| vdiff --git a/crates/openhuman-embed/src/harness/README.md b/crates/openhuman-embed/src/harness/README.mdindex b48dd8d9f3..c9d6f7807e 100644--- a/crates/openhuman-embed/src/harness/README.md+++ b/crates/openhuman-embed/src/harness/README.md@@ -1,60 +1,176 @@# harness-`Harness`: the one-call front door over the library API in-`../runtime/` and `../agent/`. One `Runtime` plus exactly one `Agent` named-`harness`, built from a single set of inputs. See+`Harness` is the one-call front door over the library API: one `Runtime`+plus exactly one `Agent` with the id `harness`, built from a single set of+inputs. This folder also defines the input types that `Runtime` and+`AgentSpec` share with it: `Access`, `Provider`, `Workspace` and `McpServer`.+Reach for `Runtime` and `AgentSpec` directly once a host needs more than one+agent. See[`gitbooks/developing/embedding.md`](../../../../gitbooks/developing/embedding.md)-for the full walkthrough; reach for `Runtime` and `AgentSpec` directly once a-host needs more than one agent.--## Contents--- `mod.rs`: `Harness` itself (`run()`, `turn()`, `runtime()`, `agent()`,- `core()`, `workspace_dir()`, `action_dir()`) and `HarnessCore`, a- deliberately narrow facade over non-turn domains (config, auth) that- exposes neither the raw runtime nor the orchestrator agent, so nothing can- start a turn that skips the harness's provider route and access tier.-- `builder.rs`: `HarnessBuilder`: provider, workspace, access, `backend_url`- (for non-inference backend calls when the embedding product has its own- backend), and `session` (installing a backend identity when required).-- `access.rs`: `Access`: the tier a turn runs under (`readonly`, `full`,- `trust`).-- `provider.rs`: `Provider`: which model answers and where the request- goes, including `Provider::openai_compatible` for a caller-supplied- endpoint and `Provider::inherit` to run exactly as the installed app does.-- `workspace.rs`: `Workspace`: `Ephemeral`, `dir(path)`, or `Inherit` (the- operator's real `~/.openhuman` workspace and session).-- `mcp.rs` (`mcp` feature): `HttpHeader`, `McpAuthConfig`, `McpServer`.-- `skills.rs` (`skills` feature): skill bundle discovery and copying for a- harness-owned agent.-- `error.rs`: `HarnessError`.+for the walkthrough.++## How it works++`HarnessBuilder::build` is a thin composition over the other two layers:++```text+ HarnessBuilder+ |+ |- refuse skills_dir with Workspace::Inherit (before claiming the slot)+ |- pick domains: DomainSet::embedded(), plus mcp only if servers were+ | given and skills only if a skills_dir was given+ |+ |- RuntimeBuilder::new()+ | .workspace .host_kind .provider .access .domains+ | [.config .backend_url .services .tool_groups .session]+ | .build() -> Runtime+ |+ |- AgentSpec::new("harness")+ | .provider .access [.tools]+ | .action_dir(the workspace's own action/ dir, unless Inherit)+ | [skills copied into <workspace>/skills] [.mcp per server]+ | runtime.agent(spec) -> Agent+ v+ Harness { agent, runtime }+```++Every `Harness` method delegates. `run` and `turn` go to the agent,+`workspace_dir` and `core` go to the runtime, and `runtime()` and `agent()`+hand out the two halves so a host can add more agents with+`Runtime::agent`. On drop the agent is released first, then the runtime, so+the core and an ephemeral workspace are torn down with nothing still holding+them.++`Harness::core()` returns `HarnessCore`, a deliberately narrow facade with+only `config()` and `auth()`. It exposes neither the raw `CoreRuntime` nor+the orchestrator facade, because either could start a turn that skips the+agent's provider route and access tier. `Runtime::core()` returns the same+type.++## Layout++| File | What it does |+| --- | --- |+| `mod.rs` | `Harness` (`builder`, `run`, `turn`, `runtime`, `agent`, `core`, `workspace_dir`, `action_dir`) and `HarnessCore`. |+| `builder.rs` | `HarnessBuilder` and `HARNESS_AGENT_ID`. Inputs: `workspace`, `action_dir`, `provider`, `access`, `skills_dir`, `mcp`, `tools`, `services`, `domains`, `tool_groups`, `host_kind`, `backend_url`, `session`, `config`. |+| `access.rs` | `Access`: the autonomy tier and the turn origin, set together. |+| `provider.rs` | `Provider`: which model answers and where the request goes. |+| `workspace.rs` | `Workspace` and the crate-private `ResolvedWorkspace` that materializes directories. |+| `mcp.rs` | `McpServer`, `HttpHeader`, `McpAuthConfig` (`mcp` feature). |+| `skills.rs` | Copies skill bundles into a skills root (`skills` feature). |+| `error.rs` | `HarnessError`: `Workspace`, `Invalid`, `Build`, `Call`, `AlreadyRunning`. |++## The shared input types++`Access` closes a trap. Access is governed by two independent mechanisms:+the autonomy tier (`config.autonomy.level`) drives `SecurityPolicy`, and the+turn origin (a task-local `AgentTurnOrigin`) is what the fail-closed approval+gate reads. Setting only the tier produces an agent whose `shell`, `edit` and+`apply_patch` calls refuse while the model narrates around the refusals.+`Access` always carries both halves:++| Preset | Tier | Origin | Approval gate |+| --- | --- | --- | --- |+| `Access::readonly()` | `ReadOnly` | none | on |+| `Access::supervised()` (default) | `Supervised` | none | on |+| `Access::full()` | `Full` | `TrustedAutomation` (workflow, no approval) | off |++`trust(path, TrustedAccess)` adds a trusted root outside the action+directory (credential stores such as `~/.ssh` stay blocked whatever is+granted), `allow_tool_install(true)` permits the `install_tool` tool (off in+every preset), and `origin(..)` overrides the turn origin for a caller with a+narrower authority. `full()` does not set `auto_approve_all`; the origin is+the instrument the gate reasons about.++`Provider` is a per-turn route, never a config write. Writing+`inference_url` or `api_key` into the config would persist it and repoint the+operator's install, so `Provider::openai_compatible(base_url, key)` compiles+to the core's `EphemeralRoute`, a field that is never serialized. The route+pins the chat, reasoning, agentic and coding roles and leaves background+roles (memory, embeddings, learning) alone. Pass the API root+(`https://host/v1`); `/chat/completions` is appended. `Provider::model` is+advisory (an unknown model falls back to the default), and a route with no+model resolved registers nothing. `Provider::inherit()` uses whatever the+machine's configuration resolves to.++`Workspace` chooses where state lives:++| Variant | Meaning |+| --- | --- |+| `Ephemeral` (default) | A temp directory (`openhuman-harness-*`), removed when the last handle drops. |+| `Dir(path)` | A caller-owned directory, created if absent. `config.toml` and `action/` sit beside it. |+| `Stateless` | No durable state; requires `RuntimeBuilder::session_store`. A scratch temp dir (`openhuman-scratch-*`) holds process-local caches. |+| `Inherit` | The machine's own OpenHuman workspace, resolved by `Config::load_or_init`. |++For the runtime-owned variants `ResolvedWorkspace::resolve` lays out a+`workspace/` directory, a sibling `action/` directory and a sibling+`config.toml`. The sibling layout matters twice: the core refuses agent+writes beneath the workspace, and the credential store, auth profiles and+keyring file resolve against `config.toml`'s parent, which is what keeps an+ephemeral harness from touching `~/.openhuman`.++`McpServer::stdio(name, command, args)` and `McpServer::http(name, endpoint)`+compile to the same `McpServerConfig` a `[[mcp_client.servers]]` block parses+into, with `env`, `cwd`, `auth`, `allow_tools`, `deny_tools`, `timeout_secs`+and `description` refinements. The config is the registration API for the+core's static MCP registry, so servers are fixed when the agent is built.## Running on your own endpoint-A harness identifies as `HostKind::Library` by default, so supplying a-`Provider` is enough for inference: the library host is trusted to bring its-own endpoint and credentials, without an OpenHuman app login. Managed-TinyHumans inference needs the runtime's API key instead-(`RuntimeBuilder::api_key`); see-[`gitbooks/developing/tinyhumans-api-key.md`](../../../../gitbooks/developing/tinyhumans-api-key.md).-Neither path applies to `Provider::inherit` with `Workspace::Inherit`, which-runs exactly as the installed app does, session included.--## Two things the harness cannot do for you--- **The tokio runtime is the host's**, and its stack size matters: an agent- turn is a deep async state machine, delegation nests another one inside- it, and the default 2 MiB worker stack can overflow. Build it with- `AGENT_WORKER_STACK_BYTES` and `MAX_BLOCKING_THREADS`.-- **One runtime per process.** The keyring master key, the RPC bearer, the- event bus and the domain subscribers are all process-scoped. A harness- owns a runtime, so a second `HarnessBuilder::build` call in the same- process returns `HarnessError::AlreadyRunning`. Put more agents on the- existing runtime with `Runtime::agent` instead of building a second- harness.--## Where to look next--- [`../runtime/README.md`](../runtime/README.md) and- [`../agent/README.md`](../agent/README.md): the two types `Harness`- wraps.+A harness identifies as `HostKind::Library` by default, so a `Provider` is+enough for inference: the library host brings its own endpoint and+credentials, without an OpenHuman app login. Managed TinyHumans inference+needs the runtime's API key instead (`RuntimeBuilder::api_key`; see+[`gitbooks/developing/tinyhumans-api-key.md`](../../../../gitbooks/developing/tinyhumans-api-key.md)).+The core can still make non-inference backend calls; `backend_url` points+them at the embedding product's backend, and `session` installs a backend+identity when one is required.++Neither applies to `Provider::inherit()` with `Workspace::Inherit`, which+runs exactly as the installed app does, session included. In that case a+requested `HostKind::Library` is downgraded to `HostKind::Cli` unless the+host supplied a usable route or an API key, so borrowing an install does not+bypass its session gate.++## Boundaries++- The runtime and agent mechanics live in [`../runtime/`](../runtime/README.md)+ and [`../agent/`](../agent/README.md); this folder only composes them.+- Security enforcement (`SecurityPolicy`, the approval gate, path checks)+ is the core's (`openhuman_core::security`). `Access` only chooses inputs.+- MCP transport and the server registry belong to the core's MCP domain and+ `vendor/tinymcp`.++## Gotchas++- The tokio runtime is the host's, and the default 2 MiB worker stack+ overflows on a turn with a nested sub-agent. Build it with+ `AGENT_WORKER_STACK_BYTES` and `MAX_BLOCKING_THREADS`+ (`openhuman_core::core::runtime`).+- One runtime per process. A harness owns one, so a second+ `HarnessBuilder::build` returns `HarnessError::AlreadyRunning`. Add agents+ to the existing runtime instead.+- `skills_dir` with `Workspace::Inherit` is refused with+ `HarnessError::Invalid`: the harness copies into `<workspace>/skills`,+ which there is the operator's own. `AgentSpec::skills_dir` copies into the+ agent's own `agents/<id>/skills/` and has no such restriction.+- Skill bundles are copied, not linked. Discovery skips symlinked bundles+ and symlinked manifests as a security control, so a link would leave the+ skills silently absent. A bundle is a directory holding `WORKFLOW.md`,+ `SKILL.md` or `skill.json`; `skills_dir` accepts either one bundle or a+ directory of them.+- `Access::supervised()` keeps the approval gate on. An unattended agent+ parks risky calls and they deny after ten minutes. Use `Access::full()` for+ automation.++## Tests++Unit tests sit beside each module (`access_tests.rs`, `builder_tests.rs`,+`provider_tests.rs`, `workspace_tests.rs`, and others). The end-to-end proof+that a harness runs a real turn against a `wiremock` provider is+`tests/harness_embed.rs`.++```bash+cargo test -p openhuman-embed --features inference,mcp,skills harness::+cargo test -p openhuman-embed --features inference,mcp,skills --test harness_embed+```