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: expand crate READMEs with architecture and layout details
Steven Enamakelc367ee3a086b
diff --git a/crates/openhuman-app/README.md b/crates/openhuman-app/README.mdindex 2e9e034b6c..0e1eb3f6bb 100644--- a/crates/openhuman-app/README.md+++ b/crates/openhuman-app/README.md@@ -1,112 +1,356 @@-# `openhuman-app`+# openhuman-app-Thin Tauri v2 desktop host for OpenHuman on Windows, macOS, and Linux (Wry-webview, no CEF). It links `openhuman_core` in-process and runs the core's-HTTP/JSON-RPC server as a tokio task (`core_process.rs`) instead of spawning a-sidecar binary, so the core's lifetime is tied to the GUI process. Identities:-Cargo package `openhuman-app`, library `openhuman`, binary `OpenHuman`. Only-the Cargo package was renamed for the `crates/` layout; the library and-executable names are shipped identities and are unchanged.+The desktop host for OpenHuman on Windows, macOS and Linux. It is a thin Tauri+v2 application on Wry (WKWebView, WebView2, WebKitGTK) that links the Rust core+as a library and runs the core's HTTP/JSON-RPC server as a tokio task inside+the GUI process. The React frontend in `app/` runs in the main webview and+talks to that core over loopback HTTP. Everything else in this crate is+platform glue the webview cannot do on its own: windows and tray, deep links,+native notifications, global hotkeys, auto-update, login, and process+recovery.-See [`gitbooks/developing/architecture/tauri-shell.md`](../../gitbooks/developing/architecture/tauri-shell.md)-for the full IPC command reference, window/tray behavior, and UI-to-core-data flow. This README covers what is specific to building and depending on-this crate.+Three names refer to this crate. The Cargo package is `openhuman-app`, the+library is `openhuman`, and the executable is `OpenHuman`. Only the package+name follows the `crates/` layout; the library and binary names are shipped+identities.-## Separate Cargo world+For the user-facing tour of windows, tray and data flow, see+[`gitbooks/developing/architecture/tauri-shell.md`](../../gitbooks/developing/architecture/tauri-shell.md).-The root `Cargo.toml` excludes this directory: this crate has its own-`Cargo.lock` and `target/`, so root-only Cargo commands never resolve-GTK/WebKit/Tauri. Build and check it explicitly:+## How it works++### Process shape++```text++---------------------------- OpenHuman process -----------------------------++| |+| main webview (React, app/src) Tauri commands (lib.rs) |+| +---------------------------+ invoke +----------------------------+ |+| | coreRpcClient |---------->| core_rpc_endpoint | |+| | fetch(url, Bearer token)|<----------| -> (url, token) | |+| +-------------+-------------+ | session::commands (auth_*) | |+| | | gateway::commands | |+| | HTTP POST /rpc | hotkeys, windows, update | |+| v +-------------+--------------+ |+| +---------------------------+ | |+| | embedded core server |<------------------------+ |+| | openhuman_rpc::server | shell-side callers (session link, |+| | (tokio task, 127.0.0.1) | iMessage scanner) use the same HTTP |+| | openhuman_core domains | |+| +---------------------------+ |++---------------------------------------------------------------------------++```++There is no sidecar binary. `core_process::CoreProcessHandle` owns a tokio task+running `openhuman_rpc::server::run_server_embedded_with_ready`, so the core+lives and dies with the window. The handle generates a 256-bit hex bearer per+launch (`generate_rpc_token`) and hands it to the embedded server in memory,+not through the environment. The frontend gets it back with the+`core_rpc_endpoint` command.++### Boot sequence++`main.rs` runs first. It calls `openhuman_tinyhumans::install` so the core has+a backend transport (the core carries none of its own), then looks at+`argv[1]`:++- `OpenHuman core <args>` goes to `run_core_from_args`, which installs the+ JSON-RPC server (`openhuman_rpc::server::install_cli_server`) and dispatches+ into the core CLI. On Windows the process reattaches to the parent console+ first so output appears in the shell.+- `OpenHuman mcp` and `OpenHuman mcp-server` do the same, which makes the app+ binary a stdio MCP server for clients such as the Claude Code CLI.+- Anything else calls `openhuman::run()` and starts the GUI.++`run()` in `lib.rs` then does, in order:++1. Builds the Tauri context (on Windows it drops native decorations for the+ custom titlebar), neutralizes a broken parent stderr+ (`stderr_panic_hook`), and installs the backend transport again in case+ the library is entered without `main.rs`.+2. Replaces Tauri's async runtime with a multi-thread tokio runtime that uses+ the core's `AGENT_WORKER_STACK_BYTES` stack size and+ `MAX_BLOCKING_THREADS`, so agent turns started from commands do not+ overflow the default stack.+3. Initializes Sentry (DSN from `OPENHUMAN_TAURI_SENTRY_DSN`), with a+ `before_send` filter that drops dev-server fetch noise and the core's+ known transient classes (`openhuman_core::core::observability::is_*`) and+ tags the signed-in user id from `session::peek_user_id`. Then the stderr+ panic hook, file logging (`file_logging::init`), and the Linux display and+ WSL checks.+4. Single-instance guards that must run before any window exists. On Windows+ a named mutex makes a second launch forward its `openhuman://` URLs over a+ named pipe (`deep_link_ipc_windows`) and exit, and+ `process_recovery::reap_stale_openhuman_processes` clears a wedged+ previous GUI instance. On Linux a second launch forwards its URLs over a+ Unix socket (`deep_link_ipc`) and exits.+5. Builds the Tauri app: the macOS app menu, `tauri-plugin-single-instance`+ (skipped on Linux when the D-Bus session bus is unreachable, because the+ plugin panics there), the opener, `external_navigation`, deep-link,+ notification, global-shortcut and updater plugins, and managed state for+ hotkeys, the staged app update and the iMessage scanner registry.+6. `setup()`: points the core at the installer's `bundled-modules/` resource+ directory, verifies `openhuman://` registration (Windows registry+ read-back, Linux xdg-utils), drains deep links that arrived early, removes+ a stale macOS LaunchAgent in debug builds, then creates the+ `CoreProcessHandle` on `default_core_port()` (`OPENHUMAN_CORE_PORT`, default+ 7788), exports `OPENHUMAN_CORE_RPC_URL`, installs the session host+ (`session::install`), restores window geometry (`window_state`), shows the+ main window, and on macOS schedules the iMessage scanner.+7. `RunEvent::Ready` sets up the tray. Tray creation is deferred to here+ because GTK is not ready earlier, and `setup_tray` is a no-op on Linux.++The core is not started in `setup()`. The frontend's boot gate calls+`start_core_process`, which calls `CoreProcessHandle::ensure_running` and+shows a notification if the server had to fall back to another port. The one+exception is daemon mode (`daemon` or `--daemon` on the command line), where+the window starts hidden and the core is started directly.++### Starting the embedded core++`ensure_running` is idempotent. If the preferred port is already taken it+probes the listener. A previous OpenHuman core (left by a crashed or sibling+dev build) is terminated and replaced, with a revalidation step that guards+against PID reuse. Anything else is logged and the server tries its fallback+bind range. `OPENHUMAN_CORE_REUSE_EXISTING=1` skips all of this and attaches to+whatever is listening, which is how you point the shell at an external+`openhuman-core run` for debugging. Readiness is a oneshot signal from the+server plus a poll, with a 60 second ceiling. Debug builds also write the+bearer to `<tmp>/openhuman-e2e-rpc-token` (mode 0600) for the E2E harness.++`restart_core_process`, `recover_port_conflict` and `force_quit_port_owner`+are the recovery commands the boot gate offers when startup fails.++### How the frontend reaches the core++```text+coreRpcClient.ts+ |+ | invoke('core_rpc_endpoint') -> active_rpc_endpoint()+ | |+ | gateways on: gateway::registry::current()+ | gateways off: embedded url + rpc_token+ v+ rpcUrlNeedsShellRelay(url)?+ | no (loopback or https) yes (plain http to a LAN host)+ v v+ fetch(url) from the webview invoke('relay_http_rpc', {url, token, body})+ -> core_rpc::post_json_rpc (reqwest)+```++`core_rpc_endpoint` returns the URL and bearer from one snapshot so the+renderer can never pair one core's URL with another core's token.+`core_rpc_url` and `core_rpc_token` are the older split accessors. The webview+origin is a secure context, so a plain-`http` runtime on a LAN address is+blocked as mixed content; `relay_http_rpc` sends that request from Rust+instead and returns the upstream status and body verbatim. With the+`gateways` feature, `post_json_rpc` refuses to attach a bearer to plain HTTP+off loopback.++### Shutdown++Every clean exit path (`RunEvent::ExitRequested`, tray or menu quit,+`app_quit`) saves the main window geometry and calls+`perform_early_teardown_sync_once`. That stops the iMessage scanner, tears+down any provisioned gateway, and sends the core its terminate signal. After+Tauri's event loop returns, `process_kill::sweep_orphan_children` kills any+child process still parented to the app. On macOS closing the main window+hides the app instead of destroying the webview, so the dock and tray can+bring it back; on Windows closing the main window exits.++## Layout++Core lifecycle and RPC:++| Path | What it does |+| --- | --- |+| `src/main.rs` | Binary entry. Installs the backend transport and routes `core`, `mcp` and GUI launches. |+| `src/lib.rs` | `run()`, `run_core_from_args()`, most `#[tauri::command]`s, tray, menu, the `generate_handler!` list and the run-event loop. |+| `src/core_process.rs` | `CoreProcessHandle`: start, restart, shut down the embedded server; stale-listener takeover; port-conflict recovery. |+| `src/core_rpc.rs` | `relay_http_rpc`, `post_json_rpc`, and helpers for shell-side calls to the embedded core (`core_rpc_url_value`, `apply_auth`). |+| `src/process_kill.rs` | Cross-platform TERM and force-kill helpers and the exit-time orphan sweep. |+| `src/process_recovery.rs` | Finds and reaps OpenHuman processes left by hard exits. See [`src/process_recovery/`](src/process_recovery/README.md). |+| `src/gateway/` | Routes the frontend to a core in a container, over SSH, or both (feature `gateways`). See [`src/gateway/`](src/gateway/README.md). |+| `src/session/` | Login, logout and current user, via `openhuman-tinyhumans`. See [`src/session/`](src/session/README.md). |++Platform integration:++| Path | What it does |+| --- | --- |+| `src/deep_link_ipc.rs` | Linux: a second launch forwards `openhuman://` URLs to the primary over a Unix socket; the primary emits `deep-link://new-url`. |+| `src/deep_link_ipc_windows.rs` | Windows: the same over a named pipe. |+| `src/deep_link_registration_check.rs` | Windows: reads back the `HKCU\Software\Classes\openhuman` registration and logs a redacted health report. |+| `src/loopback_oauth.rs` | One-shot `http://127.0.0.1:<port>/auth` listener used as the RFC 8252 OAuth redirect; emits `loopback-oauth-callback`. |+| `src/external_navigation.rs` | Plugin that cancels top-level `http(s)` navigation away from the app origin and opens the URL in the default browser. |+| `src/native_notifications/` | Notification permission and delivery, real on macOS. See [`src/native_notifications/`](src/native_notifications/README.md). |+| `src/imessage_scanner/` | macOS: reads `chat.db` and ingests conversations into memory. See [`src/imessage_scanner/`](src/imessage_scanner/README.md). |+| `src/dictation_hotkeys.rs`, `src/ptt_hotkeys.rs` | Global shortcut parsing and state for dictation and push-to-talk. |+| `src/ptt_overlay.rs` | Borderless always-on-top window for push-to-talk, rendering the `/ptt-overlay` route. |+| `src/mascot_native_window.rs`, `src/notch_window.rs` | macOS: native NSPanel plus WKWebView hosts for the floating mascot and the notch activity pill. |+| `src/window_state.rs` | Saves and restores main window position and size, with a DPI guard and work-area clamping. |+| `src/directory_picker.rs` | Native folder chooser for the folder memory source. |+| `src/workspace_paths.rs` | Open, reveal or preview a file, only after resolving it inside the active workspace. |++Updates, reset and diagnostics:++| Path | What it does |+| --- | --- |+| `src/app_update.rs` | Bounded retry policy for the updater download. The update commands themselves are in `lib.rs`. |+| `src/local_data_reset.rs` | `reset_local_data`: wipes the local `.openhuman` data. |+| `src/reset_reboot_schedule.rs` | Windows: schedules deletion at next reboot when files are locked during a reset. |+| `src/file_logging.rs` | Resolves the data dir and calls `openhuman_core::core::logging::init_for_embedded`; `reveal_logs_folder`, `logs_folder_path`. |+| `src/stderr_panic_hook.rs` | Stops a closed parent stderr pipe from turning log writes into panics. |++Other commands:++| Path | What it does |+| --- | --- |+| `src/artifact_commands.rs` | Copies an agent artifact into the Downloads folder. |+| `src/mcp_commands.rs` | Locates the `openhuman-core` binary and opens an MCP client's config file for the user. |+| `src/claude_code.rs` | Opens a native terminal running `claude auth login` for the Claude Code provider. |++Configuration and packaging:++| Path | What it does |+| --- | --- |+| `tauri.conf.json` | Windows, bundle resources (agent prompts and `bundled-modules`), updater and installer settings. |+| `capabilities/` | The capability granted to the `main` and `overlay` windows. See [`capabilities/`](capabilities/README.md). |+| `permissions/` | App permission sets referenced by the capability. See [`permissions/`](permissions/README.md). |+| `bundled-modules/` | Installer resource directory for prebuilt module releases. See [`bundled-modules/`](bundled-modules/README.md). |+| `build.rs` | Runs `tauri_build`, and empties `bundle.resources` for non-release builds. |+| `profiling/` | Standalone CPU and RAM profiler for a running app. See [`profiling/`](profiling/README.md). |+| `Info.plist`, `entitlements.sidecar.plist`, `nsis-hooks.nsh`, `main.desktop`, `postinst`, `postrm` | Platform packaging files for macOS, the Windows installer, and Linux packages. |++## IPC commands++The authoritative list is the `tauri::generate_handler!` call near the end of+`run()` in `src/lib.rs`. Grouped:++| Group | Commands |+| --- | --- |+| Core endpoint | `core_rpc_endpoint`, `core_rpc_url`, `core_rpc_token`, `relay_http_rpc`, `overlay_parent_rpc_url` |+| Core lifecycle | `start_core_process`, `restart_core_process`, `recover_port_conflict`, `force_quit_port_owner`, `process_diagnostics_list_owned` |+| Gateways (feature `gateways`) | `gateway_list`, `gateway_save`, `gateway_delete`, `gateway_activate`, `gateway_active`, `gateway_status` |+| Session | `auth_login_with_token`, `auth_store_session`, `auth_logout`, `auth_state`, `auth_current_user`, `get_active_user_id` |+| Updates | `check_app_update`, `download_app_update`, `install_app_update`, `apply_app_update`, `check_core_update`, `apply_core_update` |+| App and windows | `app_quit`, `restart_app`, `activate_main_window`, `set_titlebar_for_sidebar`, `mascot_window_show`, `mascot_window_hide`, `notch_window_show`, `notch_window_hide` |+| Hotkeys and voice | `register_dictation_hotkey`, `unregister_dictation_hotkey`, `register_ptt_hotkey`, `unregister_ptt_hotkey`, `show_ptt_overlay` |+| Notifications | `notification_permission_state`, `notification_permission_request`, `show_native_notification` |+| Files and logs | `open_workspace_path`, `reveal_workspace_path`, `preview_workspace_text`, `download_artifact_to_downloads`, `pick_directory_via_dialog`, `reveal_logs_folder`, `logs_folder_path`, `reset_local_data` |+| Integrations | `start_loopback_oauth_listener`, `stop_loopback_oauth_listener`, `mcp_resolve_binary_path`, `mcp_open_client_config`, `claude_code_login_launch` |++`check_core_update` always reports the running version as current and+`apply_core_update` always errors: the core ships inside the app, so the app+updater is the only update path. Both remain for frontend compatibility.++Events the shell emits to the renderer include `auth://changed`,+`auth://expired`, `deep-link://new-url`, `loopback-oauth-callback`,+`app-update:status` and `app-update:progress`.++## Key types and entry points++- `openhuman::run()` (`src/lib.rs`) starts the GUI.+- `openhuman::run_core_from_args(args)` (`src/lib.rs`) runs the core CLI+ in-process.+- `CoreProcessHandle` (`src/core_process.rs`) is managed Tauri state for the+ embedded server: `ensure_running`, `restart`, `shutdown`,+ `send_terminate_signal`, `rpc_url`, `rpc_token`, `port`.+- `active_rpc_endpoint` (`src/lib.rs`) is the single answer to "where does RPC+ go"; the endpoint commands and the session link both call it.+- `SessionHost` (`src/session/mod.rs`) is managed state wrapping the+ `openhuman_tinyhumans::SessionManager`.+- `gateway::registry::current` and `gateway::registry::activate`+ (`src/gateway/registry.rs`) hold the active gateway.++## Building++This crate is excluded from the root workspace. It has its own `Cargo.lock`+and resolves GTK, WebKit and Tauri only when you build it explicitly:```bashcargo check --manifest-path crates/openhuman-app/Cargo.toml-pnpm dev:app-pnpm build+pnpm dev:app # Vite dev server + this crate+pnpm build # production bundle```-Its `[patch]` tables mirror the root manifest's entries (`tinymemory-api`,-`tinyinference`, `motosan-ai-oauth`, `tinyflows`, `tinychannels`) and add a-`tinytools` path patch matching the core crate's path dependency. Keep them in-sync with the root `Cargo.toml`: drift resolves two copies of the same crate-as distinct Rust types.--## Crate relationships--- **`openhuman-rpc`** (`http-client` feature): `core_rpc.rs` re-exports- `bearer_header` (as `relay_bearer_header`), `redact_url_for_log`, and- `HttpRpcResponse` (as `RelayHttpResponse`) crate-wide, and wraps- `openhuman_rpc::post_json_rpc` for the `relay_http_rpc` command, which the- frontend's `coreRpcClient` uses only when `rpcUrlNeedsShellRelay()` says a- non-loopback plain-`http://` runtime would be blocked as mixed content- (#3865); loopback and `https://` URLs are fetched directly from the webview.-- **`openhuman_core`** (path dependency, package `openhuman`,- `default-features = false`): the embedded core does not inherit the core- crate's default feature set, so every product gate- (`channels`, `media`, `inference`, `voice`, `web3`, `documents`, `modules`,- `flows`, `skills`, `mcp`, `crash-reporting`, `http-server`,- `scheduler-gate`, `file-logging`, `contacts`, `runtime-node`, `hosting`)- must be forwarded explicitly in `Cargo.toml`. A gate missing from that list- vanishes from the shipped app silently: no build error, no test failure.- `scripts/ci/check-feature-forwarding.mjs` compares this list against- `scripts/ci/product-features.txt` and fails CI on drift.-- `lib.rs` carries two `const _: () = assert!(...)` guards- (`VOICE_COMPILED_IN`, `HTTP_SERVER_COMPILED_IN`) that fail the build if- `voice` or `http-server` is ever dropped from the forwarded list. Both- failure modes are otherwise silent and runtime-only.--## Feature flags--Shell-local gates from `[features]` in `Cargo.toml`. These are unrelated to-the `openhuman_core` product-feature forwarding above and do not belong in-`scripts/ci/product-features.txt`.+The core dependency is `openhuman_core = { path = "../openhuman-core",+package = "openhuman", default-features = false, features = [...] }`. Because+default features are off, every product gate must be listed by hand:+`channels`, `media`, `inference`, `voice`, `web3`, `documents`, `modules`,+`flows`, `skills`, `mcp`, `crash-reporting`, `http-server`, `scheduler-gate`,+`file-logging`, `runtime-node`, `hosting`. A gate missing here disappears from+the shipped app with no build error. `scripts/ci/check-feature-forwarding.mjs`+compares the list with `scripts/ci/product-features.txt`, and `lib.rs` has two+`const _: () = assert!(...)` guards (`VOICE_COMPILED_IN`,+`HTTP_SERVER_COMPILED_IN`) that fail the build if `voice` or `http-server` is+dropped.++Other dependencies: `openhuman-rpc` with `http-client` and `server` (the+embedded server and the relay), `openhuman-tinyhumans` with `jev` (backend+transport and the session owner), and the `tinybox-*` crates behind+`gateways`.++The `[patch]` tables mirror the root `Cargo.toml` for `tinytools`, the+`tinyinference-*` crates, `tinyflows` and `tinychannels`. Keep them in sync:+drift makes Cargo resolve two copies of the same crate, and their types stop+being interchangeable (a shell `dyn Tool` would no longer be the core's).++Release profile settings (thin LTO, 16 codegen units, stripped symbols,+`debug = "line-tables-only"`) must match the root manifest.++### Feature flags++These are shell-local and unrelated to the core feature forwarding above.| Feature | Meaning || --- | --- |-| `gateways` (default) | Routing the frontend to a core in a Docker container, over SSH, or both, via `tinybox`. |-| `custom-protocol` | Serve the bundled `frontendDist` via `tauri://localhost` instead of the Vite dev server. Set automatically by `cargo tauri build`; never add to `default`. |-| `sandbox-bubblewrap` | Empty in this crate (`= []`); it does not forward `openhuman_core/sandbox-bubblewrap`, so enabling it here changes nothing. |-| `e2e-test-support` | Forwards `openhuman_core/e2e-test-support` to expose `openhuman.test_reset`. Flipped on by the E2E build (`app/scripts/e2e-build.sh`). |+| `gateways` (default) | Compiles in `src/gateway/` and the `tinybox-*` crates. Off, the gateway commands are absent and `active_rpc_endpoint` always answers with the embedded core. |+| `custom-protocol` | Serves the bundled `frontendDist` from `tauri://localhost` instead of the Vite `devUrl`. `cargo tauri build` turns it on; never add it to `default`. |+| `e2e-test-support` | Forwards `openhuman_core/e2e-test-support` to expose `openhuman.test_reset`. The E2E build (`app/scripts/e2e-build.sh`) enables it. |-## Entry points+## Boundaries-- `openhuman::run()`: starts the Tauri application (window, tray, plugins,- embedded core).-- `openhuman::run_core_from_args(args)`: dispatches directly into- `openhuman_core`'s CLI without shelling out to a separate binary.-- `main.rs` routes `OpenHuman core <args>` and `OpenHuman mcp` /- `OpenHuman mcp-server` to `run_core_from_args`; everything else starts the- GUI via `run()`.+- Business rules, persistence, agents, memory and RPC methods belong to+ `crates/openhuman-core`. The shell orchestrates and presents; it does not+ duplicate core policy.+- The JSON-RPC server, envelopes and HTTP client live in `crates/openhuman-rpc`.+- Login-token exchange, `/auth/me`, the user cache and the backend transport+ live in `crates/openhuman-tinyhumans`. The shell only exposes them as+ commands and forwards events.+- Box provisioning, SSH reach and Docker confinement are implemented in the+ `vendor/tinybox` submodule (`tinyhumansai/tinybox`).+- No JavaScript injection into child webviews. New behavior goes into Rust IPC+ hooks, and new Tauri plugins must be audited for `js_init_script`.+- The app runs on Wry. Do not reintroduce CEF or CDP-scanner assumptions. The+ iMessage scanner is separate because it reads `chat.db` directly.-## Module map+## Gotchas-| Area | Modules |-| --- | --- |-| Core lifecycle | `core_process.rs`, `core_rpc.rs`, `process_kill.rs`, `process_recovery.rs`, `workspace_paths.rs` |-| Gateways (feature-gated) | `gateway/` (`types`, `store`, `ops`, `provision`, `registry`, `commands`) |-| Platform integration | `deep_link_ipc.rs` (Linux), `deep_link_ipc_windows.rs`, `deep_link_registration_check.rs`, `native_notifications/`, `imessage_scanner/` (macOS `chat.db` reader), `mascot_native_window.rs` and `notch_window.rs` (macOS), `ptt_hotkeys.rs`/`ptt_overlay.rs`, `dictation_hotkeys.rs`, `window_state.rs` |-| Updates / reset | `app_update.rs`, `local_data_reset.rs`, `reset_reboot_schedule.rs` (Windows) |-| Misc | `artifact_commands.rs`, `claude_code.rs`, `mcp_commands.rs`, `loopback_oauth.rs`, `directory_picker.rs`, `file_logging.rs`, `stderr_panic_hook.rs` |+- Many comments and log lines in `lib.rs`, `deep_link_ipc*.rs` and+ `process_recovery.rs` still say "CEF" (`cef::shutdown`, "pre-CEF mutex",+ the `com.openhuman.app-cef-init` mutex name). They describe ordering that+ still matters (single-instance checks before any webview starts), not a CEF+ runtime.+- The iMessage scanner and other shell-side callers that use+ `core_rpc::core_rpc_url_value` always reach the embedded core through+ `OPENHUMAN_CORE_RPC_URL`, even when a gateway is active. The session link+ goes through `active_rpc_endpoint` and follows the gateway.+- Without a build-time `AppManifest`, Tauri allows every app command+ registered in `generate_handler!`. The `permissions/*.toml` files are+ referenced by the capability but do not by themselves gate app commands.+- Tests for this crate do not run under `pnpm test:rust`, which only covers the+ root workspace.## Tests-Behavior tests are `*_tests.rs` siblings: `lib_tests.rs`,-`core_process_tests.rs`, `local_data_reset_tests.rs`, and-`gateway/{ops,registry,store,types}_tests.rs`. Because this crate is outside-the root workspace, `pnpm test:rust` (`scripts/test-rust-with-mock.sh`, which-runs `cargo test --manifest-path Cargo.toml --workspace`) does not reach them.-Run them directly, as CI does (`.github/workflows/test-reusable.yml`):+Tests are `*_tests.rs` siblings of each module (and under+`src/process_recovery/` and `src/native_notifications/macos/` for modules+defined inline). Run them directly, as CI does+(`.github/workflows/test-reusable.yml`):```bashcargo test --manifest-path crates/openhuman-app/Cargo.toml+cargo test --manifest-path crates/openhuman-app/Cargo.toml gateway::```-## Rules--- Keep this crate thin. New behavior belongs in Rust-side IPC hooks, not- JavaScript injected into child webviews; audit new Tauri plugins for- `js_init_script`.-- The `generate_handler!` call in `lib.rs` is the authoritative IPC command- list.-- Do not restore CEF or CDP-scanner assumptions; the app runs on Wry. The- native iMessage scanner stays separate because it reads `chat.db` directly.+Desktop E2E specs live under `app/test/e2e/specs/`.diff --git a/crates/openhuman-core/src/web3/README.md b/crates/openhuman-core/src/web3/README.mdindex 0ef7c75f28..235b217fc2 100644--- a/crates/openhuman-core/src/web3/README.md+++ b/crates/openhuman-core/src/web3/README.md@@ -1,117 +1,206 @@# web3-High-level web3 surface built on top of the [`wallet`](wallet/README.md)-module. The wallet stays basic (keys, balances, transfers, tx inspection); this-module focuses on EVM/Solana(/BTC) dapp interactions: swaps, bridges, and-generic dapp contract calls.--Quotes and ready-to-sign unsigned transactions come from the openhuman-backend's deBridge proxy (`/agent-integrations/crypto/{routes,swap,bridge}`,-backend PR #852). This module only resolves the caller's wallet address,-forwards the request, and stores a confirm-then-execute quote. On execute it-hands the unsigned transaction to the wallet's crate-internal signing-primitives: `wallet::sign_and_broadcast_evm` for an EVM `to`/`data`/`value`-transaction, or `wallet::sign_and_broadcast_solana` for a hex-`VersionedTransaction`. Private keys never leave the wallet.--## Five family members--Three members (`swap`, `bridge`, `dapp`) are documented here; `wallet` and-`x402` each have their own README:--| Module | Namespace | Purpose |-| --- | --- | --- |-| `swap/` | `web3_swap` | Single-chain swaps via deBridge. Cross-chain requests are rejected with a pointer to `web3_bridge`. |-| `bridge/` | `web3_bridge` | Cross-chain bridges via deBridge DLN. Same-chain requests rejected. Signs and broadcasts on the source chain. |-| `dapp/` | `web3_dapp` | Generic EVM contract calls from caller-supplied calldata (no backend). |-| [`wallet/`](wallet/README.md) | `wallet` | Basic multi-chain key/account management and primitive on-chain operations. |-| [`x402/`](x402/README.md) | `x402` | HTTP-402 payment protocol: intercept, pay, retry, ledger. |--`wallet` and `x402` are declared ungated in `mod.rs`, unlike `swap`/`bridge`/-`dapp`/`ops`/etc., which are `#[cfg(feature = "web3")]`. As `mod.rs` puts it:--> Ungated family members: `wallet` and `x402` are facades in their own right.-> Each keeps its own `stub.rs` and gates its real submodules on the same-> default-ON `web3` feature. Always-compiled callers resolve through those-> stubs (`tools/impl/network/host.rs` calls into `x402`), so these-> declarations must NOT carry a `#[cfg]`.--## Compile-time gate (`web3` feature)--`pub mod web3;` (declared in `crates/openhuman-core/src/lib.rs`) is always-compiled: it is a facade. The real swap/bridge/dapp implementation is gated-behind the default-ON `web3` Cargo feature. When the feature is off,-`stub.rs` takes its place and exposes-`all_web3_registered_controllers` / `all_web3_controller_schemas` /-`all_web3_agent_tools` returning empty collections, so `core/all.rs` and-`tools/ops.rs` need no per-call `#[cfg]`. `cargo check --no-default-features`-is the only thing that catches drift between the real and stub signatures.--## Where the logic lives--The swap/bridge/dapp logic is in the vendored `tinywallet-web3` crate-(`vendor/tinywallet/crates/tinywallet-web3`, `crypto::service`), not here: quote-preparation, the confirm-then-execute quote store and the agent tools. This-module is the host adapter. The crate reaches OpenHuman only through seams,-implemented in `seams.rs`.--## Key files--| File | Role |-| --- | --- |-| `mod.rs` | Export-focused root: aggregates `all_web3_controller_schemas` / `all_web3_registered_controllers` / `all_web3_agent_tools` (which builds the crate's tools over the process-wide service), plus shared schema helpers. Re-exports the crate's request/quote types as `web3::types`. |-| `seams.rs` | The host implementations of the crate's seams (`HostSigner`, `HostAccounts`, `TaskLocalScope`, `HostBackend`) and the `OnceLock` holding the process-wide `WalletEngine` and `Web3Service` (`engine()`, `service()`). |-| `client.rs` | `CryptoClient`, a thin wrapper over the shared `IntegrationClient` for `/agent-integrations/crypto/*` (Bearer JWT auth, envelope unwrap). Reached through `HostBackend`. |-| `stub.rs` | Disabled facade compiled when `web3` is off; empty `all_web3_registered_controllers` / `all_web3_controller_schemas` / `all_web3_agent_tools`. See Compile-time gate above. |-| `seams_tests.rs` | Composition tests over the real wallet state, and the regression test that `TaskLocalScope` reads `APPROVAL_CHAT_CONTEXT`. |-| `stub_tests.rs` | Runs only in the disabled build; pins that the three stub entry points return empty collections. |-| `{swap,bridge,dapp}/schemas.rs` | Per-namespace RPC controllers and handlers (namespace strings are wire contracts). |--## RPC / controllers--- `web3_swap`: `quote`, `execute`, `routes` (`openhuman.web3_swap_quote`, and so on).-- `web3_bridge`: `quote`, `execute`.-- `web3_dapp`: `call`, `execute`.--Quote/call methods return a `quoteId`; the matching `*_execute` (with-`confirmed: true`) signs and broadcasts. Quotes are bound to the chat thread-that prepared them, so a leaked `quoteId` cannot be hijacked from another-session. They expire after 5 minutes, and a failed broadcast restores the-quote with a refreshed TTL.--## Agent tools--`web3_swap_quote`, `web3_swap_execute`, `web3_swap_routes`,-`web3_bridge_quote`, `web3_bridge_execute`, `web3_dapp_call`,-`web3_dapp_execute` are defined in `tinywallet_web3::tools::web3` and built over-the process-wide service by `all_web3_agent_tools()` (registered in-`crates/openhuman-core/src/tools/ops.rs`). They call the backend-per-invocation and error gracefully when the user is not signed in.+The crypto family: a local multi-chain wallet, token swaps and cross-chain+bridges through deBridge, generic EVM dapp calls, and the x402 machine-payment+protocol. Almost all of the logic (the wallet engine, the per-chain signing+flows, the quote store, the agent tools) lives in the vendored+[`tinywallet`](../../../../vendor/tinywallet) crates. This folder is the host+adapter: it plugs OpenHuman's keyring, consent, config, backend client, and+chat scope into those crates through seams, and owns the RPC controllers.-## Chain-id mapping+Callers are the controller registry (`core/all.rs`), the tool registry+(`tools/ops.rs`), and the generic `http_request` tool, which falls back to an+x402 payment on an HTTP 402.-deBridge uses real EVM chain ids (1 ETH, 10 Optimism, 56 BNB, 137 Polygon,-8453 Base, 42161 Arbitrum) and a synthetic Solana id (`7565164`). `chain_family`-maps a deBridge id to the local signer family; ids the wallet can't sign for-are rejected at quote time.+## How it works-## Wiring+### The process-wide engine and service-- `crates/openhuman-core/src/core/all.rs`: `crate::web3::wallet::all_wallet_registered_controllers()` (around line 884), `crate::web3::all_web3_registered_controllers()` (around line 890), `crate::web3::x402::all_x402_registered_controllers()` (around line 569), each pushed onto the controller registry under `DomainGroup::Web3`.-- `crates/openhuman-core/src/tools/mod.rs` lines 59-60: `#[cfg(feature = "web3")] pub use crate::web3::wallet::tools::*;` re-exports the wallet agent tool structs.-- `crates/openhuman-core/src/tools/ops.rs`: calls `crate::web3::all_web3_agent_tools()` to register the swap/bridge/dapp agent tools, alongside the wallet and x402 tool registrations.+`seams.rs` holds one `WalletEngine` and one `Web3Service` for the whole+process, built lazily on first use behind a `OnceLock` (`seams::engine()`,+`seams::service()`). Both come from `tinywallet-web3` and hold no+configuration of their own. Everything host-specific reaches them through+seams, each resolving its configuration per call:-## Dependencies+| Seam (from `tinywallet-web3`) | Host implementation |+| --- | --- |+| `Transport` | `OpenHumanTransport` (`wallet/transport.rs`) over the wallet RPC layer |+| `RpcEndpoints` | `HostEndpoints` (`wallet/endpoints.rs`), the `OPENHUMAN_WALLET_RPC_*` environment |+| `WalletSigner` | `HostSigner` (`seams.rs`): keyring secret, decrypt, then the loaded wallet module |+| `WalletAccounts` | `HostAccounts` (`seams.rs`): the wallet's stored set-up state |+| `QuoteScope` | `TaskLocalScope` (`seams.rs`): the chat turn's `APPROVAL_CHAT_CONTEXT` |+| `Web3Backend` | `HostBackend` (`seams.rs`): `CryptoClient` over the integrations client |++```text+ core/all.rs tools/ops.rs+ (wallet_*, web3_*, (wallet_*, web3_*, x402_request)+ x402_* controllers) |+ | |+ v v+ +----------------------------------------------++ | web3/ (host adapter) |+ | seams::engine() / seams::service() |+ +----------------------------------------------++ | WalletEngine / Web3Service (tinywallet-web3)+ |+ +-- WalletSigner --> HostSigner+ | wallet::secret_material + decrypt_secret+ | -> modules::wallet (loaded tinywallet module)+ | derives key, signs, returns signed bytes+ +-- Transport/RpcEndpoints --> chain RPC (reqwest)+ +-- Web3Backend --> CryptoClient+ | -> /agent-integrations/crypto/{routes,swap,bridge}+ +-- QuoteScope --> APPROVAL_CHAT_CONTEXT (thread, client)+```++No private key is ever assembled in this process, and the recovery phrase+never enters `tinywallet-web3`. `HostSigner` decrypts the phrase for one call+and sends it, as a `tinywallet_bus::wire::SecretMaterial`, over a confidential+call to the loaded wallet module, which must have proved it is an artifact+this build pinned (`modules::wallet`).++### Swap, bridge, and dapp: confirm then execute++All three use the same two-step flow, implemented in+`tinywallet_web3::crypto::service`:++```text+ web3_swap_quote / web3_bridge_quote / web3_dapp_call+ resolve the wallet's own address for the chain family (if not given)+ swap/bridge: HostBackend -> backend deBridge proxy -> quote + unsigned tx+ dapp: validate caller-supplied contract + calldata (no backend call)+ store quote { id, owner = QuoteScope::current_owner(), TTL 5 min }+ return { quoteId, kind, expiresAtMs, quote }+ |+ v+ web3_*_execute { quoteId, confirmed: true }+ take_for(owner) -> "not found" if owner differs or expired+ sign via WalletSigner -> broadcast via Transport+ failure: restore the quote with a refreshed TTL+ return { quoteId, kind, transactionHash, explorerUrl?, feeRaw }+```++Quotes are bound to the chat thread and client that prepared them, so a+leaked `quoteId` cannot be executed from another session. Non-chat callers+(CLI, direct JSON-RPC, cron, sub-agents) have no owner and can execute their+own quotes. Cross-chain requests to `web3_swap` and same-chain requests to+`web3_bridge` are rejected, mirroring deBridge's split between single-chain+swaps and cross-chain DLN orders.++deBridge uses real EVM chain ids (1 Ethereum, 10 Optimism, 56 BNB, 137+Polygon, 8453 Base, 42161 Arbitrum) and a synthetic Solana id, `7565164`.+`chain_family` (in `tinywallet-web3`) maps a deBridge id to the local signer+family, and ids the wallet cannot sign for are rejected at quote time.++### Wallet and x402++The wallet (`wallet/`) owns onboarding, consent, the encrypted recovery+phrase, balances, and native and token transfers across EVM, Bitcoin, Solana,+and Tron, using the same prepare, confirm, execute pattern. x402 (`x402/`)+intercepts an HTTP 402 challenge, checks the spending ledger, has the wallet+sign a payment, and retries. Each has its own README.++## Layout++| Path | What it does |+| --- | --- |+| `mod.rs` | Facade. Declares the family, re-exports `tinywallet_web3::crypto::service` as `web3::types`, aggregates the swap, bridge, and dapp controllers (`all_web3_controller_schemas`, `all_web3_registered_controllers`) and agent tools (`all_web3_agent_tools`), and holds shared schema helpers (`req_json`, `opt_str`, `json_result`, `execute_inputs`). |+| `seams.rs` | The process-wide engine and service, and the host seam implementations listed above. |+| `client.rs` | `CryptoClient`, a thin wrapper over the shared `IntegrationClient` for `/agent-integrations/crypto/*`. Responses are passed through as `serde_json::Value`. |+| `stub.rs` | Compiled when `web3` is off: the three aggregators return empty collections. |+| [`swap/`](swap/README.md) | `web3_swap` controllers: `quote`, `execute`, `routes`. |+| `bridge/` | `web3_bridge` controllers: `quote`, `execute`. |+| [`dapp/`](dapp/README.md) | `web3_dapp` controllers: `call`, `execute`. |+| [`wallet/`](wallet/README.md) | Wallet controllers, onboarding and secret state (`ops/`), the engine wrapped in `Outcome` (`execution.rs`), endpoint resolution, and the chain transport. Has its own `stub.rs`. |+| [`x402/`](x402/README.md) | x402 controllers, wallet and proxy seams for `tinywallet-x402`, ledger budget from the environment, payment records. Has its own `stub.rs`. |++## Key types and entry points++- `seams::engine()` and `seams::service()` return the shared `WalletEngine`+ and `Web3Service`. The wallet tools in `tools/ops.rs` are built over+ `engine()`; the swap, bridge, and dapp tools over `service()`.+- `HostSigner`, `HostAccounts`, `TaskLocalScope`, and `HostBackend`+ (`seams.rs`) are the seam implementations a contributor changes when host+ behavior has to change.+- `CryptoClient::from_config` (`client.rs`) errors when no backend credential+ is available, the same gate the Composio tools use.+- `all_web3_agent_tools()` (`mod.rs`) builds the seven swap, bridge, and dapp+ tools from `tinywallet_web3::tools::web3`.+- `x402::request_tool()` and `x402::handle_402_and_pay` are the x402 entry+ points for the tool registry and the `http_request` 402 retry.++## RPC / CLI surface++All are registered under `DomainGroup::Web3` in `core/all.rs`. Method names+are `openhuman.<namespace>_<function>`.++| Namespace | Functions |+| --- | --- |+| `web3_swap` | `quote`, `execute`, `routes` |+| `web3_bridge` | `quote`, `execute` |+| `web3_dapp` | `call`, `execute` |+| `wallet` | `setup`, `status`, `reveal_recovery_phrase`, `balances`, `chain_status`, `network_defaults`, `supported_assets`, `encode_erc20_transfer`, `prepare_transfer`, `execute_prepared`, `tx_status`, `tx_receipt`, `lookup_tx` |+| `x402` | `get_summary`, `list_payments`, `update_budget` |-- `tinywallet-web3` (`vendor/tinywallet/crates/tinywallet-web3`, optional, feature `tools`, enabled by the `web3` feature): the swap/bridge/dapp service, quote store and tools. Its seams are implemented in `seams.rs`.-- [`crate::web3::wallet`]: `status` (through `HostAccounts`) and `secret_material` (through `HostSigner`).-- [`crate::integrations`] (`IntegrationClient`, `build_client`): backend auth and transport, through `HostBackend`.-- `crate::security::approval::APPROVAL_CHAT_CONTEXT`: quote-owner binding, read by `TaskLocalScope`.-- `crate::core::all` / `crate::core`: RPC controller registry wiring.-- `tinywallet-bus` (optional, gated by the `web3` feature): the contract crate. It supplies the `SecretMaterial`/`TransactionSpec` wire types the signer hands to the wallet module and the `Transport` seam types.+Each `*_execute` takes `quoteId` and `confirmed`, and `confirmed` must be+true. That flag is the explicit boundary between preparing and spending.-## Notes / gotchas+## Agent tools-- The backend injects a configurable affiliate fee (default 1%) collected on-chain by deBridge on the source chain; this module passes the quote through unchanged.-- deBridge returns a large nested object; everything not explicitly consumed is passed through as `serde_json::Value`.-- Same-chain `web3_bridge` requests and cross-chain `web3_swap` requests are rejected, mirroring deBridge's split between single-chain swaps and cross-chain DLN orders.+- Swap, bridge, dapp (from `tinywallet_web3::tools::web3`):+ `web3_swap_quote`, `web3_swap_execute`, `web3_swap_routes`,+ `web3_bridge_quote`, `web3_bridge_execute`, `web3_dapp_call`,+ `web3_dapp_execute`. They register unconditionally and error at call time+ when the user is not signed in.+- Wallet tools (status, chain status, prepare transfer, tx status, receipt,+ lookup) are re-exported through `wallet/tools.rs` and `tools/mod.rs`, and+ built in `tools/ops.rs`.+- `x402_request`, from `tinywallet-x402`, wired through `x402/seams.rs`.++## Boundaries++- Wallet engine, transfer flows, per-chain transaction building, swap,+ bridge, and dapp quote preparation, the quote store, and the agent tools+ belong to `tinywallet-web3`. The x402 wire format, payment builders,+ spending ledger, and `x402_request` tool belong to `tinywallet-x402`. Chain+ primitives and wire types belong to `tinywallet-bus` and+ `tinywallet-crypto`. Key derivation and signing belong to the loadable+ `tinywallet` module. All of these are in `vendor/tinywallet`, upstream+ `tinyhumansai/tinywallet`.+- Loading and attesting the wallet module belongs to `modules/wallet.rs`.+- Quote routes, deBridge integration, and the affiliate fee (default 1%,+ collected on-chain by deBridge on the source chain) belong to the backend.+ This module passes quotes through unchanged.+- The approval chat context (`APPROVAL_CHAT_CONTEXT`) belongs to+ `security::approval`.++## Gotchas++- The `web3` Cargo feature is not in the core's `default` set, despite older+ comments (including in `Cargo.toml` and the `mod.rs` docs) calling it+ default-on. It is in `scripts/ci/product-features.txt`, so the shipped app+ has it. It enables `tinywallet-bus`, `tinywallet-x402`, `tinywallet-web3`,+ and `modules`. At runtime `DomainSet::web3` gates the same surface.+- `pub mod web3`, `wallet`, and `x402` are always compiled. Each is a facade+ with its own `stub.rs` for the disabled build, so always-on callers+ (`core/all.rs`, `tools/ops.rs`, `tools/impl/network/host.rs` for x402) need+ no `#[cfg]`. Stub signatures must match the real ones, and only+ `cargo check --no-default-features` catches drift.+- `TaskLocalScope` reads a `tokio::task_local!`, which propagates across+ `.await` but not across `tokio::spawn`. If the chat path ever runs the tool+ loop on a freshly spawned task without re-installing the scope, the owner+ gate silently becomes a no-op. `seams_tests.rs` pins that it reads the+ task-local.+- `CryptoClient` logs only chain ids. Request bodies carry wallet addresses,+ which must not be logged in full.++## Tests++`seams_tests.rs` composes the real wallet state and pins the task-local scope.+`stub_tests.rs` runs only in the disabled build. `wallet/` and `x402/` keep+their own tests.++```bash+cargo test -p openhuman --features web3 web3::+cargo check -p openhuman --no-default-features # stub drift+```diff --git a/crates/openhuman-tinyhumans/README.md b/crates/openhuman-tinyhumans/README.mdindex 1e1420d50b..613070d778 100644--- a/crates/openhuman-tinyhumans/README.md+++ b/crates/openhuman-tinyhumans/README.md@@ -211,6 +211,12 @@ chain core, embed, tinyhumans, cli.- The core never obtains, validates, exchanges or refreshes a credential. Ittakes one through `auth.set_credential`. Login-token exchange, `GET/auth/me` and the current-user cache live in `session/` here.+- Hosted memory does not ride this transport. The core's `memory/engine.rs`+ hands TinyMemory's own HTTP client an endpoint from `backend::base_url`,+ the attribution headers from `backend::attribution_headers` and a bearer+ source, so memory needs the transport installed for its URL and headers,+ but `/memory/*` requests never pass through `SdkBackendTransport` and the+ SDK route registry does not apply to them.- Realtime Socket.IO stays on the core's own `platform::socket` transport; theSDK is built with `default-features = false`, which drops its socket client.- The generic Jev types (`JevRanker`, `JevEvaluator`, `JevStrategy`) live in