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
Merge remote-tracking branch 'upstream/main' into readme-pitch
Steven Enamakele7d9bb2ce9bf
diff --cc crates/openhuman-core/src/core/runtime/README.mdindex 1b8009ac24,6b12a7c999..1a553e2f48--- a/crates/openhuman-core/src/core/runtime/README.md+++ b/crates/openhuman-core/src/core/runtime/README.md@@@ -134,9 -134,64 +134,64 @@@ by `CoreRuntime::invoke`); `CoreContextprocess-wide default context when no scope is active, which is what letsexisting single-tenant call sites keep working unmodified.+ ## Operating mode: `SingleUser` and `Saas`++ `runtime/mode.rs` holds the process mode. `SingleUser` is today's+ behaviour and the default: the desktop app, the CLI and embedders. `Saas`+ serves many users from one process, one agent per user, behind a trusted+ gateway that authenticates them. The mode belongs to the process, not to any+ user's `Config`. The first SaaS boot locks it (`lock_mode`), and from then on+ `CoreContext::init_with_config` refuses every non-SaaS core. Code asks+ `is_saas()`, which reads an unset slot as `SingleUser`.++ `openhuman-core run --mode saas --saas-config <file>` (or+ `OPENHUMAN_MODE=saas`, which can raise the mode but never lower it) boots+ through `runtime/saas.rs`:++ - `SaasConfig` is the **operator's** file. It sets `root`,+ `service_token_file` (defaults to `<root>/service.token`), `tool_allowlist`,+ `rpc_allowlist_extra`, `max_agents_open`, `idle_evict_secs`,+ `shared_backend_api_key` and `custom_definitions`. Unknown keys are refused.+ - `runtime/boot_guard.rs` refuses the boot, listing every problem at once,+ when:+ - the host kind is not `Saas`;+ - services or domains go beyond `ServiceSet::saas()` / `DomainSet::saas()`;+ - single-user or back-door environment variables are set+ (`OPENHUMAN_WORKSPACE`, `OPENHUMAN_DEV_CONNECT`, backend tokens,+ `OPENHUMAN_CORE_TOKEN`, approval gate or sandbox switched off);+ - an allowlist is non-empty before its isolation has shipped;+ - the root is relative, missing, world-writable or inside `~/.openhuman`;+ - the service token is missing, readable by others, or shorter than 32 bytes.+ - The operator plane boots with its own config under `<root>/operator/`, so+ it never resolves `~/.openhuman` or an `active_user.toml`. The gateway+ bearer is the RPC token.++ The SaaS presets are closed. `DomainSet::saas()` enables only the operator+ plane (`DomainGroup::Operator`, the `user_agents.*` controllers), so a SaaS+ core answers its built-ins (`core.*`, `/health`, `/schema`) and provisioning,+ and nothing a user could reach, until each family's per-user isolation lands.+ `saas::build` installs the process's `user_agents::AgentHost`. Each open user+ agent runs under a context derived from the operator's, with its own forced+ config and `session_agent` (see `user_agents/README.md`).++ Two guards keep SaaS work from falling back to process-wide state:++ - **Config redirect.** In SaaS, `Config::load_or_init()` returns the config the+ current context carries and fails outside any context+ (`config/schema/load/saas_scope.rs`). It never resolves+ `OPENHUMAN_WORKSPACE`, `active_user.toml` or `~/.openhuman`.+ - **Scoped spawns.** `runtime/spawn.rs`'s `spawn_scoped` /+ `spawn_blocking_scoped` carry the caller's `CoreContext` and memory identity+ into the spawned task. `scripts/ci/check-saas-ambient.mjs` (`pnpm+ saas:ambient`) ratchets the bare spawns, direct `load_or_init` calls,+ environment writes and `home_dir()` lookups that remain.++ `DomainSet` lives in `runtime/domain_set.rs` and `DomainGroup` in+ `core/domain_group.rs`. Both are re-exported from their old paths.+## Shared tokio tuning constants-`runtime/mod.rs` declares two constants every multi-thread runtime that may+[`runtime/mod.rs`](../../runtime/mod.rs) declares two constants every multi-thread runtime that mayhost an agent turn must set:- `AGENT_WORKER_STACK_BYTES` (20 MiB): a single agent turn is a very largediff --cc crates/openhuman-core/src/platform/cost/README.mdindex 3c2b128bf5,062119859d..86709c480a--- a/crates/openhuman-core/src/platform/cost/README.md+++ b/crates/openhuman-core/src/platform/cost/README.md@@@ -22,9 -22,12 +22,12 @@@ Local API-usage cost tracking for the a| `crates/openhuman-core/src/platform/cost/global.rs` | Process-global `OnceCell<Arc<CostTracker>>` singleton: `init_global`, `try_global`, `record_provider_usage`, and `build_token_usage` (provider `UsageInfo` → `TokenUsage`). || `crates/openhuman-core/src/platform/cost/rpc.rs` | RPC-facing handlers (`dashboard`, `daily_history`, `summary`) returning `Outcome<Value>`; DTO types; `resolve_tracker` with a cached fallback tracker + error-replay TTL. || `crates/openhuman-core/src/platform/cost/schemas.rs` | Controller schemas + `handle_*` JSON-RPC dispatchers; `all_controller_schemas` / `all_registered_controllers`. |-| `crates/openhuman-core/src/platform/cost/tracker_tests.rs` | Sibling test suite for `tracker.rs` (`#[path]`-included). |+| `crates/openhuman-core/src/platform/cost/tracker_tests.rs` | Sibling test suite for [`tracker.rs`](./tracker.rs) (`#[path]`-included). || `crates/openhuman-core/src/platform/cost/catalog.rs` | Static per-model pricing + context-window catalog (`ModelPrice`, `lookup`, `estimate_cost_usd`, `PRICING_AS_OF`) and the tinyagents model-catalog adapters. || `crates/openhuman-core/src/platform/cost/route.rs` | `CostRoute` / `route_for_model`: derives from the model id whether a record counts against OpenHuman-managed credits or is BYOK/local (#5016). |+ | `crates/openhuman-core/src/platform/cost/scope.rs` | `UsageScope::ambient`: a record's attribution (thread, origin, agent definition, sub-agent task, embedded/SaaS user agent, provider) read from the recording task's turn origin, memory identity and `CoreContext`. |+ | `crates/openhuman-core/src/platform/cost/report.rs` | Pure usage reports over ledger records: `build_report` (group by day/week/month/model/provider/route/agent/thread/origin/session_agent; tokens, charged vs estimated cost, cache-hit ratio) and `build_cache_report` (per-call hits, cold calls, uncached premium). |+ | `crates/openhuman-core/src/platform/cost/budget.rs` | Budgets (`[[cost.budgets]]`): `evaluate` / `check_call` sum a policy's bucket (global, or this call's thread/agent/model/user agent) over its day or month and report warnings and refusals. The agent budget gate (`agent/tinyagents/host/budget_gate.rs`) runs it before every model call. || `crates/openhuman-core/src/platform/cost/tools.rs` | Read-only, default-on LLM tools (`cost_get_dashboard`, `cost_get_daily_history`, …) re-exported through `crates/openhuman-core/src/tools/mod.rs`. |## Public surface@@@ -48,8 -51,14 +51,14 @@@ Namespace `cost` (methods `openhuman.co| `cost_get_daily_history` | `days?` (u32, default 7, clamped `[1, 366]`) | Ordered daily entries, oldest first, gaps zero-filled. || `cost_get_summary` | none | Live session / daily / monthly cost summary. || `cost_get_usage_log` | `days?`, `limit?` | Recent local records, newest first, bounded to 1,000 rows. |+ | `cost_report` | `days?`, `groupBy?`, `filter?` | Totals plus one row per group (most expensive first): calls, input/output/cached/cache-write/reasoning tokens, `cost_usd` split into `charged_usd` / `estimated_usd`, `cache_hit_ratio`. |+ | `cost_cache_report` | `days?`, `filter?`, `limit?` | Per-call prompt-cache hits (newest `limit`), overall `cache_hit_ratio`, `cold_calls` (a repeat call in a thread with no cache read) and `uncached_premium_usd`. |++ Both reports are also CLI commands: `openhuman-core cost report --days 7 --groupBy '["day","agent"]'`, `openhuman-core cost cache_report --filter '{"thread_id":"…"}'`.++ **Attribution.** Every recorded call carries an optional `scope` (`UsageScope`): the thread, what started the turn, the agent definition (or the delegated sub-agent and its task), the embedded/SaaS user agent and the provider. The event bridge passes the provider and sub-agent, and the rest comes from the recording task. Records written before attribution have no `scope` and group as `unknown`.-Handlers load config via `config_rpc::load_config_with_timeout`, then delegate to `rpc.rs`. RPC DTOs (`CostDashboardDto`, `DailyCostEntryDto`, `ModelStatsDto`, `CostSummaryDto`, `UsageLogRecordDto`) add presentation fields not on the domain types: `provider` (derived from the `provider/model` prefix), `percent_of_total`, and dashboard threshold/`enabled` flags from `cost.dashboard`. Usage-log records preserve the persisted token provenance fields (`cached_input_tokens`, `cache_creation_tokens`, `reasoning_tokens`, `cost_source`) for migration audit callers for the dedicated usage-log tab.+Handlers load config via `config_rpc::load_config_with_timeout`, then delegate to [`rpc.rs`](./rpc.rs). RPC DTOs (`CostDashboardDto`, `DailyCostEntryDto`, `ModelStatsDto`, `CostSummaryDto`, `UsageLogRecordDto`) add presentation fields not on the domain types: `provider` (derived from the `provider/model` prefix), `percent_of_total`, and dashboard threshold/`enabled` flags from `cost.dashboard`. Usage-log records preserve the persisted token provenance fields (`cached_input_tokens`, `cache_creation_tokens`, `reasoning_tokens`, `cost_source`) for migration audit callers for the dedicated usage-log tab.## Events@@@ -90,8 -99,35 +99,41 @@@ None. The module has no `bus.rs` and n- All amounts are stored/computed in USD; `currency` is a presentation hint only.- Time bucketing is UTC throughout (`naive_utc().date()`); model is the bucket key for per-model stats, and `provider` is derived from the `provider/model` slash prefix in DTO mapping.+ ## Budgets++ Budgets are opt-in and empty by default:++ ```toml+ [[cost.budgets]]+ name = "monthly cap"+ max_usd = 50.0 # and/or max_tokens+ period = "month" # or "day" (UTC)+ action = "refuse" # or "warn" (default)++ [[cost.budgets]]+ name = "planner per day"+ scope = "agent" # global (default) | thread | agent | model | session_agent+ match = "planner" # omit to apply to each value separately+ period = "day"+ max_usd = 2.0+ warn_fraction = 0.8 # default+ ```++ Before every model call, the agent's budget gate (`OpenHumanBudgetGate::acquire`) sums each policy's bucket from the ledger over its period:++ - **Refuse:** a `refuse` policy at or over its limit refuses the call with `TinyAgentsError::LimitExceeded("BUDGET_EXCEEDED: …")`, before any scheduler slot is taken.+ - **Warn:** a `warn` policy, or any policy past `warn_fraction`, logs a warning.+ - **Unattributed calls:** a call without the policy's attribute is outside it. For example, a call with no thread is outside a per-thread budget.+ - **The call itself counts:** its estimated cost and tokens are added to the bucket's total, so a call that would itself cross a limit is refused.+ - **Invalid caps fail closed:** a negative or NaN `max_usd` refuses (with a warning). A NaN `warn_fraction` uses 0.8, and records with a non-finite cost count as free.+ - **Live policies:** the gate re-reads `[[cost.budgets]]` from the session's `config.toml` on every check, so a change applies to threads already open. It keeps the policies it was built with when the file is missing or does not parse (logged at warn), and always for an embedder-supplied config, whose in-memory budgets are authoritative.+ - **Soft cap under concurrency:** the check reads the ledger and reserves nothing. Calls that start together can each pass, and the overshoot is bounded by the estimates of the calls in flight. Spend is known once a call is recorded; a provider reply with no usage is not recorded and so does not count.+ - **Agent calls only:** the gate covers model calls made through the agent harness. Direct `ChatModel` callers (chat follow-up suggestions, Flow Canvas LLM nodes) are not metered against budgets yet.+ - **No `provider` scope yet:** the gate does not see a call's provider before it is made.+ - **No checking at all** when no budgets are configured, when there is no cost tracker, or when the ledger cannot be read. The budget check never fails a call for a reason of its own.+++## Further reading++- [Parent module (`platform`)](../README.md)+- [Billing and usage](../../../../../gitbooks/features/billing-and-usage.md)+- [Platform and availability](../../../../../gitbooks/features/platform.md)diff --cc scripts/ci/README.mdindex 03030eebb0,469eb5cb2d..40009e736f--- a/scripts/ci/README.md+++ b/scripts/ci/README.md@@@ -6,16 -6,17 +6,17 @@@ authoritative spec; this is an index s| File | Checks || --- | --- |-| `check-openhuman-rust-layout.mjs` (`pnpm rust:layout`) | Every file under `crates/openhuman-core/src` stays under a 750-line ceiling, warning (without failing) past 725; oversized files are pinned at their exact size in `LEGACY_LIMIT_ENTRIES`, once each, and a pinned file that shrinks must lower or drop its pin; forbids inline `#[cfg(test)] mod` blocks and `tests.rs`/`test.rs` filenames; and asserts every root `tests/*.rs` / `examples/*.rs` has a matching `[[test]]`/`[[example]]` entry in `crates/openhuman-core/Cargo.toml`. |-| `check-feature-forwarding.mjs` | The Tauri shell (`crates/openhuman-app/Cargo.toml`, which sets `default-features = false`) forwards exactly the gates in `product-features.txt` — no more, no less — and the library chain that re-declares the core's gates (`openhuman-embed` → `openhuman-tinyhumans` → `openhuman-cli`) forwards every one of them, by target and not just by name. Logic lives in `scripts/lib/feature-forwarding.mjs` (openhuman#4919, openhuman#6364). |-| `product-features.txt` / `product-features.sh` | Source of truth for the shipped desktop product's Cargo feature gates, distinct from `[features] default` (the contributor build). The `.sh` prints them comma-separated for `cargo --features "$(scripts/ci/product-features.sh)"`. |-| `check-module-pins.mjs` + `module-pin-exemptions.json` | A loadable module's registry pin (`crates/openhuman-core/src/modules/registry.rs`) and its `vendor/*` submodule pin must describe the same release (openhuman#5727). The exemptions file records known, expected drift — not a way to silence the gate. Logic lives in `scripts/lib/module-pins.mjs`. |-| `check-submodule-monotonic.mjs` | A `vendor/*` submodule pin may never move backwards onto a commit that is an ancestor of what the base branch already has. |-| `check-toolchain-image.mjs` | The CI image's toolchain, the version-pinned `dtolnay/rust-toolchain@<version>` workflow steps, and `.github/Dockerfile` all match the channel pinned in `rust-toolchain.toml`. |-| `rust-coverage.sh` | Runs the complete product-feature Rust suite under `cargo-llvm-cov`, including every core integration target and the root Rust support crates. |-| `assert-coverage-presence.sh` + `coverage-presence-allowlist.txt` | Fails when an eligible Rust source file produced no lcov records at all, meaning the full product suite never compiled it (openhuman#5593). Allowlist entries must document, inline, which gate excludes the file and why that's intended. |-| `list-feature-gated-rust-tests.mjs` | Prints every file under `crates/openhuman-core/src` that carries tests behind a product feature gate (`voice`, `media`, `web3`, `meet`, `mcp`, `skills`, `flows`, `channels`, `contacts`). `ci-lite.yml`'s `rust-feature-gate-smoke` job diffs the output against a checked-in EXPECTED list so a new gated test file forces the gate-contract test filters to be reviewed (#5022). |-| `check-saas-ambient.mjs` + `saas-ambient-baseline.json` (`pnpm saas:ambient`) | Ratchets code in `crates/openhuman-core/src` that reaches past a SaaS user agent's `CoreContext`: bare `tokio::spawn` / `spawn_blocking` / `std::thread::spawn` (use `core::runtime::spawn_scoped`), direct `Config::load_or_init`, `env::set_var` / `remove_var`, and `home_dir()`. Each existing site is baselined exactly; a new one fails, and a fixed one must be removed with `--write-baseline`. |-| `orch-ip-gate.sh` | Blocks the server-side orchestration "brain" (reasoning/wake graph, its prompts, per-agent model-selection metadata) from re-entering this open client repo. |+| [`check-openhuman-rust-layout.mjs`](check-openhuman-rust-layout.mjs) (`pnpm rust:layout`) | Every file under `crates/openhuman-core/src` stays under a 750-line ceiling, warning (without failing) past 725; oversized files are pinned at their exact size in `LEGACY_LIMIT_ENTRIES`, once each, and a pinned file that shrinks must lower or drop its pin; forbids inline `#[cfg(test)] mod` blocks and `tests.rs`/`test.rs` filenames; and asserts every root `tests/*.rs` / `examples/*.rs` has a matching `[[test]]`/`[[example]]` entry in `crates/openhuman-cli/Cargo.toml`, and that the core manifest declares no target tables. |+| [`check-feature-forwarding.mjs`](check-feature-forwarding.mjs) | The Tauri shell ([`crates/openhuman-app/Cargo.toml`](../../crates/openhuman-app/Cargo.toml), which sets `default-features = false`) forwards exactly the gates in `product-features.txt`, no more, no less, and the library chain that re-declares the core's gates (`openhuman-embed` → `openhuman-tinyhumans` → `openhuman-cli`) forwards every one of them, by target and not just by name. Logic lives in [`scripts/lib/feature-forwarding.mjs`](../lib/feature-forwarding.mjs) (openhuman#4919, openhuman#6364). |+| [`product-features.txt`](product-features.txt) / [`product-features.sh`](product-features.sh) | Source of truth for the shipped desktop product's Cargo feature gates, distinct from `[features] default` (the contributor build). The `.sh` prints them comma-separated for `cargo --features "$(scripts/ci/product-features.sh)"`. |+| [`check-module-pins.mjs`](check-module-pins.mjs) + [`module-pin-exemptions.json`](module-pin-exemptions.json) | A loadable module's registry pin ([`crates/openhuman-core/src/modules/registry.rs`](../../crates/openhuman-core/src/modules/registry.rs)) and its `vendor/*` submodule pin must describe the same release (openhuman#5727). The exemptions file records known, expected drift, not a way to silence the gate. Logic lives in [`scripts/lib/module-pins.mjs`](../lib/module-pins.mjs). |+| [`check-submodule-monotonic.mjs`](check-submodule-monotonic.mjs) | A `vendor/*` submodule pin may never move backwards onto a commit that is an ancestor of what the base branch already has. |+| [`check-toolchain-image.mjs`](check-toolchain-image.mjs) | The CI image's toolchain, the version-pinned `dtolnay/rust-toolchain@<version>` workflow steps, and [`.github/Dockerfile`](../../.github/Dockerfile) all match the channel pinned in [`rust-toolchain.toml`](../../rust-toolchain.toml). |+| [`rust-coverage.sh`](rust-coverage.sh) | Runs the complete product-feature Rust suite under `cargo-llvm-cov`, including every core integration target and the root Rust support crates. |+| [`assert-coverage-presence.sh`](assert-coverage-presence.sh) + [`coverage-presence-allowlist.txt`](coverage-presence-allowlist.txt) | Fails when an eligible Rust source file produced no lcov records at all, meaning the full product suite never compiled it (openhuman#5593). Allowlist entries must document, inline, which gate excludes the file and why that's intended. |+| [`list-feature-gated-rust-tests.mjs`](list-feature-gated-rust-tests.mjs) | Prints every file under `crates/openhuman-core/src` that carries tests behind a product feature gate (`voice`, `media`, `web3`, `meet`, `mcp`, `skills`, `flows`, `channels`, `contacts`). `ci-lite.yml`'s `rust-feature-gate-smoke` job diffs the output against a checked-in EXPECTED list so a new gated test file forces the gate-contract test filters to be reviewed (#5022). |++| [`check-saas-ambient.mjs`](check-saas-ambient.mjs) + [`saas-ambient-baseline.json`](saas-ambient-baseline.json) (`pnpm saas:ambient`) | Ratchets code in `crates/openhuman-core/src` that reaches past a SaaS user agent's `CoreContext`: bare `tokio::spawn` / `spawn_blocking` / `std::thread::spawn` (use `core::runtime::spawn_scoped`), direct `Config::load_or_init`, `env::set_var` / `remove_var`, and `home_dir()`. Each existing site is baselined exactly; a new one fails, and a fixed one must be removed with `--write-baseline`. |+| [`orch-ip-gate.sh`](orch-ip-gate.sh) | Blocks the server-side orchestration "brain" (reasoning/wake graph, its prompts, per-agent model-selection metadata) from re-entering this open client repo. |The complete Rust and frontend coverage suites feed the PR CI Gate'schanged-line diff-cover check (>= 80%) in `ci-lite.yml`.