Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/ci-paths-filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ rust-core:
- 'Cargo.toml'
- 'crates/openhuman-core/**'
- 'crates/openhuman-embed/**'
- 'crates/openhuman-platform/**'
- 'crates/openhuman-tinyhumans/**'
- 'crates/openhuman-rpc/**'
- 'crates/openhuman-cli/**'
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Virtual workspace root. Members: `crates/openhuman-core` (package `openhuman`,
# the core library), `crates/openhuman-embed` (library facade),
# the core library), `crates/openhuman-platform` (OS service managers and
# update staging, a leaf below the core), `crates/openhuman-embed` (library facade),
# `crates/openhuman-rpc` (JSON-RPC envelopes, client and server, and the on-disk
# session store hosts install, above the core), `crates/openhuman-tinyhumans`
# (SDK-backed backend transport + login/session ownership for hosts),
Expand All @@ -17,6 +18,7 @@ members = [
"crates/openhuman-core",
"crates/openhuman-embed",
"crates/openhuman-modules-linked",
"crates/openhuman-platform",
"crates/openhuman-rpc",
"crates/openhuman-tinyhumans",
"crates/openhuman-tui",
Expand All @@ -36,7 +38,7 @@ license = "GPL-3.0-only"
repository = "https://github.com/tinyhumansai/openhuman"

[workspace.dependencies]
# The library chain: core -> embed -> tinyhumans -> rpc -> app/cli/tui. Hosts
# The library chain: platform -> core -> embed -> tinyhumans -> rpc -> app/cli/tui. Hosts
# name `openhuman-rpc` only (`scripts/ci/check-crate-chain.mjs`). There is no
# `openhuman-core` entry on purpose: one spelled here carried the core's whole
# `default` feature set into whichever member named it.
Expand Down
22 changes: 14 additions & 8 deletions crates/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# crates

The Rust side of OpenHuman is seven crates. One library holds the business
logic; the others are layers above it that add a public facade, the JSON-RPC
protocol, the hosted TinyHumans connection, and the three executables people
run (the CLI binary, the terminal UI and the desktop app). Six of them are
members of the root Cargo workspace; `openhuman-app` is excluded and builds
The Rust side of OpenHuman is eight crates. One library holds the business
logic; one leaf below it holds the OS-facing pieces that need no product
configuration; the others are layers above it that add a public facade, the
JSON-RPC protocol, the hosted TinyHumans connection, and the three executables
people run (the CLI binary, the terminal UI and the desktop app). Seven of them
are members of the root Cargo workspace; `openhuman-app` is excluded and builds
with `--manifest-path crates/openhuman-app/Cargo.toml`.

## The crates

| Crate | Package / lib | What it is |
| --- | --- | --- |
| [`openhuman-core`](openhuman-core/README.md) | package `openhuman`, lib `openhuman_core` | The core library: every business domain under `src/<domain>/`, the controller contract and registry, in-process dispatch, the event bus and the CLI dispatcher. No JSON-RPC server, no backend client, no binary targets. |
| [`openhuman-platform`](openhuman-platform/README.md) | `openhuman-platform` | A leaf below the core: the per-user OS service managers (launchd, systemd user unit, scheduled task, the E2E mock) behind a `ServiceSpec`, and GitHub-release update staging behind an `UpdateSource` and an error-report callback. No `Config`, event bus or RPC envelope. |
| [`openhuman-embed`](openhuman-embed/README.md) | `openhuman-embed` | The typed library facade for running the core in-process in another product (`Runtime` then `Agent`), plus the host presets, `embed::process` lifecycle helpers and the curated facades the hosts use. |
| [`openhuman-rpc`](openhuman-rpc/README.md) | `openhuman-rpc` | JSON-RPC 2.0 over the core: envelopes, the HTTP client (`http-client`), the server with Socket.IO and the `run_server*` entry points (`server`), the on-disk session store (`session-store`), and `host::{cli, desktop, tui}`, the shared host boot. Re-exports `embed` and `tinyhumans`: the one dependency a host needs. |
| [`openhuman-tinyhumans`](openhuman-tinyhumans/README.md) | `openhuman-tinyhumans` | The hosted-backend layer, and the only owner of anything hosted: the backend transport port and its SDK implementation, the authenticated client, routes and hosted providers (plugged into the core's generic registries), `install()`, a `RuntimeBuilder` that boots connected, the hosted RPC proxies, the login and session owner, and the Jev ranker. The only crate allowed to depend on `tinyhumans-sdk`. |
Expand All @@ -23,7 +25,7 @@ with `--manifest-path crates/openhuman-app/Cargo.toml`.

Arrows point from a crate to what it depends on (normal `[dependencies]`,
taken from each [`Cargo.toml`](../Cargo.toml)). It is a strict chain: each crate
names only the layer directly below it.
names only the layer directly below it, and the core names only its leaves.

```text
openhuman-app openhuman-tui openhuman-cli (hosts)
Expand All @@ -42,14 +44,17 @@ names only the layer directly below it.
| process helpers, facades
v
openhuman-core domains, controller registry,
generic registries
| generic registries
v
openhuman-platform OS service managers, update staging
```

The same edges as a list:

| Crate | Depends on (first-party, normal) |
| --- | --- |
| `openhuman-core` | none |
| `openhuman-platform` | none |
| `openhuman-core` | `openhuman-platform` |
| `openhuman-embed` | `openhuman-core` |
| `openhuman-tinyhumans` | `openhuman-embed` (plus [`vendor/tinyhumans-sdk`](../vendor/tinyhumans-sdk/)) |
| `openhuman-rpc` | `openhuman-tinyhumans` |
Expand Down Expand Up @@ -118,6 +123,7 @@ README for the explicit `[[test]]` entries they need.
- [`crates/openhuman-cli/README.md`](openhuman-cli/README.md): the openhuman-cli crate README.
- [`crates/openhuman-core/README.md`](openhuman-core/README.md): the openhuman-core crate README.
- [`crates/openhuman-embed/README.md`](openhuman-embed/README.md): the openhuman-embed crate README.
- [`crates/openhuman-platform/README.md`](openhuman-platform/README.md): the openhuman-platform crate README.
- [`crates/openhuman-rpc/README.md`](openhuman-rpc/README.md): the openhuman-rpc crate README.
- [`crates/openhuman-tinyhumans/README.md`](openhuman-tinyhumans/README.md): the openhuman-tinyhumans crate README.
- [`crates/openhuman-tui/README.md`](openhuman-tui/README.md): the openhuman-tui crate README.
Expand Down
20 changes: 20 additions & 0 deletions crates/openhuman-app/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/openhuman-app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ pub fn run() {
// after the <key>ProgramArguments</key> marker. The
// service installer always writes it as an absolute
// path to the openhuman-core binary (see
// crates/openhuman-core/src/platform/service/macos.rs).
// crates/openhuman-platform/src/service/macos.rs).
let after_key = contents.split("<key>ProgramArguments</key>").nth(1)?;
let start = after_key.find("<string>")? + "<string>".len();
let rest = &after_key[start..];
Expand Down
4 changes: 4 additions & 0 deletions crates/openhuman-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ crate-type = ["rlib"]
# reached only through the loaded module's bus endpoints.
tinyflows = { path = "../../vendor/tinyflows/crates/tinyflows" }
tinyflows-bus = { path = "../../vendor/tinyflows/crates/tinyflows-bus" }
# OS service managers and GitHub-release update staging. A leaf below the core
# (`scripts/ci/check-crate-chain.mjs`) that knows nothing of `Config`, the event
# bus or RPC envelopes; `platform::service` / `platform::update` bind it.
openhuman-platform = { path = "../openhuman-platform" }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the crate-chain contract for the new leaf

Any subsequent change under the repository root is required to follow AGENTS.md, but that file still declares the strict Rust chain beginning at openhuman-core and omits openhuman-platform; this new normal dependency (and the modified checker that accepts it) therefore leaves the authoritative contract contradicting the implemented architecture. Update the root repository map/chain in the same change so contributors do not have to choose between the checked-in rule and CI.

AGENTS.md reference: AGENTS.md:L34-L39

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid, fixed in 32128a8. AGENTS.md (CLAUDE.md is a symlink to it) adds a crates/openhuman-platform/ row to the repository map, and the crate-chain section now says that leaf crates sit below the core, name no OpenHuman crate, and that openhuman-platform is a normal dependency of openhuman-core only. This matches check-crate-chain.mjs, which reports "OK".

# TinyAgents — Rust LLM orchestration framework (LangGraph/LangChain-style):
# durable state graphs, agent-loop harness, model/tool registries, REPL +
# `.rag` workflow language. openhuman's agent engine + orchestration run on this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn set_browser_allow_all(enabled: bool) -> Result<Outcome<RuntimeFlagsOut>,

/// Returns the operational status of the agent server.
pub fn agent_server_status() -> Outcome<serde_json::Value> {
let running = crate::platform::service::mock::mock_agent_running().unwrap_or(true);
let running = openhuman_platform::service::mock_agent_running().unwrap_or(true);
log::info!("[config] agent_server_status requested: running={running}");
let payload = json!({
"running": running,
Expand Down
2 changes: 1 addition & 1 deletion crates/openhuman-core/src/config/schema/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub use runtime::{
pub use runtime_agent37::{Agent37RuntimeConfig, DEFAULT_AGENT37_TEMPLATE};
pub use runtime_local_jail::LocalJailConfig;
pub use runtime_openshell::{OpenShellRuntimeConfig, DEFAULT_OPENSHELL_IMAGE};
pub use scheduler_gate::{PauseReason, Policy, SchedulerGateConfig, SchedulerGateMode};
pub use scheduler_gate::{SchedulerGateConfig, SchedulerGateMode};
pub use security::{AuditConfig, SandboxBackend, SandboxConfig};
pub use security_mode::{
JudgeMode, SecurityJudgeDialect, SecurityJudgeRoute, SecurityMode, SecurityModeConfig,
Expand Down
84 changes: 2 additions & 82 deletions crates/openhuman-core/src/config/schema/scheduler_gate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Scheduler-gate configuration — controls when background AI work runs.
//!
//! Consumed by `platform::llm_gate`.
//! Consumed by `platform::llm_gate`, which also owns the `Policy` /
//! `PauseReason` vocabulary this config produces.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -107,87 +108,6 @@ impl Default for SchedulerGateConfig {
}
}

// ── Gate decision vocabulary ────────────────────────────────────────────────
//
// `Policy` and `PauseReason` moved here from the host's
// `platform::llm_gate::policy` because the extracted sync loops read them on
// every tick to decide whether to back off. They are inert `Copy` enums with no
// dependencies. The pure *decision function* that produces a `Policy` from
// sampled signals lives in `platform::resource_admission`; the product config
// adapter, hardware sampling and cooperative wait stay in `platform::llm_gate`.

/// Why the gate is currently paused. Carried by [`Policy::Paused`] so
/// downstream consumers (UI, logging, observability) can surface a
/// specific user-facing reason instead of a generic "paused" label.
///
/// New variants will land alongside #1073's full power-aware work
/// (`OnBattery`, `CpuPressure`); `UserDisabled` covers the existing
/// `SchedulerGateMode::Off` path and `Unknown` is the safe fallback for
/// callers that don't have specific context yet.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PauseReason {
/// User explicitly turned the gate off in config.
UserDisabled,
/// Host on battery and gate's power-aware mode kicked in (#1073).
OnBattery,
/// CPU pressure exceeded the gate threshold (#1073).
CpuPressure,
/// No active app session — background AI work is suspended until the
/// user signs in again. Trumps every other signal: while signed out
/// the host should do *no* LLM-bound work, period. Set by
/// `gate::set_signed_out(true)` from the credentials lifecycle and
/// from 401-detection sites.
SignedOut,
/// Pause reason not yet classified — placeholder while #1073 is in flight.
Unknown,
}

impl PauseReason {
pub fn as_str(self) -> &'static str {
match self {
Self::UserDisabled => "user_disabled",
Self::OnBattery => "on_battery",
Self::CpuPressure => "cpu_pressure",
Self::SignedOut => "signed_out",
Self::Unknown => "unknown",
}
}
}

/// Background-AI scheduling tier. See module docs in `mod.rs` for semantics.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Policy {
Aggressive,
Normal,
Throttled,
/// Gate paused. The `reason` is rendered to users in the memory-sync
/// status UI (#1136) and recorded in observability.
Paused {
reason: PauseReason,
},
}

impl Policy {
pub fn as_str(self) -> &'static str {
match self {
Self::Aggressive => "aggressive",
Self::Normal => "normal",
Self::Throttled => "throttled",
Self::Paused { .. } => "paused",
}
}

/// `Some(reason)` when paused, `None` otherwise. Convenience for
/// callers that only need the reason and don't want to pattern-match
/// the whole enum (UI badges, log line construction).
pub fn pause_reason(self) -> Option<PauseReason> {
match self {
Self::Paused { reason } => Some(reason),
_ => None,
}
}
}

#[cfg(test)]
#[path = "scheduler_gate_tests.rs"]
mod tests;
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ fn scheduler_defaults_are_pinned_to_safe_auto_limits() {
}

#[test]
fn scheduler_mode_serde_and_policy_strings_are_stable() {
fn scheduler_mode_serde_strings_are_stable() {
let config: SchedulerGateConfig = toml::from_str("mode = \"always_on\"").unwrap();
assert_eq!(config.mode, SchedulerGateMode::AlwaysOn);
assert_eq!(config.mode.as_str(), "always_on");
let paused = Policy::Paused {
reason: PauseReason::SignedOut,
};
assert_eq!(paused.as_str(), "paused");
assert_eq!(paused.pause_reason(), Some(PauseReason::SignedOut));
assert_eq!(PauseReason::SignedOut.as_str(), "signed_out");
assert_eq!(Policy::Normal.pause_reason(), None);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
use super::types::RuntimeSnapshot;
use super::LOG_PREFIX;
use crate::config::Config;
use crate::platform::service::ServiceState;
use crate::platform::service::ServiceStatus;
use log::{debug, warn};
use once_cell::sync::Lazy;
use openhuman_platform::service::{ServiceState, ServiceStatus};
use parking_lot::Mutex;
use std::path::PathBuf;
use std::time::{Duration, Instant};
Expand Down
2 changes: 1 addition & 1 deletion crates/openhuman-core/src/desktop/app_state/ops/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Serde types exchanged with the frontend: the persisted local app-state
//! blob, the patch applied to it, and the polled `app_state_snapshot` shape.

use crate::platform::service::ServiceStatus;
use openhuman_platform::service::ServiceStatus;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use tinyinference_local::status::LocalAiStatus;
Expand Down
2 changes: 1 addition & 1 deletion crates/openhuman-core/src/desktop/app_state/ops_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ fn degraded_runtime_snapshot_has_expected_degraded_fields() {
assert!(
matches!(
snapshot.service.state,
crate::platform::service::ServiceState::Unknown(_)
openhuman_platform::service::ServiceState::Unknown(_)
),
"service state should be Unknown in degraded snapshot"
);
Expand Down
4 changes: 2 additions & 2 deletions crates/openhuman-core/src/platform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ the frontend which of its connection channels is broken.
| [`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`). |
| [`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 openhuman-benchmarks (`profile/`). 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`). |
| [`service/`](service/README.md) | Installs the core as a per-user OS service (LaunchAgent, systemd user unit, Windows scheduled task, through the managers in [`openhuman-platform`](../../../openhuman-platform/README.md)), 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. |
| [`update/`](update/README.md) | Self-update from GitHub Releases: check, download and atomically stage the platform binary (staging in [`openhuman-platform`](../../../openhuman-platform/README.md)), then restart (`SelfReplace`) or leave it for a supervisor. Plus the periodic background checker. |

## Key types and entry points

Expand Down
2 changes: 1 addition & 1 deletion crates/openhuman-core/src/platform/llm_gate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Gates background AI work (embeddings, summarisation, triage, local inference) on
| [`crates/openhuman-core/src/platform/llm_gate/gate.rs`](./gate.rs) | The process-wide wiring: the `SharedCore`, the signed-out override, the resume `Notify`, the single-slot LLM semaphore, `init_global(SchedulerGateConfig)`/`update_config`/`current_policy`/`wait_for_capacity`, and the per-tokio-runtime test-state scaffolding. |
| [`crates/openhuman-core/src/platform/llm_gate/throttle.rs`](./throttle.rs) | The machinery: `GateCore` (config + signals + policy), the 30s `spawn_sampler` task, `wait_for_capacity` over a caller-owned semaphore, and the `LlmPermit` RAII guard. |
| [`crates/openhuman-core/src/platform/llm_gate/signals.rs`](./signals.rs) | `sample(&SignalEnv)`: battery (via `starship_battery`, behind the `scheduler-gate` feature), CPU usage (via `sysinfo`, two-refresh delta), and server/container detection. |
| [`crates/openhuman-core/src/platform/llm_gate/decide.rs`](./decide.rs) | Config/policy adapter: `decide(signals, cfg) -> Policy` maps `SchedulerGateConfig` to `platform::resource_admission::Limits` and maps `Admission` to `Policy`. The pure decision lives in [`platform/resource_admission`](../resource_admission/mod.rs). `Policy` / `PauseReason` live beside `SchedulerGateConfig` in `config::schema::scheduler_gate`. Evaluation order: user mode override → server mode → power-aware stand-down → hard CPU ceiling → battery/CPU headroom. |
| [`crates/openhuman-core/src/platform/llm_gate/decide.rs`](./decide.rs) | The pure decision and its vocabulary: `Signals`, `Policy`, `PauseReason`, and `decide(signals, &SchedulerGateConfig) -> Policy` (thresholds clamped). Evaluation order: user mode override → server mode → power-aware stand-down → hard CPU ceiling → battery/CPU headroom. `SchedulerGateConfig` itself stays in `config::schema::scheduler_gate`. |
| `SIGNAL_ENV` in `gate.rs` | The env-override names: `OPENHUMAN_ON_AC_POWER`, `OPENHUMAN_BATTERY_CHARGE`, `OPENHUMAN_DEPLOYMENT` (plus the Kubernetes / `/.dockerenv` heuristics). |

## Public surface
Expand Down
Loading
Loading