Skip to content

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

docs: update READMEs and add module docstring for session agent caching

Steven Enamakeld6b39dbc43fd
diff --git a/crates/openhuman-core/src/integrations/task_sources/README.md b/crates/openhuman-core/src/integrations/task_sources/README.md
index 4be5ba09bf..371ddb6dde 100644
--- a/crates/openhuman-core/src/integrations/task_sources/README.md
+++ b/crates/openhuman-core/src/integrations/task_sources/README.md
@@ -132,8 +132,10 @@ Additive idempotent column migrations (`add_column_if_missing`) backfill `ingest
## Used by
- `crates/openhuman-core/src/core/all.rs` — registers controllers + schemas into the global RPC registry.
-- `crates/openhuman-core/src/core/jsonrpc.rs` — at startup registers the connection subscriber and starts the periodic poll.
-- `crates/openhuman-core/src/core/event_bus/events.rs` — defines/classifies the three `TaskSource*` event variants under domain `"task_sources"`.
+- `crates/openhuman-core/src/core/jsonrpc.rs` — at startup registers the connection subscriber (bus.rs).
+- `crates/openhuman-core/src/core/runtime/services.rs` — at startup starts the periodic poll as part of the `proactive_task_pollers` bootstrap job.
+- `crates/openhuman-core/src/core/events.rs` — defines/classifies the three `TaskSource*` event variants under domain `"task_sources"`.
+- `crates/openhuman-core/src/tools/mod.rs` — re-exports `tools.rs`'s agent tools into the global tool registry.
- `crates/openhuman-core/src/config/schema/` — `TaskSourcesConfig` block feeding domain defaults.
## Notes / gotchas
diff --git a/crates/openhuman-core/src/mcp/server/README.md b/crates/openhuman-core/src/mcp/server/README.md
index 7cbd5c0597..76a4328ccb 100644
--- a/crates/openhuman-core/src/mcp/server/README.md
+++ b/crates/openhuman-core/src/mcp/server/README.md
@@ -87,7 +87,9 @@ No `store.rs`. The only durable side effect is the **MCP write-audit log**, writ
## Used by
- `crates/openhuman-core/src/core/cli.rs` — dispatches `mcp` / `mcp-server` subcommands to `run_stdio_from_cli`; the only production entry point. (`crates/openhuman-core/src/core/legacy_aliases.rs` references the command surface; `about_app/catalog.rs` lists it in the capability catalog.)
-- The other `mcp/` members (`mcp::registry`, `mcp::config_servers`, `mcp::http_client`, `mcp::audit`) and `tool_registry` are **siblings** in the broader MCP feature set, not consumers of this server's code paths (except the test-only `McpHttpClient` round-trip).
+- `crates/openhuman-core/src/inference/provider/claude_code/driver.rs` — calls `ensure_local_http` on each Claude Code turn to hand the sandboxed `claude` subprocess a loopback MCP endpoint.
+- `crates/openhuman-core/src/tools/registry/ops.rs` — reads `McpToolSpec`/`tool_specs()` (via `crate::mcp::server::McpToolSpec`) to fold this server's advertised tools into the agent tool registry catalog.
+- The other `mcp/` members (`mcp::host`, `mcp::registry`, `mcp::audit`) are siblings in the broader MCP feature set, not consumers of this server's code paths. `mcp::http_client` is a re-export module of `tinymcp`, used here only by the test-only `McpHttpClient` HTTP round-trip.
## Notes / gotchas
diff --git a/crates/openhuman-core/src/security/policy/README.md b/crates/openhuman-core/src/security/policy/README.md
new file mode 100644
index 0000000000..1137af788a
--- /dev/null
+++ b/crates/openhuman-core/src/security/policy/README.md
@@ -0,0 +1,104 @@
+# Security / Policy
+
+`SecurityPolicy` and the autonomy/risk machinery it implements. This is where
+every invariant AGENTS.md lists for the autonomy policy is actually enforced:
+`action_dir` vs `workspace_dir`, workspace-internal path protection,
+fail-closed command classification, always-forbidden system/credential paths,
+trusted roots, and the per-hour action budget.
+
+## Responsibilities
+
+- Build a `SecurityPolicy` from `AutonomyConfig` (`SecurityPolicy::from_config`).
+- Classify shell commands into a risk level (`CommandRiskLevel`) and a
+ fail-closed gate class (`CommandClass`), and turn that into a `GateDecision`
+ for the current `AutonomyLevel`.
+- Decide whether a filesystem path is reachable at all
+ (`is_always_forbidden`), workspace-internal state
+ (`is_workspace_internal_path`), or covered by a `TrustedRoot`.
+- Track and enforce the hourly action budget (`ActionTracker`).
+- Own the two stable string markers (`POLICY_BLOCKED_MARKER`,
+ `POLICY_DENIED_MARKER`) the agent harness's repeated-failure middleware
+ keys on to stop retrying a provably-futile call.
+
+## Key files
+
+| File | Purpose |
+| --- | --- |
+| `types.rs` | `SecurityPolicy` fields, `AutonomyLevel`, `CommandRiskLevel`, `CommandClass`, `GateDecision`, `ToolOperation`, `ActionTracker`, `TrustedRoot`/`TrustedAccess`, `ActiveProfileGuard`, `WORKSPACE_INTERNAL_DIRS`/`WORKSPACE_INTERNAL_FILES`, the two policy markers |
+| `path_checks.rs` | `is_workspace_internal_path`, `is_always_forbidden`, `check_cross_profile`, `is_within_trusted_root`, `is_resolved_path_allowed[_for]`, `check_resolved_against_forbidden` |
+| `command_checks.rs` | `classify_command`, `gate_decision`, `check_gated_command`, `is_command_allowed`, `command_risk_level`, `parse_declared_class`, `is_command_executor`, `split_unquoted_segments` |
+| `enforcement.rs` | `can_act`, `enforce_write_tier`, `enforce_tool_operation`, `record_action`/`is_rate_limited`, `from_config`, `with_active_profile`/`with_privacy_mode`, `openhuman_scratch_dir`/`ensure_openhuman_scratch_dir`, `validate_path_within_root` |
+| `policy_command.rs` (`policy_command_part_01.rs`, `policy_command_part_02.rs` via `#[path]`) | Command-allowlist matching split across parts for file-size hygiene |
+
+## Public surface
+
+Re-exported through `policy/mod.rs` and then through `security/mod.rs`:
+`SecurityPolicy`, `AutonomyLevel`, `CommandClass`, `CommandRiskLevel`,
+`GateDecision`, `ToolOperation`, `ActionTracker`, `ActiveProfileGuard`,
+`TrustedRoot`, `TrustedAccess`, `POLICY_BLOCKED_MARKER`,
+`POLICY_DENIED_MARKER`, `validate_path_within_root`,
+`ensure_openhuman_scratch_dir`, `openhuman_scratch_dir`.
+
+`live_policy.rs` (`security/live_policy.rs`, a sibling of this directory)
+holds the hot-swappable *current* `SecurityPolicy` in a process-global cell so
+a runtime `[autonomy]` config change is observed by new sessions immediately
+instead of only at the next full policy rebuild. `security_for_tool_context`
+clones the live policy with its `action_dir` overridden to a profile's own
+directory when a turn runs under a dedicated-workspace profile.
+
+## Invariants
+
+Each of these must not be weakened to make a feature work:
+
+- **`action_dir` vs `workspace_dir`.** `action_dir` is the agent's action
+ sandbox root — tools resolve relative paths and default their cwd there.
+ `workspace_dir` holds core-internal state (memory DBs, sessions, tokens) and
+ is never reachable from an agent tool call. Kept as two separate fields on
+ `SecurityPolicy` (`types.rs`) specifically so the two roots can diverge.
+- **`is_workspace_internal_path`** (`path_checks.rs:420`) — true for any path
+ whose first component under `workspace_dir` is in `WORKSPACE_INTERNAL_DIRS`
+ (`types.rs:173`) or `WORKSPACE_INTERNAL_FILES` (`types.rs:211`), or starts
+ with `memory-`, `memory_tree-`, or `session_raw-`. Checked against the
+ canonicalized form of both paths when possible, falling back to the raw
+ paths for not-yet-existing targets.
+- **`is_always_forbidden`** (`path_checks.rs:471`) — case-insensitive,
+ segment-based match against `SENSITIVE_COMPONENTS` (`.ssh`, `.gnupg`,
+ `.aws`, `.azure`, `.kube`, `keychains`, Windows DPAPI dirs) plus a prefix
+ match against `SYSTEM_PREFIXES` (`/etc`, `/root`, `/boot`, `/proc`, `/sys`,
+ `/system`, `C:\Windows`, `C:\Program Files[ (x86)]`, `C:\ProgramData`).
+ Unconditional — a `trusted_root` grant can never reach these paths. Gray-area
+ directories (`/usr`, `/opt`, `/var`, `~/Library`) deliberately stay in the
+ user-overridable `forbidden_paths` list instead, so a grant can still reach
+ e.g. `/usr/local/...`.
+- **`classify_command`'s fail-closed floor** (`command_checks.rs:126`) — a
+ command that is not provably read-only (and not a recognized
+ network/destructive command) is at least `CommandClass::Write`. The highest
+ class across `;`/`|`/`&&`/`||`/newline-separated segments wins, and any
+ unquoted redirect (`>`, `>>`) or `tee` lifts the whole command to at least
+ `Write`. An LLM-declared category (`parse_declared_class`) is
+ escalate-only: callers combine it as `gate = classify_command(cmd).max(declared)`,
+ so the model can raise the gate but never lower what the runtime determined.
+- **Approval gate default-on, marker semantics.** `POLICY_BLOCKED_MARKER`
+ (`[policy-blocked]`) prefixes a *permanent* rejection — the identical call
+ can never succeed in the current tier (read-only blocking a write, a
+ forbidden/credential path, a disallowed high-risk or hidden-execution
+ command). `POLICY_DENIED_MARKER` (`[policy-denied]`) prefixes a *this-turn*
+ denial — the user said no to an approval prompt, or it timed out. The agent
+ harness's `RepeatedToolFailureMiddleware` keys on these to halt on the first
+ verbatim repeat instead of reiterating a provably-futile call. See
+ [`../approval/README.md`](../approval/README.md) for the gate itself and its
+ 10-minute default TTL.
+- **Hourly action budget.** `ActionTracker` (`types.rs:124`) is a sliding
+ one-hour window; `enforce_tool_operation`'s `Act` arm
+ (`enforcement.rs`) calls `record_action` and refuses once the count exceeds
+ `max_actions_per_hour`. `enforce_write_tier` alone (tier only, no budget) is
+ used by callers that write at a finer grain than one tool call, e.g. the
+ kernel memory guard under `MemoryCore::store`.
+
+## Tests
+
+- `policy_tests.rs` plus `policy_tests_part_01..05_tests.rs` — behavior tests
+ for classification, path checks, and tier enforcement.
+- `proptest_tests.rs` — property tests over command classification.
+- `enforcement_scratch_dir_tests_tests.rs` — `openhuman_scratch_dir`/
+ `ensure_openhuman_scratch_dir` symlink/TOCTOU hardening.
diff --git a/crates/openhuman-core/src/web3/README.md b/crates/openhuman-core/src/web3/README.md
index b057b02421..64a14240d2 100644
--- a/crates/openhuman-core/src/web3/README.md
+++ b/crates/openhuman-core/src/web3/README.md
@@ -41,7 +41,7 @@ documented by this README and two with their own README each:
`pub mod web3;` (declared in `crates/openhuman-core/src/lib.rs`) is ALWAYS
compiled — it is a facade. The real swap/bridge/dapp implementation is gated
behind the default-ON `web3` Cargo feature. When the feature is off,
-[`stub.rs`](mod.rs) takes its place and exposes
+`stub.rs` takes its place and exposes
`all_web3_registered_controllers` / `all_web3_controller_schemas` /
`all_web3_agent_tools` returning empty collections, so `core/all.rs` and
`tools/ops.rs` need no per-call `#[cfg]`. `cargo check --no-default-features`
diff --git a/crates/openhuman-core/src/web_chat/session.rs b/crates/openhuman-core/src/web_chat/session.rs
index 6811aa52ed..e8742cc2a4 100644
--- a/crates/openhuman-core/src/web_chat/session.rs
+++ b/crates/openhuman-core/src/web_chat/session.rs
@@ -1,3 +1,8 @@
+//! Builds and fingerprints the cached session `Agent`: target agent
+//! resolution, model-override normalization, locale reply directive, and the
+//! `SessionCacheFingerprint` that decides whether a cached agent can be
+//! reused for the next turn on a thread.
+
use crate::agent::profiles::{AgentProfile, DEFAULT_PROFILE_ID};
use crate::agent::Agent;
use crate::config::Config;