Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: files changed AGENTS.md,crates/openhuman-core/src/agent/README.md,crates/openhuman-core/src/a

Steven Enamakelb79021616378
diff --git a/AGENTS.md b/AGENTS.md
index 464913a16a..d90d43e402 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -102,9 +102,18 @@ coverage must be at least 80 percent.
`tests/json_rpc_e2e.rs`.
- Frontend flows need mocked browser or desktop E2E coverage under
`app/test/e2e/specs/`.
-- E2E code must use `element-helpers.ts`, not raw platform element types.
+- E2E code must use `app/test/e2e/helpers/element-helpers.ts`, not raw platform
+ element types.
- Tests must not call real backend or third-party services.
- Avoid time-based flakes and real network access in unit tests.
+- Root `tests/*.rs` and `examples/*.rs` are NOT auto-discovered (`autotests =
+ false`, `autoexamples = false` in `crates/openhuman-core/Cargo.toml`). Every
+ new file needs an explicit `[[test]]` / `[[example]]` entry with `path =
+ "../../tests/<name>.rs"`; `pnpm rust:layout`
+ (`scripts/ci/check-openhuman-rust-layout.mjs`) fails on missing or stale
+ entries, on inline `#[cfg(test)] mod` blocks, and on files named
+ `tests.rs`/`test.rs`. Files under `tests/raw_coverage/` are aggregated by
+ `build.rs` into the single `raw_coverage_all` target and need no entry.
Shared mock backend:
@@ -216,6 +225,13 @@ Additional rules:
are deduplication keys.
- Update `crates/openhuman-core/src/platform/about_app/` when user-visible capabilities
change.
+- `RpcOutcome<T>`, `StructuredRpcError`, `unwrap_rpc`, and the JSON-RPC HTTP
+ client live in `crates/openhuman-rpc/`; the core re-exports the crate as
+ `crate::rpc` (`pub use openhuman_rpc as rpc;` in
+ `crates/openhuman-core/src/lib.rs`), and `openhuman-app` and `openhuman-tui`
+ depend on it directly. Keep it free of business logic and core dependencies
+ (its only deps are serde, serde_json, and optional log/reqwest/url behind
+ the `http-client` feature).
## Tool, harness, and runtime boundaries
@@ -245,6 +261,7 @@ disables default features, so product gates must be forwarded explicitly in
`scripts/ci/check-feature-forwarding.mjs`. Test both enabled and disabled
builds after changing a gate. Use `scripts/assert-shed.sh` or
`scripts/dep-sim.py` before claiming a dependency reduction.
+
## Loadable modules and bus contracts
Each loadable module has a small `*-bus` contract crate for interface names,
diff --git a/crates/openhuman-core/src/agent/README.md b/crates/openhuman-core/src/agent/README.md
index 384c7730d5..c2e1f3d530 100644
--- a/crates/openhuman-core/src/agent/README.md
+++ b/crates/openhuman-core/src/agent/README.md
@@ -1,43 +1,88 @@
# Agent
-Multi-agent orchestration domain. Owns the LLM tool-calling loop, sub-agent dispatch, conversation transcripts, the trigger-triage pipeline that classifies incoming external events, and the bundled prompt assets in `agent/prompts/`. Does NOT own provider HTTP transport (`providers/`), tool implementations (`tools/`), prompt section assembly (lives in `context/` — which re-exports from `agent::prompts` via `context::prompt`), or memory storage (`memory/`).
+Multi-agent orchestration domain. Owns the LLM tool-calling loop, sub-agent dispatch, conversation transcripts, the trigger-triage pipeline that classifies incoming external events, and the bundled prompt assets in `agent/prompts/`. Does NOT own provider HTTP transport (`crates/openhuman-core/src/inference/provider/`), tool implementations (`tools/`), or memory storage (`memory/`).
## Public surface
- `pub struct Agent` / `pub struct AgentBuilder` — `harness/session/types.rs` — top-level conversation runtime; entry point for any chat turn.
-- `pub mod harness::session::{builder, runtime, turn}` — `harness/session/mod.rs:23-27` — turn lifecycle, fluent builder, `run_single` / `run_interactive`.
+- `pub mod harness::session::{builder, runtime, turn}` — turn lifecycle, fluent builder, `run_single` / `run_interactive`.
- `pub fn run_subagent` / `pub struct SubagentRunOptions` / `pub enum SubagentRunError` — `harness/subagent_runner/` — execute a hierarchical sub-agent from a parent tool loop.
- `pub struct AgentDefinition` / `pub struct AgentDefinitionRegistry` / `pub enum SandboxMode` / `pub enum ToolScope` — `harness/definition.rs` — sub-agent archetypes loaded from built-ins + workspace TOML.
-- `pub mod harness::fork_context` — `harness/fork_context.rs` — task-local parent context for KV-cache reuse.
-- `pub trait ToolDispatcher` / `pub struct ParsedToolCall` / `pub struct ToolExecutionResult` — `dispatcher.rs:14-50` — pluggable tool-call format (XML / JSON / P-Format).
-- `pub mod triage` (`run_triage`, `apply_decision`, `TriggerEnvelope`, `TriageDecision`, `TriageAction`) — `triage/mod.rs:34-45` — classify external triggers, escalate to sub-agents.
+- `pub mod harness::fork_context` — task-local parent context for KV-cache reuse.
+- `pub trait ToolDispatcher` / `pub struct ParsedToolCall` / `pub struct ToolExecutionResult` — `dispatcher.rs` — pluggable tool-call format (XML / JSON / P-Format).
+- `pub mod triage` (`run_triage`, `apply_decision`, `TriggerEnvelope`, `TriageDecision`, `TriageAction`) — `triage/mod.rs` — classify external triggers, escalate to sub-agents.
- `pub mod prompts::SystemPromptBuilder` — `prompts/` — system-prompt section composer.
+- `pub struct ChatMessage` / `pub enum ConversationMessage` / `pub struct ToolResultMessage` — `messages.rs` — transcript wire types (not provider transport, which lives in `inference/provider/`).
- Built-in archetypes live in `crates/openhuman-core/src/agent/registry/agents/`; this module stays focused on harness/runtime behavior.
-- RPC `agent.chat`, `agent.chat_simple`, `agent.server_status`, `agent.list_definitions`, `agent.get_definition`, `agent.reload_definitions`, `agent.triage_evaluate` — `schemas.rs:17-158`.
+- RPC `agent.{chat, chat_simple, server_status, list_definitions, get_definition, reload_definitions, triage_evaluate, graph_topologies, registry_snapshot}` — `schemas.rs`.
+- Read-only replay RPC `agent.{runs_active, run_status, run_events}` — `tinyagents/replay/schemas.rs` — pages a run's durable journal/status without holding the run open.
+
+## Submodule map
+
+| Path | Purpose |
+| --- | --- |
+| `artifacts/` | Agent-generated artifact storage, retrieval, and lifecycle ([README](artifacts/README.md)) |
+| `context/` | Prompt section assembly, tool-call format selection ([README](context/README.md)) |
+| `debug/` | Debug/introspection helpers for agent internals |
+| `experience/` | Local procedural operating experience capture for self-learning ([README](experience/README.md)) |
+| `file_state/` | Tracks files an agent has read/written within a turn |
+| `git_attribution/` (`pub(crate)`) | Attributes agent-authored commits/diffs to the acting agent |
+| `harness/` | `Agent`/`AgentBuilder`, session lifecycle, sub-agent runner, fork context — the tool-calling loop itself |
+| `harness_init/` | One-time first-run provisioning (Python/spaCy/Node) before the harness can run |
+| `learning/` | Reflection, tool-outcome tracking, user-profile inference from transcripts ([README](learning/README.md)) |
+| `library/` | Shared agent-authored content library |
+| `orchestration/` | Command center, workflow runs, agent teams, worktrees, subagent control ([README](orchestration/README.md)) |
+| `plan_review/` | Interactive plan-review gate that parks a live turn on a thread-scoped plan |
+| `profiles/` | Persistent agent profiles (name, soul, memory sources, skills, MCP, connectors) |
+| `progress_tracing/` | Structured OpenTelemetry/Langfuse-style spans off the `progress::AgentProgress` stream |
+| `prompts/` | Prompt types, section builders, `SystemPromptBuilder` |
+| `registry/` | User-facing agent registry: defaults, enablement, custom agents, tool policy; `registry/agents/` holds built-in archetypes |
+| `session_db/` | Durable run ledger backing `run_ledger` RPC |
+| `session_import/` | Importing session/run history from external sources |
+| `task_dispatcher/` | Background board poller that turns queued tasks into agent runs |
+| `tinyagents/` | Integration with the vendored `tinyagents` loop/replay crate; owns `tinyagents/replay/schemas.rs` |
+| `tools/` | Agent-domain tool implementations (`spawn_subagent`, dispatch helpers, etc.) |
+| `triage/` | Classifies external `TriggerEnvelope`s and escalates to sub-agents |
+
+Flat files: `bus.rs` (event subscribers), `cost.rs` (`pub(crate)`, token/cost accounting), `dispatcher.rs` (tool-call format dispatch), `error.rs`, `hooks.rs`, `host_runtime.rs` (native shell execution backend), `messages.rs` (transcript types), `multimodal.rs`, `pformat.rs`, `platform_shell.rs` (cross-platform shell selection shared with `host_runtime` and `sandbox::ops`), `progress.rs` (`AgentProgress` channel), `progress_sink.rs` (task-local progress sink for in-process embedders), `stop_hooks.rs`, `task_board.rs`, `task_session.rs` (`pub(crate)`), `tool_policy.rs`, `turn_origin.rs` (task-local trust/routing label read by the approval gate), `turn_workspace.rs` (task-local per-turn filesystem root).
+
+## RPC namespaces owned by this tree
+
+`agent`, `agent_registry`, `profiles`, `harness_init`, `session_import`, `plan_review`, `run_ledger` (session_db), `agent_experience` (experience), `ai` (artifacts), `learning`, `agent_team`, `agent_work` (orchestration/command_center), `workflow_run`, `worktree`, `subagent` (orchestration/subagent_control) — all registered under `DomainGroup::Agent` in `core/all.rs`.
+
+`crate::rpc` is `pub use openhuman_rpc as rpc` in `lib.rs`; shared RPC contracts, response decoding, and the HTTP client now live in the separate `crates/openhuman-rpc` crate, not under `agent/`.
## Calls into
-- `crates/openhuman-core/src/providers/` — `ChatMessage`, `ChatResponse` send/receive against LLMs.
+- `crates/openhuman-core/src/inference/provider/` — `Provider` trait sends/receives against LLMs; `ChatMessage`/`ConversationMessage` (defined in `agent/messages.rs`) cross this boundary.
- `crates/openhuman-core/src/tools/` — `Tool` / `ToolSpec` execution surface invoked from the tool loop.
- `crates/openhuman-core/src/memory/` — episodic indexing + memory-loader context injection.
- `crates/openhuman-core/src/agent/context/` — prompt sections, tool-call format selection.
- `crates/openhuman-core/src/inference/local/` — `agent_chat` / `agent_chat_simple` execution backend.
- `crates/openhuman-core/src/config/` — runtime config load via `config::rpc::load_config_with_timeout`.
-- `crates/openhuman-core/src/core/event_bus/` — emits `DomainEvent::Agent(*)` and `Trigger*` events; subscribers in `agent/bus.rs`.
+- `crates/openhuman-core/src/core/bus.rs` (`BUS.publish`/`BUS.subscribe`) and `crates/openhuman-core/src/core/events.rs` (`DomainEvent`) — emits `DomainEvent::Agent(*)` and `Trigger*` events; subscribers in `agent/bus.rs`.
## Called by
-- `crates/openhuman-core/src/channels/runtime/dispatch.rs` and `web_chat/` — drive chat turns from inbound channel messages.
-- `crates/openhuman-core/src/cron/scheduler.rs` — fire scheduled triggers through `triage::run_triage` + `apply_decision`.
-- `crates/openhuman-core/src/skills/webhooks/ops.rs` — webhook ingestion routes through triage.
-- `crates/openhuman-core/src/integrations/composio/bus.rs` — Composio trigger envelopes go through `agent::triage`.
-- `crates/openhuman-core/src/desktop/notifications/rpc.rs` — surfaces agent runs to the UI.
+- `crates/openhuman-core/src/channels/runtime/dispatch/` (`processor*.rs`, `routing.rs`) and `web_chat/` — drive chat turns from inbound channel messages.
+- `crates/openhuman-core/src/cron/scheduler_part_02.rs::run_agent_job` — builds an `Agent` directly via `Agent::from_config_for_agent[_with_profile]` / `Agent::from_config` and delivers output through `deliver_if_configured`; it does not go through triage.
+- `crates/openhuman-core/src/skills/webhooks/{ops,bus}.rs` — webhook ingestion routes through `triage::run_triage` + `apply_decision`.
+- `crates/openhuman-core/src/memory/sync/composio/bus*.rs` — Composio trigger envelopes go through `agent::triage`.
+- `crates/openhuman-core/src/integrations/task_sources/route.rs` — external task-source events go through the same `TriggerEnvelope` → `run_triage` → `apply_decision` path.
+- `crates/openhuman-core/src/desktop/notifications/rpc.rs` — desktop notification intel routes through triage before surfacing agent runs to the UI.
+- `crates/openhuman-core/src/agent/schemas.rs::triage_evaluate` — dry-run triage entry point exposed over RPC.
- `crates/openhuman-core/src/agent/learning/{reflection,tool_tracker,user_profile}.rs` — read transcripts + tool outcomes.
- `crates/openhuman-core/src/agent/orchestration/tools/{dispatch,spawn_subagent}.rs` — `spawn_subagent` tool delegates here.
-- `crates/openhuman-core/src/core/all.rs` — controller registry wires `all_agent_registered_controllers`.
+- `crates/openhuman-core/src/core/runtime/services.rs` — starts `agent::task_dispatcher::start_board_poller` and runs `agent::harness_init::run_harness_init` during core startup.
+- `crates/openhuman-core/src/core/all.rs` — controller registry wires all `agent`, `agent_registry`, `profiles`, `harness_init`, `plan_review`, `artifacts`, `experience`, `learning`, `session_db`, `session_import`, and `orchestration` controllers under `DomainGroup::Agent`.
## Tests
-- Unit: `mod.rs` `#[cfg(test)] mod tests;`, `tests.rs`, `multimodal_tests.rs`, `dispatcher_tests.rs`, plus `*_tests.rs` files under `harness/`, `harness/session/`, `triage/`.
-- Integration: `tests/agent_builder_public.rs`, `tests/agent_harness_public.rs`, `tests/agent_memory_loader_public.rs`, `tests/agent_multimodal_public.rs`.
-- Schema regression: `schemas.rs:393-410` (`controller_schema_inventory_is_stable`).
+- Unit: `agent_tests.rs` + `agent_tests_part_0N_tests.rs`, `multimodal_tests.rs` + `multimodal_tests_part_0N_tests.rs`, `dispatcher_tests.rs`, plus `*_tests.rs` files colocated with `bus.rs`, `cost.rs`, `error.rs`, `hooks.rs`, `host_runtime.rs`, `message_convert.rs`, `pformat.rs`, `platform_shell.rs`, `progress_sink.rs`, `schemas.rs`, `stop_hooks.rs`, `task_board.rs`, `task_session.rs`, `tool_policy.rs`, `turn_origin.rs`, `turn_workspace.rs`, and under `harness/`, `harness/session/`, `triage/`.
+- Integration: `tests/agent_builder_public.rs`, `tests/agent_harness_public.rs`, `tests/agent_harness_e2e.rs`, `tests/agent_multimodal_public.rs`, `tests/agent_turn_overrides_e2e.rs`, `tests/agent_approval_memory_coverage_e2e.rs`.
+- Schema regression: `schemas_tests.rs` (`controller_schema_inventory_is_stable`).
+
+## Related docs
+
+- [gitbooks/developing/architecture/agent-harness.md](../../../../../gitbooks/developing/architecture/agent-harness.md)
+- [gitbooks/developing/agent-observability.md](../../../../../gitbooks/developing/agent-observability.md)
diff --git a/crates/openhuman-core/src/agent/harness/README.md b/crates/openhuman-core/src/agent/harness/README.md
new file mode 100644
index 0000000000..766a80c763
--- /dev/null
+++ b/crates/openhuman-core/src/agent/harness/README.md
@@ -0,0 +1,124 @@
+# harness
+
+Product shell around the tinyagents tool loop. The model/tool iteration
+itself runs in `crate::agent::tinyagents` (via
+`run_turn_via_tinyagents_shared`); this module owns everything OpenHuman
+layers on top: the `Agent`/`AgentBuilder` session, transcript persistence and
+legacy-format migration, sub-agent dispatch, agent archetypes, post-turn
+memory/archival hooks, mid-turn message steering, and oversized-tool-result
+handling.
+
+Cancellation is the tinyagents steering channel (`run_queue` below) — there
+is no in-house interrupt fence.
+
+## Responsibilities
+
+- Own the `Agent` struct and its per-turn lifecycle: prompt/context assembly,
+ tool dispatch, transcript persistence, KV-cache prefix stability
+ (`session/`).
+- Dispatch sub-agents: resolve an `AgentDefinition`, filter tools, build a
+ narrow prompt, run the child turn, and return one compact tool result to
+ the parent (`subagent_runner/`).
+- Define sub-agent archetypes (built-in + workspace TOML) and the task-local
+ plumbing that lets a spawned tool see its parent's runtime context
+ (`definition*.rs`, `builtin_definitions.rs`, `fork_context.rs`,
+ `sandbox_context.rs`, `spawn_depth_context.rs`, `task_recency_context.rs`,
+ `turn_attachments_context.rs`).
+- Drive channel turns through the agent graph (`agent_graph.rs`, `graph.rs`).
+- Extract lessons and episodic memory after each turn as a `PostTurnHook`
+ (`archivist/`).
+- Offload oversized worker artifacts to the filesystem, and persist oversized
+ tool results as action-workspace artifacts (`artifact_offload/`,
+ `tool_result_artifacts/`).
+- Queue mid-turn messages into steer/followup/collect lanes without aborting
+ the in-flight turn (`run_queue/`).
+
+## Key sub-modules
+
+| Module | Role |
+| --- | --- |
+| `session/` | `Agent`/`AgentBuilder`/`TurnOverrides` (`types.rs`), the fluent builder + `Agent::from_config` factory (`builder/`), the turn lifecycle (`turn/`: `context.rs`, `core*.rs`, `graph.rs`, `recall_lanes.rs`, `session_io*.rs`, `tools.rs`), transcript persistence + legacy migration (`transcript*.rs`, `migration.rs`, `turn_checkpoint.rs`). |
+| `subagent_runner/` | `run_subagent`/`SubagentRunOptions`/`SubagentRunError` and the build pipeline around the tinyagents graph: model resolution, tool filtering, sandbox/action-root narrowing, checkpoint/handback, transcript mirroring (`autonomous.rs`, `extract_tool.rs`, `handoff.rs`, `tool_prep.rs`, `ops/{provider,prompt,runner,graph,checkpoint,pause_checkpoint}.rs`). |
+| `definition*.rs`, `builtin_definitions.rs`, `definition_loader.rs` | `AgentDefinition`/`AgentDefinitionRegistry`/`SandboxMode`/`ToolScope`/`PromptSource`/`ModelSpec`; loads built-ins from `crate::agent::registry::agents` and user TOML from the workspace/home `agents/` directory. |
+| `fork_context.rs`, `sandbox_context.rs`, `spawn_depth_context.rs`, `task_recency_context.rs`, `turn_attachments_context.rs` | `ParentExecutionContext` and other task-locals a spawned tool reads to see its parent's provider, tools, sandbox mode, spawn depth (capped by `MAX_SPAWN_DEPTH`), and recent-task window. |
+| `agent_graph.rs`, `graph.rs` | `AgentGraph`/`AgentTurnRequest` and `run_channel_turn_via_graph`, the entry point channels use to run a turn. |
+| `archivist/` | `ArchivistHook` — post-turn boundary detection, LLM recap (heuristic fallback), lesson extraction, and raw-prose ingestion into the memory tree (`boundary.rs`, `lifecycle.rs`, `recap.rs`, `resummarise.rs`, `store.rs`, `tree_ingest.rs`, `events_heuristic.rs`). |
+| `artifact_offload/` | The `outputs/` / `workspace/` convention under `action_dir`: prompt half (`contract.rs`) and host policy half (`policy.rs`); mechanics (thresholds, path resolution, pointer rendering, the writer) live in `tinyagents_harness::artifacts` and are re-exported here. |
+| `run_queue/` | `RunQueue` and `QueuedMessage` — steer/followup/collect lanes wrapping `tinyagents_harness::run_queue`; `QueueStatus` is re-exported from the crate. |
+| `tool_result_artifacts/` | Persists oversized individual and aggregate tool outputs under `action_dir/artifacts/tool-results/`, replacing them with a bounded `[tool_result_preview]` envelope pointing at the full, redacted file. |
+| `memory_context*.rs`, `memory_protocol.rs` | Memory/context injection policy for turns and sub-agent prompts. |
+| `tool_filter.rs`, `instructions.rs`, `parse.rs`, `required_output.rs` | Tool visibility filtering, tool-instruction section assembly, `parse_tool_calls_with_pformat`, and required-output enforcement. |
+| `credentials.rs` | Credential lookup used when assembling sub-agent context. |
+| `turn_dispatch_guard.rs`, `turn_subagent_usage.rs` | Per-turn dispatch guard rails and `LastTurnUsage`/`SubagentUsageEntry` accounting. |
+
+## Public surface
+
+- `Agent`, `AgentBuilder`, `TurnOverrides` — re-exported from `session`; the
+ entry point for any chat turn. External callers import these from
+ `crate::agent`, which re-exports them from `harness::session`.
+- `run_subagent`, `SubagentRunOptions`, `SubagentRunError` — hierarchical
+ sub-agent dispatch from a parent tool loop.
+- `AgentDefinition`, `AgentDefinitionRegistry`, `DefinitionSource`,
+ `ModelSpec`, `PromptSource`, `SandboxMode`, `ToolScope`,
+ `TriggerMemoryAgent` — sub-agent archetype data model.
+- `ParentExecutionContext` and its accessors (`current_parent`,
+ `with_parent_context`, `current_agent_context_prepared_sources`,
+ `with_agent_context_prepared_sources`) — parent runtime context for
+ spawned tools.
+- `current_sandbox_mode`/`with_current_sandbox_mode`,
+ `current_task_recency_window`/`with_task_recency_window` — other
+ task-local accessors.
+- `AgentGraph`, `AgentTurnRequest`, `AgentTurnResult`, `AgentTurnUsage`.
+- `LastTurnUsage`, `SubagentUsageEntry`.
+- `artifact_offload::{ArtifactKind, OffloadedArtifact, new_artifact_offload, offload_oversized_result, render_artifact_offload_contract, ...}` — not glob-re-exported at the `harness` level (would shadow `agent::artifacts::ArtifactKind`); import via the `artifact_offload::` path.
+- `run_queue::{RunQueue, QueueMode, QueuedMessage, QueueStatus}`.
+
+## Dependencies
+
+- `tinyagents_harness` (vendored via `vendor/tinyagents/`) — the tool loop
+ itself (`run_turn_via_tinyagents_shared`), the `run_queue` and `artifacts`
+ primitives this module wraps, and the `Store` trait implemented by
+ `tool_result_artifacts::ToolResultArtifactIndexStore`.
+- `crate::agent::registry::agents` — built-in agent archetype TOML/prompt
+ bundles loaded by `definition_loader`/`builtin_definitions`.
+- `crate::security::SecurityPolicy` — workspace containment policy plumbed
+ into `artifact_offload::new_artifact_offload`.
+- `crate::memory` — context injection (`memory_context*`) and text
+ sanitization (`tool_result_artifacts` uses `memory::safety::sanitize_text`).
+- `crate::config::AgentConfig`, `crate::skills::Workflow`,
+ `crate::tools::{Tool, ToolSpec}` — runtime context carried through
+ `fork_context::ParentExecutionContext`.
+
+## Used by
+
+- `crate::agent::mod` re-exports `Agent`/`AgentBuilder` for the rest of the
+ crate.
+- `cron/scheduler_part_02.rs`, `web_chat/`, `channels/runtime/dispatch/`,
+ `inference/local/ops.rs` (`agent_chat`) drive turns through this module.
+- `agent/orchestration/tools/*` (`spawn_subagent`, `spawn_parallel_agents`,
+ `spawn_async_subagent`, `continue_subagent`, `steer_subagent`, …) and
+ `agent/task_dispatcher/executor.rs` call into `subagent_runner` and the
+ task-local context modules.
+
+## Tests
+
+- Unit: `harness_tests.rs`, `harness_gap_tests.rs`, plus `*_tests.rs` files
+ beside each sub-module (`session/session_tests*.rs`,
+ `subagent_runner/{ops_tests*,handoff_tests,extract_tool_tests,tool_prep_tests}.rs`,
+ `run_queue/run_queue_tests.rs`, `tool_result_artifacts/mod_tests.rs`,
+ `artifact_offload/artifact_offload_tests.rs`).
+- Integration: `tests/agent_harness_public.rs`, `tests/agent_harness_e2e.rs`.
+
+## Notes / gotchas
+
+- `session/mod.rs` and `artifact_offload/mod.rs` reference
+ `docs/tinyagents-harness-migration-audit.md` and `docs/specs/plan-agents.md`
+ as the migration plan for moving durable state and offload mechanics onto
+ TinyAgents primitives. Neither file is checked into this repo; treat the
+ plan as undocumented rather than following a broken link.
+- `artifact_offload` deliberately has no flat `ArtifactKind` re-export at the
+ `harness` level — it would shadow `agent::artifacts::ArtifactKind` for glob
+ importers. Use the `artifact_offload::` path.
+- No in-house turn-interrupt mechanism: steering goes through
+ `tinyagents_harness::run_queue` (wrapped by `run_queue::RunQueue`), not a
+ cancellation token owned here.
diff --git a/crates/openhuman-core/src/agent/orchestration/tools.rs b/crates/openhuman-core/src/agent/orchestration/tools.rs
index f7786c33f1..71b938e452 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools.rs
@@ -1,3 +1,22 @@
+//! Declares the LLM-callable orchestration tools kept in `tools/` (via
+//! `#[path]`, since this file lives in `orchestration/` rather than a
+//! `tools/mod.rs`).
+//!
+//! Split by role:
+//! - **Spawn**: `spawn_subagent`, `spawn_async_subagent`,
+//! `spawn_parallel_agents`, `spawn_worker_thread`.
+//! - **Control**: `steer_subagent`, `continue_subagent`, `close_subagent`,
+//! `wait_subagent`, `wait`, `list_subagents`.
+//! - **Delegation**: `delegate_graph`, `archetype_delegation`,
+//! `skill_delegation`, `collapsed_delegation`, `dispatch`,
+//! `agent_prepare_context`, `awaiting_user`, `worker_thread`.
+//!
+//! All of them are re-exported through `crate::tools` (`tools/mod.rs`:
+//! `pub use crate::agent::orchestration::tools::*`), which is how the agent
+//! tool-calling loop discovers them. Execution itself goes through
+//! `agent::harness::run_subagent`; this module only owns the tool-call
+//! surface (schema, argument parsing, response formatting).
+
#[path = "tools/agent_prepare_context.rs"]
mod agent_prepare_context;
#[path = "tools/archetype_delegation.rs"]
diff --git a/crates/openhuman-core/src/agent/profiles/README.md b/crates/openhuman-core/src/agent/profiles/README.md
new file mode 100644
index 0000000000..5ad02f69f9
--- /dev/null
+++ b/crates/openhuman-core/src/agent/profiles/README.md
@@ -0,0 +1,120 @@
+# profiles
+
+Persistent, user-selectable agent "flavours". A profile carries a name,
+description, an `agent_id`, runtime defaults (model override, temperature,
+system-prompt suffix, SOUL.md), and configurable allowlists for tools, skills,
+MCP servers, Composio integrations, and memory sources. Selecting a profile
+changes how the agent introduces itself, what it remembers, and what it can do.
+State persists under `<workspace>/agent_profiles.json`; the module also owns
+each profile's on-disk "home" (identity/memory files under `workspace_dir`,
+optional dedicated workspace under `action_dir`) and the guard that keeps
+dedicated-workspace profiles from writing into a sibling's directory.
+
+## Responsibilities
+
+- Define the `AgentProfile` / `AgentProfilesState` serde types and the
+ built-in profile set (`default`, `reasoning`, `research`, `planner`,
+ `review`).
+- Persist and normalise profile state (`AgentProfileStore`): merge built-ins
+ into any loaded/saved state, slugify ids, drop empty allowlist entries to
+ `None`, and auto-assign a stable numeric `memory_dir_suffix` to new custom
+ profiles.
+- Materialize and reconcile each profile's on-disk "home" — `SOUL.md`,
+ `MEMORY.md`, a private `skills/` dir, and (opt-in) a dedicated workspace.
+- Resolve profile-scoped paths for prompt building: which SOUL.md content and
+ MEMORY.md to use, the effective memory subtree suffix, and a session
+ signature that changes when a profile's resolved inputs change.
+- Enforce the cross-profile write guard: block a dedicated-workspace profile's
+ tool calls from targeting a sibling profile's workspace.
+- Expose the `profiles` RPC namespace (list/select/upsert/delete), wired into
+ the core registry.
+
+## Key files
+
+| File | Role |
+| --- | --- |
+| `mod.rs` | Module docs, `mod` decls, and the re-export surface. |
+| `types.rs` | `AgentProfile`, `AgentProfilesState`, `DEFAULT_PROFILE_ID`, `profile_signature` (a serialized cache key for prompt construction). |
+| `store.rs` | `AgentProfileStore` (load/save/select/upsert/delete/resolve) over `<workspace>/agent_profiles.json`; `built_in_profiles`, `load_profiles`, id normalisation/slugification, and the numeric `memory_dir_suffix` allocator. |
+| `home.rs` | Per-profile home materialization: `profile_home`, `profile_action_workspace`, `profile_skills_dir`/`profile_skills_root`, `validate_profile_id`, `ensure_profile_home` (idempotent seed), `sync_soul_md_on_upsert` (reconcile an edited inline soul into the on-disk file), `dedicated_workspace_dir`. |
+| `paths.rs` | Personality-scoped path/content resolution: `resolve_personality_soul`, `resolve_personality_memory_md`, `effective_memory_suffix`, the `*_subdir_for_suffix` helpers, `profile_session_signature`, `PersonalityContext`, `filter_integrations`/`HasToolkit`. |
+| `guard.rs` | Cross-profile identity plumbing and write guard: `workspace_policy_id`/`profile_id_from_policy_id` (encode/decode the `WorkspaceDescriptor::policy_id`), `classify_cross_profile_target` (file tools), `scan_command_for_cross_profile` (shell/process tools, best-effort). |
+| `prompt_section.rs` | `AgentProfilePromptSection` (renders the `## Agent profile` prompt block) and `cross_profile_workspace_notice`. |
+| `ops.rs` | `list`/`select`/`upsert`/`delete` business logic: `agent_id` validation against the global agent registry, home materialization, SOUL.md reconciliation, and read-only path enrichment (`soulMdFile`, `skillsDir`, `workspaceDir`) on the returned payload. |
+| `schemas.rs` | Controller schemas + thin handlers for the `profiles` namespace; re-exported as `all_profiles_controller_schemas` / `all_profiles_registered_controllers`. |
+| `*_tests.rs` | Sibling test suites per file (via `#[path]`). |
+
+## Profile home layout (hermes-agent style)
+
+```text
+<workspace>/personalities/<id>/SOUL.md identity (hot-read each prompt)
+<workspace>/personalities/<id>/MEMORY.md curated per-profile memory
+<workspace>/personalities/<id>/skills/ private skills (owner-only discovery)
+<workspace>/{memory,memory_tree,session_raw}-<id>/ dedicated memory subtree (opt-in)
+<action_dir>/profiles/<id>/ agent-writable workspace (opt-in)
+```
+
+Identity/memory files live under `workspace_dir`, which the agent's write
+tools cannot reach; the writable working dir lives under `action_dir`, which
+acting tools are allowed to touch. `SOUL.md` is re-read on every prompt build
+so identity edits take effect live. `dedicated_memory` derives a `-<id>`
+suffix and wins over the auto-assigned numeric suffix; `dedicated_workspace`
+roots a per-profile default cwd for acting tools. `ensure_profile_home` never
+overwrites a user's edited files.
+
+## RPC / controllers
+
+Namespace `profiles`, registered via `all_profiles_registered_controllers()`:
+
+| Method | Inputs | Output |
+| --- | --- | --- |
+| `profiles.list` | — | `{ profiles, activeProfileId }`, each profile enriched with `soulMdFile`/`skillsDir`/`workspaceDir` when present on disk |
+| `profiles.select` | `profile_id: string` | updated state payload |
+| `profiles.upsert` | `profile: AgentProfile` (JSON) | updated state payload |
+| `profiles.delete` | `profile_id: string` | updated state payload |
+
+`upsert` fails closed on a non-empty, non-`orchestrator` `agent_id` when the
+global `AgentDefinitionRegistry` is not yet initialised, rather than persist a
+reference it cannot validate. Built-in profiles have their home materialized
+on first `select`; custom profiles are materialized on `upsert`. Soul edits are
+reconciled into the on-disk `SOUL.md` on every `upsert`, built-in included.
+
+## Cron attribution
+
+A cron job may carry a `profile_id` (`cron::CronJob::profile_id`). When set and
+the profile still exists, the scheduled run is built under that profile (soul,
+memory scope, dedicated workspace, allowlists) via the same profile-aware
+session path the task dispatcher uses; a deleted profile falls back to a
+profile-less run rather than failing the job.
+
+## Used by
+
+- `crates/openhuman-core/src/core/all.rs` registers the controllers.
+- `agent/harness/session/builder/factory.rs` is the primary consumer: resolves
+ memory suffix/subdirs, soul/memory content, the dedicated workspace
+ descriptor (`workspace_policy_id`), the cross-profile prompt notice, and
+ integration filtering when building a session.
+- `agent/harness/session/turn/tools.rs` resolves `profile_skills_root` for
+ workflow discovery.
+- `security/policy/path_checks.rs` and `tools/impl/system/mod.rs` call
+ `classify_cross_profile_target` / `scan_command_for_cross_profile` to enforce
+ the write guard at the file-tool and process-tool call sites.
+- `cron/scheduler_part_02.rs` resolves a job's attributed profile
+ (`from_config_for_agent_with_profile`).
+- `skills/ops_discover.rs` and `agent/tools/{run_workflow,delegate_to_personality}.rs`
+ scope skill discovery and delegation to the active profile.
+- `channels/system_prompt.rs` and `web_chat/session.rs` resolve profile-scoped
+ prompt content and the session signature for cache invalidation.
+
+## Notes / gotchas
+
+- `validate_profile_id` (hermes grammar `^[a-z0-9][a-z0-9_-]{0,63}$`) gates
+ every home read/write path; a legacy id that fails validation gets no home,
+ no dedicated workspace, and no profile-local skills — reads and writes stay
+ symmetric.
+- `scan_command_for_cross_profile` is explicitly best-effort defense in depth
+ for process tools (static token scan, not a real shell parser); the hard
+ boundary for file mutations is `SecurityPolicy::validate_path`.
+- The mod-level doc comment's note about being "relocated from
+ `openhuman::agent::profiles` / `::personality_paths`" is historical residue
+ from the pre-flattening layout; the current path is `crate::agent::profiles`.
diff --git a/crates/openhuman-core/src/agent/task_dispatcher/README.md b/crates/openhuman-core/src/agent/task_dispatcher/README.md
new file mode 100644
index 0000000000..6e262f1ec4
--- /dev/null
+++ b/crates/openhuman-core/src/agent/task_dispatcher/README.md
@@ -0,0 +1,59 @@
+# task_dispatcher
+
+The single executor for task-board cards. Turns a `TaskBoardCard` into work:
+claims it via a compare-and-set (`Todo`/`Ready` → `in_progress`, so a
+stale/concurrent re-dispatch is rejected), runs one autonomous agent turn
+toward the card's objective, and writes the outcome back — `done` + evidence
+on success, `blocked` + reason on failure.
+
+Two dispatch paths converge on `dispatch_card`, so the claim is what keeps
+them from racing:
+
+- the **board poller** (`poller.rs`, `start_board_poller`) — a periodic sweep
+ spawned from `channels/runtime/startup_part_01.rs`, catching cards that
+ arrive without a proactive trigger.
+- **proactive triage** (`agent::triage::escalation`) — dispatches a card once
+ it has decided to act on it.
+
+The dispatcher only ever sweeps the `user-tasks` and `task-sources` boards. It
+never sweeps conversation-thread boards; a chat-turn plan is gated on the turn
+itself instead (see `agent::plan_review`).
+
+## Files
+
+- `mod.rs` — module doc, public re-exports, and `run_system_turn_on_thread`
+ (a one-off system turn streamed into an existing chat thread, used by
+ `agent::orchestration::background_delivery` to surface a finished detached
+ sub-agent result back into the chat).
+- `dispatch.rs` — `dispatch_card`: the plan-approval gate, the atomic claim,
+ spawning the detached run, and registering it for cancellation.
+- `executor.rs` — `resolve_executor` (a card's `assigned_agent` → personality,
+ skill, or built-in agent, degrading to the default `orchestrator`),
+ `run_autonomous` (builds the agent, pins the task-run iteration cap, streams
+ progress into the session thread), and `write_back` (deterministic
+ done/blocked board write-back; respects a card the run already
+ self-blocked via `update_task`).
+- `poller.rs` — `start_board_poller`: idempotent periodic sweep with
+ diminishing-returns backoff, gated on `cron::scheduler_gate` capacity;
+ reclaims stale runs before picking the highest-urgency dispatchable card.
+- `prompt.rs` — `build_task_prompt` / `build_progress_instruction`: thin
+ binding of `tinyagents_graph::todos::dispatch::prompt` to OpenHuman's tool
+ names (`memory_recall`, `update_task`).
+- `registry.rs` — in-flight run registry keyed by session `thread_id`;
+ `cancel_session` / `cancel_session_scoped` abort a detached run and drive its
+ cancellation write-back for the web-channel Cancel button.
+- `types.rs` — `DispatchOutcome` (`Running` / `AwaitingApproval`),
+ `ResolvedExecutor`, and the crate-backed `ActiveRun` alias.
+
+## Related
+
+- `agent::task_board` re-exports the board types
+ (`tinyagents_graph::todos::{TaskBoard, TaskBoardCard, TaskCardStatus, ...}`)
+ used throughout this module.
+- `threads::todos/` is the compatibility surface that maps `BoardLocation`
+ onto the TinyAgents stores, exposes the `openhuman.todos_*` RPC and
+ `todo_*` tools, and owns the run ledger (`runs.rs`) this dispatcher reads
+ and writes through.
+- Selection and backoff policy (`pick_next_card`, `requires_plan_approval`,
+ `PollCadence`) live in `tinyagents_graph::todos::dispatch::select`; this
+ crate only tunes and wires them.
diff --git a/crates/openhuman-core/src/lib.rs b/crates/openhuman-core/src/lib.rs
index 66d9ca801b..b96e502816 100644
--- a/crates/openhuman-core/src/lib.rs
+++ b/crates/openhuman-core/src/lib.rs
@@ -1,9 +1,41 @@
-//! Core library for the OpenHuman platform.
+//! `openhuman-core` — the in-process Rust core.
//!
-//! This crate provides the central logic for the OpenHuman core binary, including:
-//! - API and RPC handlers for external interactions.
-//! - Core system services (CLI, configuration, monitoring).
-//! - Domain-specific logic for the OpenHuman agent runtime.
+//! Cargo package `openhuman`, library `openhuman_core`, binary `openhuman-core`
+//! ([`main.rs`](../src/main.rs)). Owns business rules, persistence, execution
+//! policy, the JSON-RPC/Socket.IO server, and the CLI. Hosted in-process by
+//! `openhuman-app` (the Tauri shell), `openhuman-embed` (the typed facade for
+//! third-party embedders such as Medulla and OpenCompany), and `openhuman-tui`.
+//!
+//! Business logic lives one directory per domain family under `src/`, listed
+//! below in the order they are declared (module declarations are kept
+//! alphabetical, with the `rpc` re-export sitting between `platform` and
+//! `runtime` — keep new modules sorted the same way): `agent`, `api`,
+//! `channels`, `config`, `core`, `cron`, `desktop`, `flows` (feature
+//! `flows`), `hooks`, `hosted`, `hosting` (feature `hosting`), `http_host`
+//! (feature `http-server`), `inference`, `integrations`, `json_schema`,
+//! `mcp`, `media` (feature `media`), `medulla`, `memory`, `modules` (feature
+//! `modules`), `platform`, `sandbox`, `search`, `security`, `skills`,
+//! `test_support` (feature `e2e-test-support`), `threads`, `tools`, `util`,
+//! `voice`, `web3`, `web_chat`. `core/` is not a domain: it holds transport,
+//! dispatch, the controller registry (`core::all`), the CLI, the event bus,
+//! and runtime composition (`core::runtime`). See `README.md` and AGENTS.md
+//! ("Rust domain structure") for the preferred per-domain module shape.
+//!
+//! `pub use openhuman_rpc as rpc;` re-exports the `openhuman-rpc` crate, so
+//! `crate::rpc::{RpcOutcome, StructuredRpcError, ...}` are the same types the
+//! app and TUI decode responses with — there is no separate RPC contract
+//! layer in this crate.
+//!
+//! [`CoreBuilder`], [`CoreRuntime`], [`DomainSet`], [`ServiceSet`],
+//! [`TokenSource`] and [`HostKind`] are the embeddable composition API;
+//! `openhuman-embed` layers a typed facade on top of them.
+//! [`run_core_from_args`] is the CLI entry point shared by `src/main.rs` and
+//! the desktop shell's `openhuman core` subcommand.
+//!
+//! Cargo features split into a contributor `default` set and a larger
+//! shipped-product set (`scripts/ci/product-features.txt`); slim or headless
+//! embedding builds use `--no-default-features --features "<list>"`. See the
+//! `[features]` block in `Cargo.toml` for the full gate list and rationale.
// The RPC dispatch chokepoint wraps each handler future in an ambient
// `CoreContext` scope (Phase 2). Combined with the already very deep async type
@@ -61,7 +93,8 @@ pub use config::DaemonConfig;
/// Embeddable core composition API. Host the OpenHuman core in any process —
/// the Tauri shell, a CLI, a stdio MCP server, or a cloud/team server — via
-/// [`CoreBuilder`] → [`CoreRuntime`]. See `docs/plans/pluggable-core/`.
+/// [`CoreBuilder`] → [`CoreRuntime`]. See `crates/openhuman-embed/README.md`
+/// and [`crate::core::runtime`] for the composition this builds on.
pub use core::runtime::{CoreBuilder, CoreRuntime, DomainSet, ServiceSet, TokenSource};
pub use core::types::HostKind;