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(platform): add README for the platform module
Steven Enamakel483f729eb336
diff --git a/crates/openhuman-core/src/platform/README.md b/crates/openhuman-core/src/platform/README.mdindex 1fe84fbb0f..30b0bc082e 100644--- a/crates/openhuman-core/src/platform/README.md+++ b/crates/openhuman-core/src/platform/README.md@@ -1,32 +1,143 @@# platform-Host-platform services for the core process: lifecycle, self-update, diagnostics, and the local transport surfaces the desktop shell talks to. Nothing here is feature-gated. A build whose only inference driver is an external backend still has to start, stay healthy, report cost, and be reachable over Socket.IO, so this module ships in every build.+Services about the core process itself rather than about what the agent is+doing: is it running, is it healthy, what did it cost, is it connected to the+backend, does it need an update, how does it restart. The desktop shell, the+CLI, and the frontend reach these through ordinary JSON-RPC controllers, and+the boot path in `core/runtime/` starts the background pieces.-## What's in it+Nothing here is feature-gated. A build whose only inference driver is an+external backend still has to start, stay healthy, report cost, and be+reachable, so this family ships in every build. Its controllers are tagged+`DomainGroup::Platform`, the catch-all group that `DomainSet::platform`+switches at runtime.-| Folder | Purpose |+## How it works++Most members are small request and response domains. A few take part in+startup, and two are driven by events rather than calls. In boot order:++```text+ core/runtime/bootstrap.rs+ |- platform::cost::init_global(cfg.cost, workspace) cost ledger singleton+ |- platform::startup::run_workspace_migrations(ws) one-shot migrations+ |- platform::socket::set_global_socket_manager(..) SocketManager singleton+ core/runtime/subscribers.rs+ |- platform::health::bus::register_health_subscriber()+ |- platform::service::bus::register_restart_subscriber()+ |- platform::service::bus::register_shutdown_subscriber()+ core/runtime/services.rs+ |- platform::update::scheduler::run(config.update) periodic update check+ |- spawn_socket_auto_connect(..) if socketio service on+ token_provider_from_config(config) and a transport is+ installed+ core/all.rs+ '- about_app, health, doctor, cost, connectivity,+ service, socket, update controllers (DomainGroup::Platform)+```++The event-driven pieces:++- `health` keeps an in-memory component registry. Its subscriber listens to+ `system` and `channel` domain events and marks components ok or in error.+ `GET /health` on the RPC server reads the verdict: 503 only when a critical+ component (`core`) is unhealthy, 200 with a `degraded` flag otherwise.+- `service` turns a restart or shutdown request into+ `DomainEvent::SystemRestartRequested` or `SystemShutdownRequested`. Its+ subscribers respawn the process or exit after a short flush window.+ `update` uses the same restart path after staging a new binary.+- `socket` goes the other way. It is the core's own Socket.IO client to the+ hosted backend, and it republishes inbound server events onto the bus+ (`WebhookIncomingRequest`, `ComposioTriggerReceived`,+ `ChannelInboundMessage`, device tunnel events) for other domains to handle.++Some members read state other domains own instead of keeping their own.+`doctor` reads the daemon state file `service` writes and the memory engine+status from `memory`. `connectivity` reads the `SocketManager` state to tell+the frontend which of its connection channels is broken.++## Layout++| Path | What it does || --- | --- |-| [`about_app/`](about_app/README.md) | The desktop app's user-facing capability catalog: what each feature does, its maturity, and its privacy disclosure. |-| [`connectivity/`](connectivity/README.md) | Reachability diagnostics (`connectivity_diag`) and the listen-port selection logic used when the core binds its HTTP listener. |-| [`cost/`](cost/README.md) | Local token-usage and USD cost tracking, with a 7-day dashboard over JSON-RPC. |-| [`doctor/`](doctor/README.md) | Self-check probes over config, workspace, the daemon state file, and the embedding provider, aggregated into a `DoctorReport`. |-| [`health/`](health/README.md) | In-process component health registry, driven by domain events, backing `GET /health`. |-| [`proc_metrics/`](proc_metrics/README.md) | Cross-platform process (and process-tree) RSS sampling used by the RSS benchmark harness. |-| [`service/`](service/README.md) | Installs the core as a per-user OS service and drives self-restart / graceful shutdown. |-| [`socket/`](socket/README.md) | The persistent Socket.IO client that keeps the core connected to the hosted backend. |-| [`startup/`](startup/README.md) | One-shot workspace migrations run during core boot. |-| [`update/`](update/README.md) | Self-update: checks GitHub Releases, downloads and stages a new binary, and triggers a restart. |+| [`about_app/`](about_app/README.md) | The user-facing capability catalog: what each feature does, where it is in the UI, its maturity, and its privacy disclosure. A compile-time static table with list, lookup, and search. Update it when user-visible capabilities change. |+| [`connectivity/`](connectivity/README.md) | `connectivity_diag` (backend socket state, loop liveness, core PID and port, a loopback port probe) and the listen-port picker the core uses to bind its HTTP listener, including stale-listener takeover and the Windows excluded-port fallback. |+| [`cost/`](cost/README.md) | Token usage and USD cost: an append-only `costs.jsonl` ledger, day and month aggregates, the 7-day dashboard, the static pricing and context-window catalog (`catalog.rs`), and managed vs BYOK route classification (`route.rs`). |+| [`doctor/`](doctor/README.md) | Self-checks over config, workspace, the daemon state file, the environment, the memory engine, and the embedding model, aggregated into a severity-tagged `DoctorReport`. Powers `openhuman doctor` and the Settings health view. |+| [`health/`](health/README.md) | The in-process component health registry, the `HealthVerdict` behind `GET /health`, and static system info. |+| [`proc_metrics/`](proc_metrics/README.md) | Cross-platform RSS and peak-RSS sampling for this process and its tree. Used by the `rss_bench` and `library_profile` bins in `crates/openhuman-cli`. No RPC. |+| [`service/`](service/README.md) | Installs the core as a per-user OS service (LaunchAgent, systemd user unit, Windows scheduled task), self-restart and graceful shutdown over the bus, daemon-host tray preferences, and a file-backed mock for E2E (`OPENHUMAN_SERVICE_MOCK`). |+| [`socket/`](socket/README.md) | The persistent Socket.IO client to the backend: hand-rolled Engine.IO and Socket.IO handshakes over a WebSocket, reconnect with backoff, a token provider re-read on every reconnect, redirect following, and inbound event dispatch. |+| [`startup/`](startup/README.md) | One-shot workspace migrations run during boot (session layout, welcome-agent artifacts). Errors are logged and never abort startup. |+| [`update/`](update/README.md) | Self-update from GitHub Releases: check, download and atomically stage the platform binary, then restart (`SelfReplace`) or leave it for a supervisor. Plus the periodic background checker. |++## Key types and entry points++There is no type shared across the family. The ones contributors touch most:++- `HealthSnapshot`, `mark_component_ok`, `mark_component_error` (`health/`)+ for reporting component state.+- `CostTracker` and `cost::init_global` / `try_global` / `rebind_global`+ (`cost/global.rs`). The tracker is bound to one workspace, and signing in or+ out rebinds it so usage lands in the right user's ledger.+- `DoctorReport` (`doctor/core/types.rs`).+- `SocketManager` and `token_provider_from_config` (`socket/`).+- `pick_listen_port_for_host` and its variants (`connectivity/`), used by the+ RPC host when binding.+- `ServiceStatus` and the restart and shutdown publishers (`service/`).++## RPC / CLI surface++Method names are `openhuman.<namespace>_<function>`.++| Namespace | Functions |+| --- | --- |+| `about_app` | `list`, `lookup`, `search` |+| `connectivity` | `diag` |+| `cost` | `get_dashboard`, `get_daily_history`, `get_summary`, `get_usage_log` |+| `doctor` | `report`, `models` |+| `health` | `snapshot`, `system_info` |+| `service` | `install`, `start`, `stop`, `status`, `uninstall`, `restart`, `shutdown`, `daemon_host_get`, `daemon_host_set` |+| `socket` | `connect`, `connect_with_session`, `disconnect`, `emit`, `state` |+| `update` | `version`, `check`, `apply`, `run` |++Agent tools from this family (registered in `tools/ops.rs`):+`health_snapshot`, `health_system_info`, `doctor_health`, `doctor_models`,+`cost_get_dashboard`, `cost_get_daily_history`, `cost_get_summary`,+`service_restart`, `service_shutdown`, and `daemon_host_prefs_set`. The+lifecycle mutators ship off by default through the user tool filter.-## How it fits+## Boundaries-Everything under `platform/` answers questions about the process itself rather than about what the agent is doing: is it running, is it healthy, what did it cost, is it connected, does it need an update. Most of these domains expose a small `*.rs` RPC surface registered into the global controller registry in `crates/openhuman-core/src/core/all.rs`, the same way business-domain modules do, so the frontend and CLI reach them through ordinary JSON-RPC rather than a side channel.+- The JSON-RPC server, `/health` route, and Socket.IO server the frontend+ connects to belong to `crates/openhuman-rpc`. `platform::socket` is the+ core's outbound client to the backend, not that server.+- The backend URL and transport belong to the installed backend transport+ (`crates/openhuman-tinyhumans`). `socket` asks for them; with no transport+ installed it does not auto-connect.+- The session credential belongs to the host's session owner. `socket` reads+ whatever token the core was given through `auth.set_credential`.+- How the desktop shell supervises the core belongs to+ `crates/openhuman-app/src/core_process.rs`.-A few subfolders read state that other domains own instead of maintaining their own: `doctor` reads the daemon state file that `service` writes and the memory-tree database that `memory` owns, and `health` is driven entirely by events other domains publish rather than by direct calls into them.+## Gotchas-## Key types+- `update` mutations are fail-closed behind+ `config.update.rpc_mutations_enabled`, and download URLs and asset names are+ validated at the RPC boundary.+- Cost history is recorded even when `cost.enabled` is off+ (`record_usage_unconditional`), and the local limits apply only to records+ classified as managed. BYOK and local calls are recorded but never gated.+- `socket` reports `Reconnecting` between attempts and `Disconnected` only+ when the loop is not running. The frontend's connectivity chip depends on+ that distinction.-There is no single shared type across `platform/`; each subfolder defines its own (`DoctorReport`, `HealthSnapshot`, `CostTracker`, `ServiceStatus`, and so on). See each subfolder's README for its public surface.+## Tests-## Where next+Each member keeps sibling `*_tests.rs` files. The `service` mock backend makes+lifecycle tests deterministic.-Start with the subfolder README for the concern you're touching. `service/README.md` and `update/README.md` are the pair to read together if you're changing how the core restarts itself; `health/README.md` and `connectivity/README.md` if you're changing what "is the app connected" means to the frontend.+```bash+cargo test -p openhuman platform::+pnpm debug rust platform::+```