Skip to content

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

docs(core): update READMEs for context and tool registry modules

Steven Enamakel16434749fffd
diff --git a/crates/openhuman-core/src/agent/context/README.md b/crates/openhuman-core/src/agent/context/README.md
index 7c0925ccc5..abcd630a58 100644
--- a/crates/openhuman-core/src/agent/context/README.md
+++ b/crates/openhuman-core/src/agent/context/README.md
@@ -1,39 +1,38 @@
# context
-Global context management for agent sessions: the home for system-prompt assembly, per-session context bookkeeping (utilisation stats, budget configuration, session-memory triggers), and prompt-cache diagnostics. Agents hold one `ContextManager` per session. This is a **pure logic / state-tracking domain** — no RPC controllers, no agent tools, no event-bus subscribers, no persisted store.
+Global context management for agent sessions: system-prompt assembly, per-session context bookkeeping (utilisation stats, budget configuration, session-memory triggers), and the shared microcompact constants. Agents hold one `ContextManager` per session. This is a **pure logic / state-tracking domain** — no RPC controllers, no agent tools, no event-bus subscribers, no persisted store.
-> **Status (#4249): live history reduction/summarization moved to the tinyagents graph.** The in-turn compaction that used to live here — `ContextManager::reduce_before_call`, the `Summarizer` trait, `ProviderSummarizer`, `SegmentRecapSummarizer`, `context/microcompact.rs`, `context/pipeline.rs`, and `context/guard.rs` — has been **removed**. Folding an over-budget transcript into a summary now runs as `ContextCompressionMiddleware` (+ `MessageTrimMiddleware` backstop) inside `run_turn_via_tinyagents_shared`, backed by `tinyagents::summarize::ModelSummarizer`. Tool-result body clearing now runs in TinyAgents `MicrocompactMiddleware`; `context/stats.rs` keeps the data model behind `ContextManager::stats()` (the utilisation footer) and session-memory bookkeeping.
+> **Status (#4249): live history reduction/summarization moved out of this directory.** The in-turn compaction that used to live here (`ContextManager::reduce_before_call`, the `Summarizer` trait, `ProviderSummarizer`, `SegmentRecapSummarizer`, `microcompact.rs`, `pipeline.rs`, `guard.rs`) is gone — see [History](#history-4249). Folding an over-budget transcript into a summary now runs as the vendored `tinyagents_harness::middleware::ContextCompressionMiddleware` (with the seam-owned `ImageAwareMessageTrimMiddleware` as the deterministic backstop) inside `run_turn_via_tinyagents_shared` (`agent/tinyagents/mod_part_02.rs`), backed by `agent/tinyagents/summarize.rs::ModelSummarizer`. Tool-result body clearing runs in `tinyagents_harness::middleware::MicrocompactMiddleware`. `stats.rs` keeps the data model behind `ContextManager::stats()` and session-memory bookkeeping.
## Responsibilities
-- Assemble opening system prompts (delegates to `agent::prompts` via `prompt.rs`; provides a separate bespoke builder for channel runtimes).
+- Assemble opening system prompts (delegates to `agent::prompts` via `prompt.rs`; provides a separate bespoke builder for channel runtimes in `channels_prompt.rs`).
- Track context-window utilisation per session (`ContextStatsState`).
-- Expose the configured per-tool-result byte budget; enforcement now lives in TinyAgents tool-output middleware and action-workspace artifact previews.
-- Expose microcompact configuration/placeholder constants consumed by TinyAgents middleware.
-- Maintain session-memory and utilisation bookkeeping (`stats.rs`).
-- Track session-memory extraction thresholds (token growth, tool calls, turns) and report when a background archivist extraction should fire — without spawning it itself (`session_memory`).
+- Expose the configured per-tool-result byte budget and the compaction/microcompact/autocompact toggles the tinyagents turn reads; enforcement lives in `agent/tinyagents` (`ToolOutputMiddleware`, `MicrocompactMiddleware`, `ContextCompressionMiddleware`) and in `agent/harness/tool_result_artifacts`.
+- Expose the microcompact placeholder/keep-recent constants consumed by the microcompact middleware.
+- Track session-memory extraction thresholds (token growth, tool calls, turns) and report when a background archivist extraction should fire — without spawning it itself (`session_memory.rs`).
## Key files
| File | Role |
| --- | --- |
-| `crates/openhuman-core/src/agent/context/mod.rs` | Module docstring + `pub mod` decls + `pub use` re-exports. Export-focused, no logic. |
-| `crates/openhuman-core/src/agent/context/manager.rs` | `ContextManager` — per-session handle agents hold. Owns the default prompt builder, stats/session-memory state, and budget/markdown config. Surfaces `build_system_prompt`, `stats()`, tool-result budget settings, and session-memory triggers. (The former `reduce_before_call`/summarizer dispatch was removed in #4249.) |
-| `crates/openhuman-core/src/agent/context/stats.rs` | `ContextStatsState` — provider usage, context-window utilisation, and shared `SessionMemoryHandle` bookkeeping. Pure state; issues no LLM calls and does not mutate history. |
-| `crates/openhuman-core/src/agent/context/session_memory.rs` | `SessionMemoryState` / `SessionMemoryConfig` — threshold-gated `should_extract` decision (token growth + tool calls + turns must all cross) and extraction bookkeeping. Holds `ARCHIVIST_EXTRACTION_PROMPT`. State-tracking only; does not spawn the archivist. |
-| `crates/openhuman-core/src/agent/context/prompt.rs` | Compat shim — `pub use crate::agent::prompts::*`. Prompt rendering moved to `agent::prompts`; this keeps `context::prompt::...` as a stable import path. |
-| `crates/openhuman-core/src/agent/context/channels_prompt.rs` | Bespoke free-function `build_system_prompt(...)` for channel runtimes (Discord/Slack/Telegram/…). Byte-stable for prefix-cache hits; injects OpenClaw bootstrap files (`SOUL.md`, `IDENTITY.md`, optional `PROFILE.md`/`MEMORY.md`), tools, safety, skills, runtime, and channel-capabilities sections. |
-| `crates/openhuman-core/src/agent/context/manager_tests.rs` | Sibling test suite wired via `#[cfg(test)] #[path = ...] mod tests`. Other files use inline `#[cfg(test)] mod tests`. |
+| `crates/openhuman-core/src/agent/context/mod.rs` | Module docstring, `pub mod` decls, `pub use` re-exports, and the three shared constants (`DEFAULT_TOOL_RESULT_BUDGET_BYTES`, `CLEARED_PLACEHOLDER`, `DEFAULT_KEEP_RECENT_TOOL_RESULTS`). No other logic. |
+| `crates/openhuman-core/src/agent/context/manager.rs` | `ContextManager` — per-session handle agents hold. Owns the default prompt builder, `ContextStatsState`, and the `ContextConfig`-derived knobs. Surfaces `build_system_prompt` / `build_system_prompt_tiered` / `build_system_prompt_with`, `stats()`, the getters the tinyagents turn reads (`tool_result_budget_bytes`, `compaction_enabled`, `microcompact_keep_recent`, `autocompact_enabled`, `prefer_markdown_tool_output`), and the session-memory trigger/mark methods. |
+| `crates/openhuman-core/src/agent/context/stats.rs` | `ContextStatsState` — last provider usage, context-window utilisation, and the shared `SessionMemoryHandle` (`Arc<Mutex<SessionMemoryState>>`). Pure state; issues no LLM calls and does not mutate history. |
+| `crates/openhuman-core/src/agent/context/session_memory.rs` | `SessionMemoryState` / `SessionMemoryConfig` — threshold-gated `should_extract` decision (token growth, tool calls, and turns must all cross) and extraction bookkeeping. Holds `ARCHIVIST_EXTRACTION_PROMPT`. State-tracking only; does not spawn the archivist. |
+| `crates/openhuman-core/src/agent/context/prompt.rs` | Compat shim — `pub use crate::agent::prompts::*`. Prompt rendering lives in `agent::prompts`; this keeps `context::prompt::...` as a stable import path. |
+| `crates/openhuman-core/src/agent/context/channels_prompt.rs` | Bespoke free functions `build_system_prompt(...)` / `build_system_prompt_with_identity(...)` (plus `PromptIdentityOverride`, `ProjectContextPlacement`, `render_project_context`) for channel runtimes (Discord/Slack/Telegram/…). Byte-stable for prefix-cache hits; injects workspace bootstrap files (`SOUL.md`, `IDENTITY.md`, optional `PROFILE.md`/`MEMORY.md`, with profile overrides for `SOUL.md`/`MEMORY.md`), tools, safety, skills, runtime, and channel-capabilities sections. |
+| `crates/openhuman-core/src/agent/context/manager_tests.rs`, `channels_prompt_tests.rs`, `session_memory_tests.rs` | Sibling test files wired via `#[cfg(test)] #[path = "..."] mod tests;` from their source file (the layout check rejects inline test modules). |
## History (#4249)
-Live history reduction/summarization moved out of this directory into the tinyagents graph:
+Live history reduction/summarization moved out of this directory into the tinyagents turn path:
-- `pipeline.rs` — removed; live context reduction moved to TinyAgents middleware, stats/session-memory state lives in `context/stats.rs`.
-- `guard.rs` — removed; the live 0.90 compression threshold is mirrored by `tinyagents::summarize::SUMMARIZE_THRESHOLD_FRACTION`.
-- `microcompact.rs` — removed; live tool-result body clearing is owned by TinyAgents `MicrocompactMiddleware`, only shared constants remain in `context/mod.rs`.
+- `pipeline.rs` — removed; live context reduction moved to tinyagents middleware, stats/session-memory state lives in `stats.rs`.
+- `guard.rs` — removed; the live 0.90 compression threshold is `SUMMARIZE_THRESHOLD_FRACTION` in `agent/tinyagents/summarize.rs`.
+- `microcompact.rs` — removed; live tool-result body clearing is owned by `tinyagents_harness::middleware::MicrocompactMiddleware`, only the shared constants remain in `mod.rs`.
- `tool_result_budget.rs` — removed; UTF-8-safe per-result truncation moved next to action-workspace artifact preview/fallback handling in `agent/harness/tool_result_artifacts`.
-- `summarizer.rs` — removed; live summarization moved to `tinyagents::summarize` (`ModelSummarizer`), the summarizer system prompt was relocated there.
+- `summarizer.rs` — removed; live summarization moved to `agent/tinyagents/summarize.rs` (`ModelSummarizer`, which also carries the summarizer system prompt).
- `segment_recap_summarizer.rs` — removed; the archivist-recap-backed compaction wrapper is gone, the archivist still produces durable segment recaps on its own post-turn path.
- `summarizer_tests.rs` / `segment_recap_summarizer_tests.rs` — removed along with the files above.
@@ -43,19 +42,19 @@ From `mod.rs` re-exports:
- **Manager**: `ContextManager`, `ContextStats`.
- **Microcompact config**: `CLEARED_PLACEHOLDER`, `DEFAULT_KEEP_RECENT_TOOL_RESULTS`.
-- **Stats**: `ContextStats` via `ContextManager::stats()`; internal
- bookkeeping stays in `ContextStatsState` / `SessionMemoryHandle`.
-- **Prompt** (re-exported from `agent::prompts`): `SystemPromptBuilder`, `PromptSection`, `PromptContext`, `PromptTool`, `ArchetypePromptSection`, `DateTimeSection`, `IdentitySection`, `LearnedContextData`, `RuntimeSection`, `SafetySection`, `ToolsSection`, `WorkspaceSection`.
+- **Prompt** (re-exported from `agent::prompts`): `SystemPromptBuilder`, `PromptSection`, `PromptContext`, `PromptTool`, `ArchetypePromptSection`, `DateTimeSection`, `IdentitySection`, `LearnedContextData`, `RuntimeSection`, `SafetySection`, `ToolsSection`, `WorkspaceSection`. The full `agent::prompts` surface is reachable through `context::prompt::*`.
- **Session memory**: `SessionMemoryConfig`, `SessionMemoryState`, `ARCHIVIST_EXTRACTION_PROMPT`, `DEFAULT_MIN_TOKEN_GROWTH`, `DEFAULT_MIN_TOOL_CALLS`, `DEFAULT_MIN_TURNS_BETWEEN`.
-- **Tool-result budget**: `DEFAULT_TOOL_RESULT_BUDGET_BYTES` config default only; live truncation logic is owned by TinyAgents tool-output middleware / tool-result artifacts.
+- **Tool-result budget**: `DEFAULT_TOOL_RESULT_BUDGET_BYTES` config default only; live truncation is owned by `ToolOutputMiddleware` / `tool_result_artifacts`.
+
+`ContextStatsState` and `SessionMemoryHandle` are `pub(crate)` and not re-exported.
## RPC / controllers
-None. No `schemas.rs`, no `all_controller_schemas`, no `handle_*`. `ContextStats` doc comments reference an optional `context.get_stats` / `context.get_stats` RPC, but the schema/handler is not defined in this module.
+None. No `schemas.rs`, no `all_controller_schemas`, no `handle_*`. The `ContextStats` doc comment mentions an "optional `context.get_stats` RPC", but no such schema or handler exists anywhere in the crate.
## Agent tools
-None. No `tools.rs`. (Session-memory extraction uses the `update_memory_md` / `memory_recall` / `memory_search` tools, but those are owned elsewhere; this module only references them in prompt text.)
+None. No `tools.rs`. `ARCHIVIST_EXTRACTION_PROMPT` tells the spawned archivist to use the `update_memory_md` tool, which is owned elsewhere; this module only references it in prompt text.
## Events
@@ -65,31 +64,32 @@ None. No `bus.rs`; no `DomainEvent`s published or subscribed.
No `store.rs`. State is per-session and in-memory:
-- `ContextStatsState` holds last token counts, context window, and the shared
- `SessionMemoryHandle`.
-- `SessionMemoryState` (behind a shared `Arc<Mutex<…>>` `SessionMemoryHandle`) tracks cumulative tokens / tool calls / turn counters and extraction-in-progress flag; resets naturally when a session ends.
+- `ContextStatsState` holds last token counts, context window, and the shared `SessionMemoryHandle`.
+- `SessionMemoryState` (behind the `Arc<Mutex<…>>` `SessionMemoryHandle`) tracks cumulative tokens / tool calls / turn counters and the extraction-in-progress flag; it resets naturally when a session ends.
-The durable long-term substrate session-memory targets is the workspace `MEMORY.md` file, but that file is written by the spawned archivist sub-agent (owned by the agent harness), not by this module.
+The durable substrate session-memory targets is the workspace `MEMORY.md` file, written by the spawned archivist sub-agent (owned by the agent harness), not by this module.
## Dependencies
-- `crate::config` — reads `ContextConfig` (`config/schema/context.rs`): enabled flag, microcompact/autocompact toggles, `summarizer_model`, `tool_result_budget_bytes`, `prefer_markdown_tool_output`, and embedded `SessionMemoryConfig` thresholds.
-- `crate::inference::provider` — core types including `UsageInfo`.
-- `crate::agent::prompts` — `prompt.rs` re-exports the entire prompt-section/builder surface from here (prompt logic lives next to the agents that consume it).
-- `crate::skills::Skill` — `channels_prompt.rs` renders the available-skills section.
+- `crate::config` — `ContextConfig` (`config/schema/context.rs`): `enabled`, `microcompact_enabled` / `microcompact_keep_recent`, `autocompact_enabled`, `compaction_enabled`, `tool_result_budget_bytes`, `prefer_markdown_tool_output`, `summarizer_model`, and the embedded `session_memory: SessionMemoryConfig`.
+- `crate::inference::provider::UsageInfo` — fed into `record_usage`.
+- `crate::agent::prompts` — `prompt.rs` re-exports its whole surface; `channels_prompt.rs` uses `inject_inline_content`.
+- `crate::skills::Workflow` — `channels_prompt.rs` renders the available-skills section from a `&[Workflow]`.
+
## Used by
-- **`agent::harness`** — the primary consumer: `session/builder.rs` constructs the `ContextManager`; `session/turn.rs` drives the session-memory counters and spawns the archivist extraction when `should_extract_session_memory` says so; `fork_context.rs`, `subagent_runner/*`, and `tool_filter.rs` consume the prompt builder and stats/budget surface. (History reduction/summarization moved to the tinyagents graph in #4249 — see the status banner above; `reduce_before_call`/`ProviderSummarizer`/`SegmentRecapSummarizer`/`unified_compaction_enabled` are removed.)
-- **`agent::agents/*/prompt.rs`** — every archetype prompt module pulls prompt sections/builder through `context::prompt`.
-- **`channels`** — `channels/runtime/startup.rs` (and channel prompt/identity tests) call `channels_prompt::build_system_prompt`.
-- **`agent::dispatcher`, `agent::triage`, `agent::tools` (spawn_subagent / spawn_parallel / spawn_worker_thread), `learning::prompt_sections`, `memory_tools::prompt`, `tools::orchestrator_tools`, `composio::ops`** — consume the prompt-building surface.
+- **`agent::harness`** — the primary consumer: `session/builder/builder_build.rs` constructs the `ContextManager`; `session/turn/core_turn.rs` drives the session-memory counters and spawns the archivist extraction when `should_extract_session_memory` says so; `session/turn/core_session_part_01.rs` reads the budget/compaction getters into the tinyagents turn config; `session/turn/session_io_impl_01_part_02.rs` reads `stats()`; `fork_context.rs`, `subagent_runner/*`, and `tool_filter.rs` consume prompt types.
+- **`agent::tinyagents`** — `middleware_part_01.rs` and `mod_part_04.rs` read `CLEARED_PLACEHOLDER` when configuring `MicrocompactMiddleware`; `payload_summarizer.rs` and `host/context_composer.rs` build `PromptContext`s through `context::prompt`.
+- **`agent::registry::agents/*/prompt.rs`**, `flows/agents/*/prompt.rs`, `memory/agent/agent/prompt.rs`, `skills/*/agent/*/prompt.rs` — archetype prompt modules pull prompt sections/builder through `context::prompt`.
+- **`channels`** — `channels/system_prompt.rs` (`ChannelSystemPrompt`, used by `channels/runtime/startup_part_01.rs`) calls `channels_prompt::build_system_prompt_with_identity`; `channels/mod.rs` re-exports `build_system_prompt`; the `channels/tests/*` prompt/identity tests call it directly.
+- **`agent::dispatcher`, `agent::triage`, `agent::debug`, `agent::orchestration::tools` (spawn_subagent and friends), `agent::learning::prompt_sections`, `agent::profiles::prompt_section`, `memory::tool_memory::prompt`, `tools::orchestrator_tools`, `integrations::composio`** — consume prompt types (`PromptContext`, `PromptSection`, `ToolCallFormat`, `ConnectedIntegration`, …) via `context::prompt`.
- **`config::schema`** — `context.rs` embeds `SessionMemoryConfig`.
## Notes / gotchas
-- **The context stats state issues no LLM calls and does not mutate history.** Live reduction is owned by TinyAgents middleware.
-- **Tool-result budgeting is not a context pipeline stage.** The live TinyAgents path applies per-result budgets in `ToolOutputMiddleware`, and artifact-preview fallback truncation lives in `agent/harness/tool_result_artifacts`.
-- **Cache contract**: cache-affecting history rewrites live in TinyAgents middleware, where the run can emit the corresponding events.
+- **The context stats state issues no LLM calls and does not mutate history.** Live reduction is owned by the tinyagents middleware stack.
+- **Tool-result budgeting is not a context pipeline stage.** The tinyagents path applies per-result budgets in `ToolOutputMiddleware` (`agent/tinyagents/middleware_part_01.rs`), and artifact-preview fallback truncation lives in `agent/harness/tool_result_artifacts`.
+- **`autocompact_enabled()` is `config.enabled && config.autocompact_enabled`**, and `microcompact_keep_recent()` is `0` when `microcompact_enabled` is off — the manager folds the config gates so the turn reads one value per knob.
- **Session memory is separate from compaction**: it does not mutate in-flight history; it gates a *persistent* `MEMORY.md` extraction. All three thresholds (token growth, tool calls, turns) must be crossed and no extraction may be in flight. `mark_extraction_failed` keeps deltas so the next turn retries; `mark_extraction_complete` resets them. The handle is `Arc`-cloned so a detached background task can flip completion state after the synchronous borrow is released.
- **`prompt.rs` is a compat shim** — do not add prompt logic here; it lives in `agent::prompts`.
- **`channels_prompt::build_system_prompt` deliberately bypasses `SystemPromptBuilder`** to keep production channel prompt bytes stable for prefix-cache hits; it is a standalone free function despite living under `context/`.
diff --git a/crates/openhuman-core/src/tools/registry/README.md b/crates/openhuman-core/src/tools/registry/README.md
index 8aa7af794d..a410a3d425 100644
--- a/crates/openhuman-core/src/tools/registry/README.md
+++ b/crates/openhuman-core/src/tools/registry/README.md
@@ -4,10 +4,10 @@ Unified **read-only** tool registry for OpenHuman. It builds a single discovery
## Responsibilities
-- Build a sorted, de-duplicated registry snapshot from three sources: `mcp_server` stdio tool specs, `tools` controller schemas, and `mcp_registry` connected-client tools.
+- Build a sorted, de-duplicated registry snapshot from three sources: `mcp::server` stdio tool specs, `tools` controller schemas (`crate::tools::all_tools_controller_schemas()`), and `mcp::registry::connections` connected-client tools.
- Normalize controller `ControllerSchema` inputs/outputs into JSON Schema; attach transport (`json_rpc` / `mcp_stdio`), route metadata, tags, `allowed_agents` (`*` in this MVP), `enabled`, and `health`.
- Serve `list` / `get` (by `tool_id`) RPC lookups over the registry.
-- Produce redacted `diagnostics`: tool counts by transport, heuristic write-capable surfaces, policy surfaces, autonomy posture, MCP allowlist summaries, MCP write-audit row counts (last 24h), recent denials, and capability-provider counts.
+- Produce redacted `diagnostics`: tool counts by transport, heuristic write-capable surfaces, policy surfaces, autonomy posture, MCP allowlist summaries, MCP write-audit row counts (last 24h), the 25 most recent denials, and capability-provider counts.
- Maintain a bounded, secret-redacting in-memory log of recent policy denials (`denials.rs`).
- Normalize and validate configured external **capability providers** (id slugging, dedupe, trust/enabled state) for policy and diagnostics callers (`providers.rs`).
@@ -15,21 +15,21 @@ Unified **read-only** tool registry for OpenHuman. It builds a single discovery
| File | Role |
| --- | --- |
-| `crates/openhuman-core/src/tools/registry/mod.rs` | Export-focused. Re-exports ops, providers, schemas (as `all_tool_registry_*`), and types. |
-| `crates/openhuman-core/src/tools/registry/ops.rs` | Core logic: `registry_entries()`, `list_tools()`, `get_tool()`, `diagnostics()` / `diagnostics_for_config()`, plus schema→JSON-Schema conversion, tagging, write-capability heuristics, MCP write-audit health query. |
+| `crates/openhuman-core/src/tools/registry/mod.rs` | Export-focused. `pub mod denials` and `pub mod ops`; re-exports ops entry points, providers, schemas (as `all_tool_registry_*`), and types. |
+| `crates/openhuman-core/src/tools/registry/ops.rs` | Core logic: `registry_entries()` / `registry_entries_for_config()`, `list_tools()`, `get_tool()`, `diagnostics()` / `diagnostics_for_config()`, plus schema→JSON-Schema conversion, tagging, write-capability heuristics, MCP write-audit health query. |
| `crates/openhuman-core/src/tools/registry/types.rs` | Serde response types: `ToolRegistryEntry`, `ToolRegistryList`, `ToolRegistryTransport`, `ToolRegistryHealth`, `ToolPolicyDiagnostics` + sub-structs, `RecentPolicyDenial`, `CapabilityProviderDiagnostics`. |
-| `crates/openhuman-core/src/tools/registry/schemas.rs` | Controller schemas + `handle_list` / `handle_get` / `handle_diagnostics` handlers delegating to `ops.rs`. Inline tests. |
-| `crates/openhuman-core/src/tools/registry/providers.rs` | `CapabilityProviderRegistry` over config: id normalization, dedupe, trust checks, redacted diagnostics. Inline tests. |
-| `crates/openhuman-core/src/tools/registry/denials.rs` | Static `Mutex<VecDeque>` ring buffer (max 50) of recent policy denials; `record()` / `list()`; redacts secret markers, truncates reasons. Inline tests. |
-| `crates/openhuman-core/src/tools/registry/ops_tests.rs` | Sibling test module for `ops.rs` (`#[path]`-included). |
+| `crates/openhuman-core/src/tools/registry/schemas.rs` | Controller schemas + `handle_list` / `handle_get` / `handle_diagnostics` handlers delegating to `ops.rs`. |
+| `crates/openhuman-core/src/tools/registry/providers.rs` | `CapabilityProviderRegistry` over config: id normalization, dedupe, trust checks, redacted diagnostics. |
+| `crates/openhuman-core/src/tools/registry/denials.rs` | Static `Mutex<VecDeque>` ring buffer (max 50) of recent policy denials; `record()` / `list()`; redacts secret markers, truncates reasons. |
+| `crates/openhuman-core/src/tools/registry/{ops,schemas,providers,denials}_tests.rs` | Sibling `#[path]`-included test modules for each file above. |
## Public surface
-- From `ops`: `get_tool`, `list_tools`, `registry_entries`.
+- From `ops`: `get_tool`, `list_tools`, `registry_entries`, `registry_entries_for_config`. `ops` is also `pub mod`, so `ops::diagnostics_for_config` is reachable (used by the raw-coverage tests).
- From `providers`: `CapabilityProviderMetadata`, `CapabilityProviderRegistry`, `CapabilityProviderRegistryError`, `capability_provider_by_id`, `capability_provider_diagnostics`, `capability_provider_registry`, `is_capability_provider_trusted_enabled`, `list_capability_providers`, `normalize_capability_provider_id`.
- From `schemas`: `all_tool_registry_controller_schemas`, `all_tool_registry_registered_controllers`.
- From `types`: `ToolRegistryEntry`, `ToolRegistryList`, `ToolRegistryTransport`, `ToolRegistryHealth`, `ToolPolicyDiagnostics`, `ToolPolicyPosture`, `McpAllowlistDiagnostics`, `McpServerAllowlistSummary`, `McpWriteAuditHealth`, `RecentPolicyDenial`, `CapabilityProviderDiagnostics`.
-- `denials` is `pub mod` — consumers call `tool_registry::denials::record(...)` directly.
+- `denials` is `pub mod` — consumers call `tools::registry::denials::record(...)` directly.
## RPC / controllers
@@ -45,32 +45,33 @@ All handlers return `RpcOutcome<T>` serialized via `into_cli_compatible_json()`.
## Persistence
-No owned persistence. `diagnostics()` reads (read-only) the `mcp_writes` table via `memory_store::chunks::store::with_connection` to count rows in the last 24h for `McpWriteAuditHealth`. Recent denials live in a **process-global in-memory** `Mutex<VecDeque>` in `denials.rs` (not durable; max 50 entries).
+No owned persistence. `diagnostics()` reads the MCP write-audit log through `crate::mcp::audit::list_writes` (with a `McpWriteListQuery` whose `since_ms` is now minus 24h, capped at `tinymcp_bus::MAX_LIST_LIMIT` rows) to fill `McpWriteAuditHealth`; a query error lands in `last_error` rather than failing diagnostics. Recent denials live in a **process-global in-memory** `Mutex<VecDeque>` in `denials.rs` (not durable; max 50 entries).
## Dependencies
-- `crate::core::all` — `all_controller_schemas()` / `rpc_method_name()` to enumerate controller tools and resolve their RPC method names for routes/policy surfaces.
+- `crate::core::all` — `rpc_method_name()` for controller route metadata and `all_controller_schemas()` for the `security.` / `approval.` policy-surface scan. Registry *entries* for controllers come from `crate::tools::all_tools_controller_schemas()`, not the whole controller set.
- `crate::core::{ControllerSchema, FieldSchema, TypeSchema}` and `core::all::{ControllerFuture, RegisteredController}` — schema model and controller registration contract.
- `crate::config` (`Config`, `config::schema::CapabilityProviderTrustState`) — autonomy posture, MCP client allowlists, capability-provider config.
- `crate::mcp::server` (`McpToolSpec`, `tool_specs()`) — MCP stdio tool source for registry entries.
-- `crate::mcp::registry` (`all_connected_tools()`, defined in `mcp/registry/mod.rs`; a no-op stub in `mcp/registry/stub.rs` when the `mcp` feature is disabled) — live MCP client server tools, fetched via `block_in_place` only on the multi-thread runtime.
-- `tinymemory_core::store::chunks::store` — read-only `mcp_writes` audit query.
+- `crate::mcp::registry::connections` (`all_connected_tools()` / `all_connected_tools_for_config()`, defined inside `mcp/registry/mod.rs`; empty-returning stubs in `mcp/registry/stub.rs` when the `mcp` feature is disabled) — live MCP client server tools, fetched via `block_in_place` only on the multi-thread runtime.
+- `crate::mcp::audit` (`list_writes`, `McpWriteListQuery`; stubbed under `mcp/audit/stub.rs` without the `mcp` feature) — write-audit health.
- `crate::rpc::RpcOutcome` — RPC result envelope.
## Used by
- `crates/openhuman-core/src/core/all.rs` — registers controllers/schemas and routes the `tool_registry` namespace.
-- `crates/openhuman-core/src/agent/tinyagents/middleware.rs` — calls `tool_registry::denials::record(...)` to log agent-tool policy denials.
-- `crates/openhuman-core/src/platform/about_app/catalog.rs` — capability catalog references the registry surface.
-- `crates/openhuman-core/src/mcp/registry/mod.rs` — provides `all_connected_tools()` for registry integration (no-op in `stub.rs` when the `mcp` feature is disabled).
+- `crates/openhuman-core/src/agent/tinyagents/middleware.rs` (body in `middleware_part_03.rs`) — calls `tools::registry::denials::record(...)` when a tool call is denied or requires approval.
+- `crates/openhuman-core/src/platform/about_app/catalog_part_01.rs` — the `intelligence.tool_registry` capability entry points users at `openhuman.tool_registry_list` / `openhuman.tool_registry_get`.
+- `tests/raw_coverage/tool_registry_approval_raw_coverage_e2e.rs` and siblings — exercise `denials`, `ops::diagnostics_for_config`, and the provider registry directly.
## Notes / gotchas
- **Read-only by design** — the registry never executes tools; routes are descriptive metadata only.
-- **Duplicate `tool_id` is first-write-wins**: ordered MCP-stdio → controller → MCP-client; duplicates (e.g. external servers reusing well-known names) are logged and skipped, not overwritten.
+- **Duplicate `tool_id` is first-write-wins**: ordered MCP-stdio → controller → MCP-client; duplicates (e.g. external servers reusing well-known names) are logged and skipped, not overwritten. MCP-client ids are `mcp-client::<server_id>::<tool>` and route to `openhuman.mcp_clients_tool_call`.
- **MCP client enumeration is best-effort**: on a single-thread tokio runtime (e.g. unit tests) or with no runtime, connected-client tools silently fall back to empty, since `block_in_place` panics outside the multi-thread runtime.
+- **`registry_entries()` vs `registry_entries_for_config()`**: the ambient form resolves the MCP host through the process default, which stops answering once a second workspace is open in the process (test binaries). Callers holding a `Config` should use the `_for_config` variant.
- `looks_write_capable` is a **heuristic** over tool-id keywords (add/create/delete/send/write/…), surfaced as `possible_write_surfaces` for review — not an authoritative permission check.
- `policy_surfaces` includes a fixed seed list plus any controller whose method starts with `security.` / `approval.`.
-- Denial reasons are redacted on the markers `Bearer `, `sk-`, `ghp_`, `-----BEGIN` and truncated to 240 chars; entries are bounded to 50.
+- Denial reasons containing any of `Bearer `, `sk-`, `ghp_`, `-----BEGIN` are replaced wholesale with `[redacted: sensitive content]`, then truncated to 240 chars; entries are bounded to 50, and blank tool names are dropped.
- Capability-provider ids are slugged to lowercase alphanumerics with `-`/`_`/`.` separators (max 96 chars); invalid or post-normalization-duplicate ids return `CapabilityProviderRegistryError`.
- `version` on every entry is the core crate version (`CARGO_PKG_VERSION`), used as the registry schema/version marker.