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: update agent prompts and module docs to reflect new source layout
Steven Enamakelc9d430187d82
diff --git a/.claude/agents/pr-manager-lite.md b/.claude/agents/pr-manager-lite.mdindex 5b25599a6c..ae37e18812 100644--- a/.claude/agents/pr-manager-lite.md+++ b/.claude/agents/pr-manager-lite.md@@ -79,13 +79,13 @@ Classify each comment:- `disagree` / `defer-human` / `question` — surface in final report; never silently dismiss.Also do a standards pass against `CLAUDE.md` / `AGENTS.md` on the diff:-- New Rust functionality lives under `crates/openhuman-core/src/openhuman/<domain>/`, not root-level files.+- New Rust functionality lives under `crates/openhuman-core/src/<domain>/`, not root-level files.- Domain exposure via `schemas.rs` + registry — not ad-hoc branches in `crates/openhuman-core/src/core/cli.rs` / `crates/openhuman-core/src/core/jsonrpc.rs`.- No dynamic `import()` in production `app/src` code.- Frontend `VITE_*` reads go through `app/src/utils/config.ts`.- `crates/openhuman-app` is desktop-only.- Debug logging on new flows; no secrets logged.-- Capability changes update `crates/openhuman-core/src/openhuman/about_app/`.+- Capability changes update `crates/openhuman-core/src/platform/about_app/`.- Files preferably ≤ ~500 lines.### 4. Apply fixes (REQUIRED)diff --git a/.claude/agents/pr-manager.md b/.claude/agents/pr-manager.mdindex 0a03b4cdd5..01ee3b12bb 100644--- a/.claude/agents/pr-manager.md+++ b/.claude/agents/pr-manager.md@@ -78,7 +78,7 @@ Classify each comment:Also do a standards pass against `CLAUDE.md` on the full diff, as a safety net for anything reviewers missed:-- New Rust functionality lives in a subdirectory under `crates/openhuman-core/src/openhuman/`, not root-level `.rs` files.+- New Rust functionality lives in a subdirectory under `crates/openhuman-core/src/<domain>/`, not flat `crates/openhuman-core/src/*.rs` files or `crates/openhuman-core/src/core/`.- Controllers exposed via `schemas.rs` + registry, not ad-hoc branches in `core/cli.rs` / `core/jsonrpc.rs`.- No dynamic `import()` in production `app/src` code.- Frontend reads `VITE_*` via `app/src/utils/config.ts`, not `import.meta.env` directly.diff --git a/.claude/agents/pr-reviewer.md b/.claude/agents/pr-reviewer.mdindex a3f6521c4b..97576b9881 100644--- a/.claude/agents/pr-reviewer.md+++ b/.claude/agents/pr-reviewer.md@@ -47,7 +47,7 @@ Skipping this step produces shallow reviews that miss architectural/consistency**Correctness** — logic bugs, off-by-one, null/undefined, async/await misuse, race conditions, error propagation (`Result<T>` / `RpcOutcome<T>` / thrown errors).**Project standards** (from `CLAUDE.md`)-- New Rust functionality lives in a subdirectory under `crates/openhuman-core/src/openhuman/`, not root-level `.rs` files.+- New Rust functionality lives in a subdirectory under `crates/openhuman-core/src/<domain>/`, not flat `crates/openhuman-core/src/*.rs` files or `crates/openhuman-core/src/core/`.- Controllers exposed via `schemas.rs` + registry, not ad-hoc branches in `core/cli.rs` / `core/jsonrpc.rs`.- No dynamic `import()` in production `app/src` code.- Frontend reads `VITE_*` via `app/src/utils/config.ts`, not `import.meta.env` directly.@@ -66,7 +66,7 @@ Skipping this step produces shallow reviews that miss architectural/consistency**UX / UI** (frontend) — accessibility, keyboard nav, loading/error/empty states, mobile responsiveness.-**Documentation** — rustdoc/comments match new behavior; `AGENTS.md` / architecture docs updated for rule changes; capability catalog (`crates/openhuman-core/src/openhuman/about_app/`) updated for user-facing feature changes.+**Documentation** — rustdoc/comments match new behavior; `AGENTS.md` / architecture docs updated for rule changes; capability catalog (`crates/openhuman-core/src/platform/about_app/`) updated for user-facing feature changes.### 5. Classify findings@@ -129,13 +129,13 @@ sequenceDiagram### 💡 Refactor / suggestion-#### 3. `crates/openhuman-core/src/openhuman/bar/ops.rs:200-240` — <short title>+#### 3. `crates/openhuman-core/src/bar/ops.rs:200-240` — <short title><…>## Nitpicks (<count>)<One-line items, file:line, optional one-line fix. No code blocks needed unless the fix is non-obvious.>- `path/to/file.ts:15` — prefer `const` over `let`; not reassigned.-- `crates/openhuman-core/src/openhuman/x/mod.rs:3` — unused import `std::collections::HashMap`.+- `crates/openhuman-core/src/x/mod.rs:3` — unused import `std::collections::HashMap`.## Questions for the author (<count>)- `path/to/file.ts:88` — <question; something genuinely unclear from the diff>@@ -190,7 +190,7 @@ cd app && pnpm lintcd app && pnpm format # auto-fixcd app && pnpm test:unit-# Rust (if src/ or crates/openhuman-app changed)+# Rust (if crates/ or tests/ changed)cargo fmt --manifest-path Cargo.tomlcargo check --manifest-path Cargo.tomlcargo check --manifest-path crates/openhuman-app/Cargo.tomldiff --git a/crates/openhuman-core/src/core/socketio.rs b/crates/openhuman-core/src/core/socketio.rsindex 4e59573ff6..b1faa06642 100644--- a/crates/openhuman-core/src/core/socketio.rs+++ b/crates/openhuman-core/src/core/socketio.rs@@ -1,3 +1,29 @@+//! Socket.IO live-event bridge to the desktop shell.+//!+//! `spawn_web_channel_bridge` subscribes to a handful of domain broadcast+//! channels — web-chat events, dictation hotkeys, overlay attention bubbles+//! (`crate::desktop::overlay::subscribe_attention_events`, see+//! `desktop/overlay/README.md`), core notifications, transcription results,+//! and shell companion state — and fans each one out to every connected+//! Socket.IO client, emitting both a colon- and an underscore-separated event+//! name for frontend compatibility. `COMPANION_STATE_BUS` is a broadcast+//! channel dedicated to shell-originated companion lifecycle events: the+//! companion implementation itself lives in the Tauri shell, but the native+//! macOS notch WKWebView has no Tauri IPC bridge and connects to the+//! embedded core's Socket.IO endpoint directly, so this module keeps a+//! transport-only seam for it rather than reintroducing a core-side+//! companion domain.+//!+//! The socketioxide/axum transport bodies (the actual `SocketIo` server,+//! connection handlers, and `spawn_web_channel_bridge`) are gated behind the+//! `http-server` feature (#5048). The event payload types further down+//! (`WebChannelEvent`, `TurnUsagePayload`, `SubagentUsagePayload`,+//! `SubagentProgressDetail`) stay compiled in every build regardless — around+//! ten always-on domains (`web_chat`, `cron`, `channels`, `agent`, …)+//! construct them — so only the transport surface is gated, not the types+//! (a "type carve-out"; see AGENTS.md). `pub mod socketio;` in `core::mod` is+//! intentionally NOT gated for the same reason.+use serde::Deserialize;use serde::Serialize;use serde_json::Value;diff --git a/crates/openhuman-core/src/inference/local/README.md b/crates/openhuman-core/src/inference/local/README.mdnew file mode 100644index 0000000000..4b50036815--- /dev/null+++ b/crates/openhuman-core/src/inference/local/README.md@@ -0,0 +1,89 @@+# local++Local AI runtime manager: Ollama, LM Studio, and Piper sub-process+lifecycle, plus the RPC surface used to prompt/summarize/embed against the+active local model. Was previously `local_ai/` (pre-consolidation+`src/openhuman/` layout); see `../README.md` for the wider `inference` domain.++## Key files++| File / dir | Role |+| --- | --- |+| `mod.rs` | Re-exports `super::{device, model_ids, parse, paths, presets, sentiment, types}` under `local::` (compatibility for files migrated from `local_ai/`); `pub use core::*`, `pub use ops as rpc`, `pub use service::LocalAiService`. |+| `core.rs` | `LocalAiService` singleton (`global`/`try_global`), `model_artifact_path`. |+| `ops.rs` + `ops_part_0{1,2}.rs` | RPC entry points: `local_ai_status/prompt/summarize/vision_prompt/embed/transcribe[_bytes]/tts/chat`, `agent_chat[_simple]`, `local_ai_should_react` (`ReactionDecision`), assets/downloads status. |+| `schemas.rs` | Local-runtime `inference.*` controller schemas + handlers (see RPC below); exported as `all_local_inference_controller_schemas` / `all_local_inference_registered_controllers`. |+| `ollama.rs` | `ollama_base_url[_from_config]`, `validate_ollama_url`. |+| `lm_studio.rs` | LM Studio base-url resolution, adopt vs spawn. |+| `install.rs`, `install_piper.rs`, `voice_install_common.rs` | Ollama/Piper download and install; shared download-progress plumbing. No Whisper install any more — local STT was retired (`config/migrations/retire_local_whisper_stt.rs`). |+| `model_requirements.rs` | `MIN_CONTEXT_TOKENS`, `evaluate_context`, `ContextEligibility` — minimum-context-window floor enforcement. |+| `profile.rs` | `LocalProviderProfile` per-provider-type capability metadata (tool-dispatch strategy, context-window defaults, request-body extras like `options.num_ctx`, `think` suppression) consulted by the factory and agent harness. |+| `process_util.rs` | Shared subprocess helpers (`pub(crate)`, notably the Windows `CREATE_NO_WINDOW` flag) reused by `agent::host_runtime`. |+| `provider.rs` | `LocalAiProvider` (Ollama / LM Studio) selection helper. |+| `service/` | `LocalAiService` impl, split by concern (below). |++## `service/` split++| File | Role |+| --- | --- |+| `mod.rs` | `LocalAiService` struct (`status`, `bootstrap_lock`, `http`, `owned_ollama`), `has_owned_ollama`, `inject_owned_ollama` (test bridge). |+| `bootstrap.rs` | Detect/spawn/adopt the local runtime on first use. |+| `lm_studio.rs`, `model_rpc.rs` | LM Studio-specific and generic model-RPC plumbing. |+| `public_infer.rs` | Chat/vision/summarize/embed entry points called from `ops.rs`. |+| `speech.rs` | `transcribe`, `transcribe_with_prompt`, `tts` — delegates STT to `crate::voice::create_stt_provider` (cloud/engine-configurable) and TTS to the local Piper install. |+| `transcription.rs` | `TranscriptionResult` — provider-neutral transcription result type. It outlived the bundled whisper.cpp engine that introduced it; the shape is still the contract with `channels::host::adapters`. |+| `vision_embed.rs` | Vision-prompt and embedding entry points. |+| `spawn_marker.rs` | Marks/detects an OpenHuman-spawned child so ownership survives a process restart. |+| `assets.rs` + `assets_impl_01_part_0{1,2}.rs` | Asset status and download-progress tracking. |+| `ollama_admin/` | Ollama daemon lifecycle, split by concern: `binary` (resolve/verify the executable), `diagnostics`, `health` (`test_ollama_connection` in `util.rs`), `model_pull`, `server` (start/stop, adopt vs own). |++## Singleton lifecycle++`local::global(config)` lazily initializes a process-wide `Arc<LocalAiService>`+behind a `once_cell::sync::OnceCell`; `try_global()` returns `None` instead of+creating it, for shutdown paths that should no-op rather than stand up the+service just to tear it down. An **owned** `ollama serve` child (one this+process spawned) is killed on exit; an **adopted** daemon (already running on+`:11434` when OpenHuman started) is left alone — `LocalAiService::owned_ollama`+tracks the distinction, and `has_owned_ollama`/`inject_owned_ollama` exist so+integration tests can inspect or set up that state without a real Ollama+binary.++Model artifacts live under `<root>/models/local-ai/`+(`core.rs::model_artifact_path`).++## RPC / controllers++`inference.*` controllers registered from this module (`schemas.rs`,+`ops.rs`/`ops_part_0{1,2}.rs`), aggregated into the domain-wide surface by+`crates/openhuman-core/src/inference/mod.rs` and wired into the registry by+`core/all.rs` (`crate::inference::all_local_inference_registered_controllers()`,+alongside `all_inference_registered_controllers()`): `agent_chat`,+`agent_chat_simple`, `transcribe`, `transcribe_bytes`, `tts`, `assets_status`,+`downloads_progress`, `download_asset`, `install_piper`,+`piper_install_status`, `test_connection`. Chat/vision/summarize/embed and+device/preset RPCs live one level up in `inference/schemas.rs` and delegate+into `local::rpc` (`ops.rs`).++## Consumers++`grep -rn 'inference::local::' crates/openhuman-core/src` shows the main+callers outside this module: `voice/ops.rs` (STT/TTS RPC), `inference/ops.rs`+and `inference/provider/factory_part_0{1,3,4}.rs` (routing into the local+runtime as a chat-model backend), `inference/embeddings/factory.rs` (Ollama+embedding provider), `agent/host_runtime.rs` and `agent/tinyagents/mod_part_03.rs`+(local-provider-aware agent tooling), and `runtime/python_server/{kompress,spacy}.rs`.++## Tests++- Per-file `*_tests.rs` (`core_tests.rs`, `install_tests.rs`,+ `install_piper_tests.rs`, `lm_studio_tests.rs`, `model_requirements_tests.rs`,+ `ollama_tests.rs`, `ops_tests.rs`, `process_util_tests.rs`, `profile_tests.rs`,+ `provider_tests.rs`, `schemas_tests.rs`, `voice_install_common_tests.rs`).+- `service/*_tests.rs` (`bootstrap_tests.rs`, `model_rpc_tests.rs`,+ `public_infer_tests.rs`, `spawn_marker_tests.rs`, `vision_embed_tests.rs`,+ `ollama_admin_tests*.rs`).+- Tests that touch the runtime singleton or shared config serialize through+ `inference_test_guard()` (a process-global mutex defined in `mod.rs`,+ re-exported through `inference::mod.rs`) since `LocalAiService` and `Config`+ are shared process state.diff --git a/crates/openhuman-core/src/inference/local/service/ollama_admin/mod.rs b/crates/openhuman-core/src/inference/local/service/ollama_admin/mod.rsindex 391360255a..5789c6bf71 100644--- a/crates/openhuman-core/src/inference/local/service/ollama_admin/mod.rs+++ b/crates/openhuman-core/src/inference/local/service/ollama_admin/mod.rs@@ -1,4 +1,7 @@-// Sub-modules split by concern from the original ollama_admin.rs (1586 lines).+//! Ollama daemon lifecycle: binary resolution, health checks, model pulls,+//! diagnostics, and start/stop/adopt handling for `ollama serve`.+//!+//! Sub-modules split by concern from the original ollama_admin.rs (1586 lines).mod binary;mod diagnostics;mod health;diff --git a/crates/openhuman-core/src/platform/update/README.md b/crates/openhuman-core/src/platform/update/README.mdindex b0aa5efb3f..b5c2e5a119 100644--- a/crates/openhuman-core/src/platform/update/README.md+++ b/crates/openhuman-core/src/platform/update/README.md@@ -58,7 +58,7 @@ None. No `store.rs` — staged binaries are written to the filesystem (current-e- `crate::platform::service` — `service::rpc::service_restart` to publish the self-restart for `SelfReplace`.- `crate::platform::health` — `health::bus::register_health_subscriber` in the scheduler.- `crate::util` — `utf8_safe_prefix_at_byte_boundary` for safe error-body truncation.-- `crate::core::event_bus` — `publish_global`, `DomainEvent`, `init_global`, `DEFAULT_CAPACITY`.+- `crate::core::bus` — `BUS.publish`, `crate::core::events::DomainEvent`, and `bus::init()` to bring up the in-process broker.- `crate::core::observability` — Sentry reporting + transient-failure classifiers (`report_error`, `is_updater_transient_message`, `is_updater_transient_http_status`).- `crate::core::all` — `ControllerFuture`, `RegisteredController` (schemas wiring); `crate::core::{ControllerSchema, FieldSchema, TypeSchema}`.- `crate::rpc::RpcOutcome` — RPC return contract.diff --git a/crates/openhuman-core/src/security/pii/README.md b/crates/openhuman-core/src/security/pii/README.mdnew file mode 100644index 0000000000..05f8751d94--- /dev/null+++ b/crates/openhuman-core/src/security/pii/README.md@@ -0,0 +1,68 @@+# pii++Local PII / identification-risk detector (privacy epic #4256, slice S5).+Detects when a prompt or document may contain patient / legal / financial /+family or other identifiable information and reports a risk **level**, a+numeric **score**, and the matched **categories**, so upstream gates can+decide whether content is safe to send off-device.++## Guarantees++- **Fully local.** `scan()` is pure pattern + keyword matching over the input+ string — no network call, no async, no external model. Importing this+ module pulls in nothing beyond `regex`.+- **Recall over precision.** A missed flag means sensitive data leaves the+ machine unnoticed, so the detector is tuned to over-flag rather than+ under-flag.+- **Never reports raw matched text.** The result type carries only categories+ and counts, never the matched substrings — the result itself must not+ become a new PII sink.++## Key files++| File | Purpose |+| --- | --- |+| `types.rs` | `RiskLevel`, `PiiCategory` (with per-category `weight()` and `is_strong_identifier()`), `CategoryHit`, `PiiScanResult` |+| `detector.rs` | `scan()` — walks the compiled rule set, tallies matches, folds into a `PiiScanResult` |+| `rules.rs` | Compiled rule table: pattern rules (regex + optional structural validator, e.g. Luhn for cards) and keyword rules (word-boundaried term alternations for topical categories) |++## Public surface++- `scan(content: &str) -> PiiScanResult` — the only entry point.+- `PiiCategory` — structured identifiers (`Email`, `PhoneNumber`, `NationalId`,+ `CreditCard`, `BankAccount`, `IpAddress`, `PostalAddress`) and topical+ context (`DateOfBirth`, `Passport`, `Medical`, `Legal`, `Financial`,+ `Family`).+- `RiskLevel` — `None < Low < Medium < High`; `is_sensitive()` is `true` for+ anything above `None`.+- `PiiScanResult { level, score, categories, hits }` — `is_sensitive()` /+ `has_category()` helpers.++## Scoring model (`detector::scan`)++- Each distinct category contributes its `PiiCategory::weight()` once.+- Each additional co-occurring category adds a flat `CO_OCCURRENCE_BONUS` (5)+ — multiple distinct categories in one blob look more like a real record than+ any single one alone.+- A "strong identifier" (`NationalId`, `CreditCard`, `Passport`,+ `BankAccount`) forces `RiskLevel::High` regardless of the numeric score.+- The raw score otherwise maps to level via fixed thresholds: `0` → `None`,+ `1..=19` → `Low`, `20..=44` → `Medium`, `45+` → `High`.++## Used by++- `security::mod.rs` re-exports `scan` as `scan_pii`, along with+ `CategoryHit`, `PiiCategory`, `PiiScanResult`, `RiskLevel`.+- `crates/openhuman-core/src/agent/tinyagents/host/security_gate.rs` documents+ `security::pii::scan` as the detection primitive for a future `Redacted`+ screening outcome; as of this writing it is referenced but not yet wired+ in — screening only ever passes or blocks (see the `TODO(phase4)` in+ `screen_input`).+- Cross-links [`../egress/README.md`](../egress/README.md):+ `EgressDescriptor::risk_level` / `risk_categories`+ (`IdentificationRisk`) are the eventual consumer of this detector's output+ once the S5 slice wires it into the egress spine.++## Tests++- `detector_tests.rs`, `pii_tests.rs`.diff --git a/crates/openhuman-core/src/util/README.md b/crates/openhuman-core/src/util/README.mdnew file mode 100644index 0000000000..a2675de44c--- /dev/null+++ b/crates/openhuman-core/src/util/README.md@@ -0,0 +1,33 @@+# util++Kernel helper family — always compiled, never feature-gated. These are+dependency-free helpers reused across domains; nothing here may reach into a+domain (`use crate::<domain>::...`). `bm25` and `redact` say why explicitly in+their own module docs; the same rule applies to every file in this directory.++## Layout++| File | Purpose |+| --- | --- |+| `bm25.rs` | BM25 ranking over short documents, shared by `tool_search` and `skill_search`. Deliberately names nothing from `crate::` so it stays extraction-ready for a loadable module. |+| `redact.rs` | `redact()` — SHA-256-based PII redaction for log output (source ids, entity ids, content paths). Kept independent of `tinymemory_core::util::redact`, the engine's own copy, so the host does not link the memory engine just for a log formatter. |+| `retry.rs` | `retry_with_backoff` / `retry_with_backoff_async` and `is_transient_fs_error` — exponential-backoff retry for filesystem operations, mainly to ride out Windows mandatory-file-locking errors (`ERROR_SHARING_VIOLATION`, `ERROR_ACCESS_DENIED`). |+| `sanitize.rs` | Re-exports `tinymcp_bus::sanitize` (`sanitize_for_llm`, `strip_control_chars`, `strip_instruction_fences`, `truncate_utf8_safe`, `MAX_DESCRIPTION_BYTES`, `MAX_TITLE_BYTES`) under the path callers have always used. LLM-facing text sanitization for tool and skill descriptions; the real implementation lives in `tinymcp_bus` so MCP transports and the orchestrator prompt builder share one stripping rule. |+| `text.rs` | UTF-8-safe string helpers: `truncate_with_ellipsis` / `truncate_with_suffix` (char-boundary-safe truncation), `floor_char_boundary` / `ceil_char_boundary` / `utf8_safe_prefix_at_byte_boundary` (byte-boundary rounding), `provenance_tag` (non-leaky `chat:xxxxxxxx` tag hashed from a session id for the cross-chat context block). |+| `types.rs` | `MaybeSet<T>` — tri-state `Set(T)` / `Unset` / `Null` for optional-update payloads. |+| `tls/` | Platform-conditional TLS backend selection for `reqwest` clients — see [tls/README.md](tls/README.md). |++## Public surface++Everything is re-exported at the module root (`pub use` in `mod.rs`), so+`crate::util::<fn>` resolves for every helper above without naming the+submodule.++## Notes++- No file here may depend on another domain. `bm25` and `redact` exist as+ separate copies from otherwise-similar engine/vendor code specifically to+ avoid pulling in a dependency for a few lines of logic — keep new additions+ to the same standard.+- `sanitize.rs` is a thin re-export; the sanitization rule itself is owned by+ `tinymcp_bus` and must not be forked back into this crate.