Skip to content

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

refactor(registry): split large schemas module into smaller parts

Steven Enamakel067b63884b24
diff --git a/crates/openhuman-core/src/mcp/registry/schemas.rs b/crates/openhuman-core/src/mcp/registry/schemas.rs
deleted file mode 100644
index 9231380f89..0000000000
--- a/crates/openhuman-core/src/mcp/registry/schemas.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-//! Controller schemas and handler dispatch for the MCP clients domain.
-//!
-//! Every `schemas(function)` match arm defines the RPC method's input/output
-//! shape. Every `handle_*` function deserialises params and delegates to
-//! `ops.rs`.
-
-#[cfg(test)]
-#[path = "schemas_tests.rs"]
-mod tests;
-include!("schemas_part_01.rs");
-include!("schemas_part_02.rs");
diff --git a/crates/openhuman-core/src/mcp/registry/schemas_part_01.rs b/crates/openhuman-core/src/mcp/registry/schemas_part_01.rs
deleted file mode 100644
index 47f7c574a2..0000000000
--- a/crates/openhuman-core/src/mcp/registry/schemas_part_01.rs
+++ /dev/null
@@ -1,666 +0,0 @@
-use serde::de::DeserializeOwned;
-use serde_json::{Map, Value};
-
-use crate::core::all::{ControllerFuture, RegisteredController};
-use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
-use crate::config::rpc as config_rpc;
-use crate::rpc::RpcOutcome;
-
-// ── Schema registry ──────────────────────────────────────────────────────────
-
-pub fn all_controller_schemas() -> Vec<ControllerSchema> {
- vec![
- schemas("registry_search"),
- schemas("registry_get"),
- schemas("installed_list"),
- schemas("install"),
- schemas("update_env"),
- schemas("uninstall"),
- schemas("detect_auth"),
- schemas("oauth_begin"),
- schemas("connect"),
- schemas("disconnect"),
- schemas("status"),
- schemas("tool_call"),
- schemas("config_assist"),
- schemas("registry_settings_get"),
- schemas("registry_settings_set"),
- schemas("set_enabled"),
- // Setup-agent surface (mcp_setup namespace, lives in setup_ops.rs).
- setup_schemas("search"),
- setup_schemas("get"),
- setup_schemas("request_secret"),
- setup_schemas("submit_secret"),
- setup_schemas("test_connection"),
- setup_schemas("install_and_connect"),
- ]
-}
-
-pub fn all_registered_controllers() -> Vec<RegisteredController> {
- vec![
- RegisteredController {
- schema: schemas("registry_search"),
- handler: handle_registry_search,
- },
- RegisteredController {
- schema: schemas("registry_get"),
- handler: handle_registry_get,
- },
- RegisteredController {
- schema: schemas("installed_list"),
- handler: handle_installed_list,
- },
- RegisteredController {
- schema: schemas("install"),
- handler: handle_install,
- },
- RegisteredController {
- schema: schemas("update_env"),
- handler: handle_update_env,
- },
- RegisteredController {
- schema: schemas("uninstall"),
- handler: handle_uninstall,
- },
- RegisteredController {
- schema: schemas("detect_auth"),
- handler: handle_detect_auth,
- },
- RegisteredController {
- schema: schemas("oauth_begin"),
- handler: handle_oauth_begin,
- },
- RegisteredController {
- schema: schemas("connect"),
- handler: handle_connect,
- },
- RegisteredController {
- schema: schemas("disconnect"),
- handler: handle_disconnect,
- },
- RegisteredController {
- schema: schemas("status"),
- handler: handle_status,
- },
- RegisteredController {
- schema: schemas("tool_call"),
- handler: handle_tool_call,
- },
- RegisteredController {
- schema: schemas("config_assist"),
- handler: handle_config_assist,
- },
- RegisteredController {
- schema: schemas("registry_settings_get"),
- handler: handle_registry_settings_get,
- },
- RegisteredController {
- schema: schemas("registry_settings_set"),
- handler: handle_registry_settings_set,
- },
- RegisteredController {
- schema: schemas("set_enabled"),
- handler: handle_set_enabled,
- },
- RegisteredController {
- schema: setup_schemas("search"),
- handler: handle_setup_search,
- },
- RegisteredController {
- schema: setup_schemas("get"),
- handler: handle_setup_get,
- },
- RegisteredController {
- schema: setup_schemas("request_secret"),
- handler: handle_setup_request_secret,
- },
- RegisteredController {
- schema: setup_schemas("submit_secret"),
- handler: handle_setup_submit_secret,
- },
- RegisteredController {
- schema: setup_schemas("test_connection"),
- handler: handle_setup_test_connection,
- },
- RegisteredController {
- schema: setup_schemas("install_and_connect"),
- handler: handle_setup_install_and_connect,
- },
- ]
-}
-
-pub fn schemas(function: &str) -> ControllerSchema {
- match function {
- "registry_search" => ControllerSchema {
- namespace: "mcp_clients",
- function: "registry_search",
- description: "Search the Smithery.ai MCP server registry.",
- inputs: vec![
- FieldSchema {
- name: "query",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "Free-text search query.",
- required: false,
- },
- FieldSchema {
- name: "transport",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "Transport filter: \"stdio\", \"hosted\", or \"all\"/omitted.",
- required: false,
- },
- FieldSchema {
- name: "page",
- ty: TypeSchema::Option(Box::new(TypeSchema::U64)),
- comment: "1-based page number (default: 1).",
- required: false,
- },
- FieldSchema {
- name: "page_size",
- ty: TypeSchema::Option(Box::new(TypeSchema::U64)),
- comment: "Results per page (default: 20).",
- required: false,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "servers",
- ty: TypeSchema::Array(Box::new(TypeSchema::Ref("SmitheryServerSummary"))),
- comment: "Matching server summaries from the registry.",
- required: true,
- },
- FieldSchema {
- name: "page",
- ty: TypeSchema::U64,
- comment: "Current page number.",
- required: true,
- },
- FieldSchema {
- name: "total_pages",
- ty: TypeSchema::U64,
- comment: "Total number of pages available.",
- required: true,
- },
- ],
- },
-
- "registry_get" => ControllerSchema {
- namespace: "mcp_clients",
- function: "registry_get",
- description: "Fetch full details for one MCP server from the Smithery registry.",
- inputs: vec![FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name, e.g. `@modelcontextprotocol/server-filesystem`.",
- required: true,
- }],
- outputs: vec![FieldSchema {
- name: "server",
- ty: TypeSchema::Ref("SmitheryServerDetail"),
- comment: "Full server detail including connection specs.",
- required: true,
- }],
- },
-
- "installed_list" => ControllerSchema {
- namespace: "mcp_clients",
- function: "installed_list",
- description: "List all locally installed MCP servers.",
- inputs: vec![],
- outputs: vec![FieldSchema {
- name: "installed",
- ty: TypeSchema::Array(Box::new(TypeSchema::Ref("InstalledServer"))),
- comment: "Installed server records (env values omitted).",
- required: true,
- }],
- },
-
- "install" => ControllerSchema {
- namespace: "mcp_clients",
- function: "install",
- description: "Install an MCP server from the Smithery registry.",
- inputs: vec![
- FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name.",
- required: true,
- },
- FieldSchema {
- name: "env",
- ty: TypeSchema::Map(Box::new(TypeSchema::String)),
- comment: "Environment variable values required by the server. Values are stored encrypted and never returned.",
- required: true,
- },
- FieldSchema {
- name: "config",
- ty: TypeSchema::Option(Box::new(TypeSchema::Json)),
- comment: "Optional JSON configuration blob.",
- required: false,
- },
- ],
- outputs: vec![FieldSchema {
- name: "server",
- ty: TypeSchema::Ref("InstalledServer"),
- comment: "The newly installed server record.",
- required: true,
- }],
- },
-
- "update_env" => ControllerSchema {
- namespace: "mcp_clients",
- function: "update_env",
- description: "Replace the stored env values for an installed server and reconnect so the new credentials take effect (reconfigure / rotate keys without reinstalling).",
- inputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the installed server to reconfigure.",
- required: true,
- },
- FieldSchema {
- name: "env",
- ty: TypeSchema::Map(Box::new(TypeSchema::String)),
- comment: "Replacement environment variable values. Stored encrypted and never returned.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "The reconfigured server id.",
- required: true,
- },
- FieldSchema {
- name: "status",
- ty: TypeSchema::Enum {
- variants: vec!["connected", "disconnected"],
- },
- comment: "`connected` if the reconnect succeeded, `disconnected` if env was saved but reconnect failed.",
- required: true,
- },
- FieldSchema {
- name: "env_keys",
- ty: TypeSchema::Array(Box::new(TypeSchema::String)),
- comment: "Env key names after the update (values omitted).",
- required: true,
- },
- FieldSchema {
- name: "tools",
- ty: TypeSchema::Array(Box::new(TypeSchema::Ref("McpTool"))),
- comment: "Tools exposed after reconnect (present only when status=connected).",
- required: false,
- },
- ],
- },
-
- "uninstall" => ControllerSchema {
- namespace: "mcp_clients",
- function: "uninstall",
- description: "Uninstall a locally installed MCP server.",
- inputs: vec![FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the server to remove.",
- required: true,
- }],
- outputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "The server id that was targeted.",
- required: true,
- },
- FieldSchema {
- name: "removed",
- ty: TypeSchema::Bool,
- comment: "True when the server was actually removed.",
- required: true,
- },
- ],
- },
-
- "detect_auth" => ControllerSchema {
- namespace: "mcp_clients",
- function: "detect_auth",
- description: "Probe a server to classify how it authenticates (none / token / oauth).",
- inputs: vec![FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the installed server to probe.",
- required: true,
- }],
- outputs: vec![
- FieldSchema {
- name: "kind",
- ty: TypeSchema::Enum {
- variants: vec!["none", "token", "oauth"],
- },
- comment: "`none` (open), `token` (static bearer/API key), or `oauth` (browser sign-in).",
- required: true,
- },
- FieldSchema {
- name: "authorization_endpoint",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "OAuth authorization endpoint, when kind is `oauth`.",
- required: false,
- },
- FieldSchema {
- name: "grant_types",
- ty: TypeSchema::Array(Box::new(TypeSchema::String)),
- comment: "Grant types the authorization server supports.",
- required: true,
- },
- ],
- },
-
- "oauth_begin" => ControllerSchema {
- namespace: "mcp_clients",
- function: "oauth_begin",
- description: "Begin browser OAuth: discover + dynamically register a client + PKCE, returning the authorize URL to open.",
- inputs: vec![FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the installed server to authenticate.",
- required: true,
- }],
- outputs: vec![FieldSchema {
- name: "authorize_url",
- ty: TypeSchema::String,
- comment: "Live OAuth authorize URL to open in the browser; the /oauth/mcp/callback route completes sign-in.",
- required: true,
- }],
- },
-
- "connect" => ControllerSchema {
- namespace: "mcp_clients",
- function: "connect",
- description: "Spawn the MCP server subprocess and run the initialize handshake.",
- inputs: vec![FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the installed server to connect.",
- required: true,
- }],
- outputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "Connected server id.",
- required: true,
- },
- FieldSchema {
- name: "status",
- ty: TypeSchema::Enum {
- variants: vec!["connected"],
- },
- comment: "Always `connected` on success.",
- required: true,
- },
- FieldSchema {
- name: "tools",
- ty: TypeSchema::Array(Box::new(TypeSchema::Ref("McpTool"))),
- comment: "Tools exposed by the connected server.",
- required: true,
- },
- ],
- },
-
- "disconnect" => ControllerSchema {
- namespace: "mcp_clients",
- function: "disconnect",
- description: "Disconnect a running MCP server and stop its process.",
- inputs: vec![FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the server to disconnect.",
- required: true,
- }],
- outputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "Disconnected server id.",
- required: true,
- },
- FieldSchema {
- name: "status",
- ty: TypeSchema::Enum {
- variants: vec!["disconnected"],
- },
- comment: "Always `disconnected` on success.",
- required: true,
- },
- ],
- },
-
- "status" => ControllerSchema {
- namespace: "mcp_clients",
- function: "status",
- description: "Return connection status for all installed MCP servers.",
- inputs: vec![],
- outputs: vec![FieldSchema {
- name: "servers",
- ty: TypeSchema::Array(Box::new(TypeSchema::Ref("ConnStatus"))),
- comment: "Per-server connection status summaries.",
- required: true,
- }],
- },
-
- "tool_call" => ControllerSchema {
- namespace: "mcp_clients",
- function: "tool_call",
- description: "Invoke a tool on a connected MCP server.",
- inputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the connected server.",
- required: true,
- },
- FieldSchema {
- name: "tool_name",
- ty: TypeSchema::String,
- comment: "Name of the tool to call.",
- required: true,
- },
- FieldSchema {
- name: "arguments",
- ty: TypeSchema::Json,
- comment: "Tool arguments as a JSON value.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "result",
- ty: TypeSchema::Json,
- comment: "Tool result value.",
- required: true,
- },
- FieldSchema {
- name: "is_error",
- ty: TypeSchema::Bool,
- comment: "True when the tool returned an error.",
- required: true,
- },
- ],
- },
-
- "config_assist" => ControllerSchema {
- namespace: "mcp_clients",
- function: "config_assist",
- description: "AI assistant that helps configure an MCP server's required env vars.",
- inputs: vec![
- FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name of the server being configured.",
- required: true,
- },
- FieldSchema {
- name: "user_message",
- ty: TypeSchema::String,
- comment: "User's question or reply.",
- required: true,
- },
- FieldSchema {
- name: "history",
- ty: TypeSchema::Option(Box::new(TypeSchema::Array(Box::new(TypeSchema::Ref(
- "ChatTurn",
- ))))),
- comment: "Prior conversation turns `[{role, content}]`.",
- required: false,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "reply",
- ty: TypeSchema::String,
- comment: "Assistant reply (markdown).",
- required: true,
- },
- FieldSchema {
- name: "suggested_env",
- ty: TypeSchema::Option(Box::new(TypeSchema::Map(Box::new(TypeSchema::String)))),
- comment: "Env vars extracted from the user's message, if any.",
- required: false,
- },
- ],
- },
-
- "registry_settings_get" => ControllerSchema {
- namespace: "mcp_clients",
- function: "registry_settings_get",
- description: "Report which registry credentials are configured (Smithery key, official-registry base/token). Never returns secret values — only `*_set` booleans plus the non-secret base URL override.",
- inputs: vec![],
- outputs: vec![
- FieldSchema {
- name: "smithery_api_key_set",
- ty: TypeSchema::Bool,
- comment: "True when a Smithery API key is set (config or env).",
- required: true,
- },
- FieldSchema {
- name: "mcp_official_token_set",
- ty: TypeSchema::Bool,
- comment: "True when an official-registry bearer token is set (config or env).",
- required: true,
- },
- FieldSchema {
- name: "mcp_official_base",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "User-configured official-registry base URL override (non-secret).",
- required: false,
- },
- ],
- },
-
- "registry_settings_set" => ControllerSchema {
- namespace: "mcp_clients",
- function: "registry_settings_set",
- description: "Persist registry credentials. Per field: omit to leave unchanged, empty string to clear, value to set. Secrets are write-only; the response is the same non-secret snapshot as registry_settings_get.",
- inputs: vec![
- FieldSchema {
- name: "smithery_api_key",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "New Smithery API key (empty string clears).",
- required: false,
- },
- FieldSchema {
- name: "mcp_official_base",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "New official-registry base URL override (empty string clears).",
- required: false,
- },
- FieldSchema {
- name: "mcp_official_token",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "New official-registry bearer token (empty string clears).",
- required: false,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "smithery_api_key_set",
- ty: TypeSchema::Bool,
- comment: "True when a Smithery API key is set after the update.",
- required: true,
- },
- FieldSchema {
- name: "mcp_official_token_set",
- ty: TypeSchema::Bool,
- comment: "True when an official-registry token is set after the update.",
- required: true,
- },
- FieldSchema {
- name: "mcp_official_base",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "Official-registry base URL override after the update.",
- required: false,
- },
- ],
- },
-
- "set_enabled" => ControllerSchema {
- namespace: "mcp_clients",
- function: "set_enabled",
- description: "Enable or disable an installed MCP server. Disabling auto-disconnects any live session and hides the server's tools from the agent; the install row and env values are kept so re-enabling does not require re-entry.",
- inputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "UUID of the installed server.",
- required: true,
- },
- FieldSchema {
- name: "enabled",
- ty: TypeSchema::Bool,
- comment: "Target state; `false` also disconnects.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "Echoed server id.",
- required: true,
- },
- FieldSchema {
- name: "enabled",
- ty: TypeSchema::Bool,
- comment: "Effective enabled state after the call.",
- required: true,
- },
- ],
- },
-
- // Handled by setup_schemas() — surface a clearer error rather than
- // falling through to the generic unknown sink.
- "setup_search"
- | "setup_get"
- | "setup_request_secret"
- | "setup_submit_secret"
- | "setup_test_connection"
- | "setup_install_and_connect" => setup_schemas(function.trim_start_matches("setup_")),
-
- _other => ControllerSchema {
- namespace: "mcp_clients",
- function: "unknown",
- description: "Unknown mcp_clients controller function.",
- inputs: vec![FieldSchema {
- name: "function",
- ty: TypeSchema::String,
- comment: "Unknown function requested for schema lookup.",
- required: true,
- }],
- outputs: vec![FieldSchema {
- name: "error",
- ty: TypeSchema::String,
- comment: "Lookup error details.",
- required: true,
- }],
- },
- }
-}
diff --git a/crates/openhuman-core/src/mcp/registry/schemas_part_02.rs b/crates/openhuman-core/src/mcp/registry/schemas_part_02.rs
deleted file mode 100644
index f04d5d5a62..0000000000
--- a/crates/openhuman-core/src/mcp/registry/schemas_part_02.rs
+++ /dev/null
@@ -1,608 +0,0 @@
-// ── Handler implementations ──────────────────────────────────────────────────
-
-fn handle_registry_search(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let query = read_optional_string(&params, "query")?;
- let transport = read_optional_string(&params, "transport")?;
- let page = read_optional_u32(&params, "page")?;
- let page_size = read_optional_u32(&params, "page_size")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_registry_search(
- &config, query, transport, page, page_size,
- )
- .await?,
- )
- })
-}
-
-fn handle_registry_get(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let qualified_name = read_required::<String>(&params, "qualified_name")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_registry_get(&config, qualified_name)
- .await?,
- )
- })
-}
-
-fn handle_installed_list(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let _ = params;
- let config = config_rpc::load_config_with_timeout().await?;
- to_json(crate::mcp::registry::ops::mcp_clients_installed_list(&config).await?)
- })
-}
-
-fn handle_install(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let qualified_name = read_required::<String>(&params, "qualified_name")?;
- let env = read_required::<std::collections::HashMap<String, String>>(&params, "env")?;
- let config_value = read_optional_json(&params, "config")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_install(
- &config,
- qualified_name,
- env,
- config_value,
- )
- .await?,
- )
- })
-}
-
-fn handle_update_env(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- let env = read_required::<std::collections::HashMap<String, String>>(&params, "env")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_update_env(&config, server_id, env)
- .await?,
- )
- })
-}
-
-fn handle_uninstall(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_uninstall(&config, server_id).await?,
- )
- })
-}
-
-fn handle_detect_auth(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_detect_auth(&config, server_id)
- .await?,
- )
- })
-}
-
-fn handle_oauth_begin(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_oauth_begin(&config, server_id)
- .await?,
- )
- })
-}
-
-fn handle_connect(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_connect(&config, server_id).await?,
- )
- })
-}
-
-fn handle_disconnect(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_disconnect(&config, server_id)
- .await?,
- )
- })
-}
-
-fn handle_set_enabled(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let server_id = read_required::<String>(&params, "server_id")?;
- let enabled = read_required::<bool>(&params, "enabled")?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_set_enabled(
- &config, server_id, enabled,
- )
- .await?,
- )
- })
-}
-
-fn handle_status(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let _ = params;
- let config = config_rpc::load_config_with_timeout().await?;
- to_json(crate::mcp::registry::ops::mcp_clients_status(&config).await?)
- })
-}
-
-fn handle_tool_call(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let server_id = read_required::<String>(&params, "server_id")?;
- let tool_name = read_required::<String>(&params, "tool_name")?;
- let arguments = params
- .get("arguments")
- .cloned()
- .unwrap_or(Value::Object(Map::new()));
- let config = config_rpc::load_config_with_timeout().await?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_tool_call(
- &config, server_id, tool_name, arguments,
- )
- .await?,
- )
- })
-}
-
-fn handle_config_assist(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let qualified_name = read_required::<String>(&params, "qualified_name")?;
- let user_message = read_required::<String>(&params, "user_message")?;
- let history = read_optional::<Vec<crate::mcp::registry::types::ChatTurn>>(
- &params, "history",
- )?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_config_assist(
- &config,
- qualified_name,
- user_message,
- history,
- )
- .await?,
- )
- })
-}
-
-fn handle_registry_settings_get(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let _ = params;
- let config = config_rpc::load_config_with_timeout().await?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_registry_settings_get(&config)
- .await?,
- )
- })
-}
-
-fn handle_registry_settings_set(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let smithery_api_key = read_optional::<String>(&params, "smithery_api_key")?;
- let mcp_official_base = read_optional::<String>(&params, "mcp_official_base")?;
- let mcp_official_token = read_optional::<String>(&params, "mcp_official_token")?;
- let mut config = config_rpc::load_config_with_timeout().await?;
- to_json(
- crate::mcp::registry::ops::mcp_clients_registry_settings_set(
- &mut config,
- smithery_api_key,
- mcp_official_base,
- mcp_official_token,
- )
- .await?,
- )
- })
-}
-
-// ── mcp_setup_* schemas + handlers ────────────────────────────────────────────
-
-/// All setup-agent schemas under the `mcp_setup` RPC namespace. Kept in a
-/// separate function so the setup surface can evolve independently of the
-/// existing `mcp_clients_*` controllers.
-pub fn setup_schemas(function: &str) -> ControllerSchema {
- match function {
- "search" => ControllerSchema {
- namespace: "mcp_setup",
- function: "search",
- description: "Search all enabled MCP registries (Smithery + official).",
- inputs: vec![
- FieldSchema {
- name: "query",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "Free-text search query.",
- required: false,
- },
- FieldSchema {
- name: "page",
- ty: TypeSchema::Option(Box::new(TypeSchema::U64)),
- comment: "1-based page number (default: 1).",
- required: false,
- },
- FieldSchema {
- name: "page_size",
- ty: TypeSchema::Option(Box::new(TypeSchema::U64)),
- comment: "Results per page (default: 20).",
- required: false,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "servers",
- ty: TypeSchema::Array(Box::new(TypeSchema::Ref("SmitheryServerSummary"))),
- comment: "Merged summaries; each row tagged with its `source` (`smithery` | `mcp_official`).",
- required: true,
- },
- FieldSchema {
- name: "page",
- ty: TypeSchema::U64,
- comment: "Current page number.",
- required: true,
- },
- FieldSchema {
- name: "total_pages",
- ty: TypeSchema::U64,
- comment: "Upper-bound page count across registries.",
- required: true,
- },
- ],
- },
- "get" => ControllerSchema {
- namespace: "mcp_setup",
- function: "get",
- description: "Fetch full details for one server. Adds `required_env_keys` derived from the connection schema.",
- inputs: vec![FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name. May be prefixed with `<source>::` to pin a registry.",
- required: true,
- }],
- outputs: vec![FieldSchema {
- name: "server",
- ty: TypeSchema::Ref("SmitheryServerDetail"),
- comment: "Full detail with `required_env_keys` injected.",
- required: true,
- }],
- },
- "request_secret" => ControllerSchema {
- namespace: "mcp_setup",
- function: "request_secret",
- description: "Ask the user out-of-band for a secret value. Blocks until the UI submits via `submit_secret` (5-minute timeout). Returns an opaque ref; the raw value never enters the agent's context.",
- inputs: vec![
- FieldSchema {
- name: "key_name",
- ty: TypeSchema::String,
- comment: "Display name of the env var (e.g. `NOTION_API_KEY`).",
- required: true,
- },
- FieldSchema {
- name: "prompt",
- ty: TypeSchema::String,
- comment: "Plain-English instruction shown to the user in the native input box.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "ref",
- ty: TypeSchema::String,
- comment: "Opaque handle like `secret://<hex>`. Pass back via `test_connection` / `install_and_connect`.",
- required: true,
- },
- FieldSchema {
- name: "key_name",
- ty: TypeSchema::String,
- comment: "Echoed key name.",
- required: true,
- },
- ],
- },
- "submit_secret" => ControllerSchema {
- namespace: "mcp_setup",
- function: "submit_secret",
- description: "UI-side: fulfill a pending `request_secret` with the user-entered value. Not intended for agent use.",
- inputs: vec![
- FieldSchema {
- name: "ref_id",
- ty: TypeSchema::String,
- comment: "The `secret://<hex>` ref returned by `request_secret`.",
- required: true,
- },
- FieldSchema {
- name: "value",
- ty: TypeSchema::String,
- comment: "Raw secret value. NEVER log this.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "ref",
- ty: TypeSchema::String,
- comment: "Echoed ref.",
- required: true,
- },
- FieldSchema {
- name: "fulfilled",
- ty: TypeSchema::Bool,
- comment: "True on success.",
- required: true,
- },
- ],
- },
- "test_connection" => ControllerSchema {
- namespace: "mcp_setup",
- function: "test_connection",
- description: "Dry-run install: spawn a candidate server in a scratch process with the supplied secret refs, list its tools, tear down. Nothing persisted.",
- inputs: vec![
- FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name.",
- required: true,
- },
- FieldSchema {
- name: "env_refs",
- ty: TypeSchema::Map(Box::new(TypeSchema::String)),
- comment: "Map `{ENV_KEY: secret://<hex>}` produced by `request_secret`.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "ok",
- ty: TypeSchema::Bool,
- comment: "True if initialize + tools/list succeeded.",
- required: true,
- },
- FieldSchema {
- name: "tools",
- ty: TypeSchema::Option(Box::new(TypeSchema::Array(Box::new(TypeSchema::Ref(
- "McpRemoteTool",
- ))))),
- comment: "Tools advertised by the candidate. Present iff `ok`.",
- required: false,
- },
- FieldSchema {
- name: "error",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "Error string. Present iff `ok` is false.",
- required: false,
- },
- ],
- },
- "install_and_connect" => ControllerSchema {
- namespace: "mcp_setup",
- function: "install_and_connect",
- description: "Commit: persist the install + secrets (consuming the refs), then connect immediately and return the tool list.",
- inputs: vec![
- FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name.",
- required: true,
- },
- FieldSchema {
- name: "env_refs",
- ty: TypeSchema::Map(Box::new(TypeSchema::String)),
- comment: "Map `{ENV_KEY: secret://<hex>}`. Refs are consumed (removed from the in-memory map) on success.",
- required: true,
- },
- ],
- outputs: vec![
- FieldSchema {
- name: "server_id",
- ty: TypeSchema::String,
- comment: "Freshly-minted server UUID.",
- required: true,
- },
- FieldSchema {
- name: "qualified_name",
- ty: TypeSchema::String,
- comment: "Registry qualified name the install was made from — echoed back so a caller need not correlate on the request.",
- required: true,
- },
- FieldSchema {
- name: "status",
- ty: TypeSchema::String,
- comment: "`connected` or `installed_disconnected` (install succeeded, connect failed).",
- required: true,
- },
- FieldSchema {
- name: "tools",
- ty: TypeSchema::Option(Box::new(TypeSchema::Array(Box::new(TypeSchema::Ref(
- "McpTool",
- ))))),
- comment: "Tool list iff `status == connected`.",
- required: false,
- },
- FieldSchema {
- name: "error",
- ty: TypeSchema::Option(Box::new(TypeSchema::String)),
- comment: "Connect error iff `status != connected`.",
- required: false,
- },
- ],
- },
- _ => ControllerSchema {
- namespace: "mcp_setup",
- function: "unknown",
- description: "Unknown mcp_setup controller function.",
- inputs: vec![FieldSchema {
- name: "function",
- ty: TypeSchema::String,
- comment: "Unknown function requested for schema lookup.",
- required: true,
- }],
- outputs: vec![FieldSchema {
- name: "error",
- ty: TypeSchema::String,
- comment: "Lookup error details.",
- required: true,
- }],
- },
- }
-}
-
-fn handle_setup_search(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let query = read_optional_string(&params, "query")?;
- let page = read_optional_u32(&params, "page")?;
- let page_size = read_optional_u32(&params, "page_size")?;
- to_json(
- crate::mcp::registry::setup_ops::mcp_setup_search(
- &config, query, page, page_size,
- )
- .await?,
- )
- })
-}
-
-fn handle_setup_get(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let qualified_name = read_required::<String>(&params, "qualified_name")?;
- to_json(
- crate::mcp::registry::setup_ops::mcp_setup_get(&config, qualified_name)
- .await?,
- )
- })
-}
-
-fn handle_setup_request_secret(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let key_name = read_required::<String>(&params, "key_name")?;
- let prompt = read_required::<String>(&params, "prompt")?;
- let config = config_rpc::load_config_with_timeout().await?;
- to_json(
- crate::mcp::registry::setup_ops::mcp_setup_request_secret(
- &config, key_name, prompt,
- )
- .await?,
- )
- })
-}
-
-fn handle_setup_submit_secret(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let ref_id = read_required::<String>(&params, "ref_id")?;
- let value = read_required::<String>(&params, "value")?;
- let config = config_rpc::load_config_with_timeout().await?;
- to_json(
- crate::mcp::registry::setup_ops::mcp_setup_submit_secret(
- &config, ref_id, value,
- )
- .await?,
- )
- })
-}
-
-fn handle_setup_test_connection(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let qualified_name = read_required::<String>(&params, "qualified_name")?;
- let env_refs =
- read_required::<std::collections::HashMap<String, String>>(&params, "env_refs")?;
- to_json(
- crate::mcp::registry::setup_ops::mcp_setup_test_connection(
- &config,
- qualified_name,
- env_refs,
- )
- .await?,
- )
- })
-}
-
-fn handle_setup_install_and_connect(params: Map<String, Value>) -> ControllerFuture {
- Box::pin(async move {
- let config = config_rpc::load_config_with_timeout().await?;
- let qualified_name = read_required::<String>(&params, "qualified_name")?;
- let env_refs =
- read_required::<std::collections::HashMap<String, String>>(&params, "env_refs")?;
- to_json(
- crate::mcp::registry::setup_ops::mcp_setup_install_and_connect(
- &config,
- qualified_name,
- env_refs,
- )
- .await?,
- )
- })
-}
-
-// ── Param helpers ─────────────────────────────────────────────────────────────
-
-fn read_required<T: DeserializeOwned>(params: &Map<String, Value>, key: &str) -> Result<T, String> {
- let value = params
- .get(key)
- .cloned()
- .ok_or_else(|| format!("missing required param '{key}'"))?;
- serde_json::from_value(value).map_err(|e| format!("invalid '{key}': {e}"))
-}
-
-fn read_optional<T: DeserializeOwned>(
- params: &Map<String, Value>,
- key: &str,
-) -> Result<Option<T>, String> {
- match params.get(key) {
- None | Some(Value::Null) => Ok(None),
- Some(v) => serde_json::from_value(v.clone())
- .map(Some)
- .map_err(|e| format!("invalid '{key}': {e}")),
- }
-}
-
-fn read_optional_string(params: &Map<String, Value>, key: &str) -> Result<Option<String>, String> {
- read_optional::<String>(params, key)
-}
-
-fn read_optional_u32(params: &Map<String, Value>, key: &str) -> Result<Option<u32>, String> {
- match params.get(key) {
- None | Some(Value::Null) => Ok(None),
- Some(Value::Number(n)) => n
- .as_u64()
- .and_then(|v| u32::try_from(v).ok())
- .map(Some)
- .ok_or_else(|| format!("invalid '{key}': expected u32")),
- Some(other) => Err(format!(
- "invalid '{key}': expected number, got {}",
- type_name(other)
- )),
- }
-}
-
-fn read_optional_json(params: &Map<String, Value>, key: &str) -> Result<Option<Value>, String> {
- match params.get(key) {
- None | Some(Value::Null) => Ok(None),
- Some(v) => Ok(Some(v.clone())),
- }
-}
-
-fn to_json<T: serde::Serialize>(outcome: RpcOutcome<T>) -> Result<Value, String> {
- serde_json::to_value(outcome.value).map_err(|e| e.to_string())
-}
-
-fn type_name(value: &Value) -> &'static str {
- match value {
- Value::Null => "null",
- Value::Bool(_) => "bool",
- Value::Number(_) => "number",
- Value::String(_) => "string",
- Value::Array(_) => "array",
- Value::Object(_) => "object",
- }
-}
diff --git a/crates/openhuman-core/src/memory/guard/families/ingest_and_tree.rs b/crates/openhuman-core/src/memory/guard/families/ingest_and_tree.rs
new file mode 100644
index 0000000000..3cd359e4c5
--- /dev/null
+++ b/crates/openhuman-core/src/memory/guard/families/ingest_and_tree.rs
@@ -0,0 +1,523 @@
+//! Guarded `Ingest`, `Documents`, and `Tree` — the families that write new
+//! content into memory or read back its hierarchical tree structure.
+//!
+//! Split out of `families.rs`; see [`super::types`] for the shared decorator
+//! scaffolding these `impl` blocks build on.
+
+use std::borrow::Cow;
+
+use crate::memory::api::capabilities::Capability;
+use crate::memory::api::error::MemoryError;
+use crate::memory::api::provider::content::{
+ RootSummary, SummaryContext, SummaryInput, SummaryOutput,
+};
+use crate::memory::api::provider::types::{IngestItem, IngestOutcome, SourceScope};
+use crate::memory::api::provider::{MemoryDocuments, MemoryIngest, MemoryTree};
+use crate::memory::api::tree::{IngestRequest, QueryResult, SummaryForest, TreeLeaf, TreeNode, TreeStatus};
+use crate::memory::api::types::{NamespaceDocumentInput, StoredMemoryDocument};
+use async_trait::async_trait;
+
+use super::super::audit::{trace_allowed, NO_NAMESPACE};
+use super::types::{GuardedDocuments, GuardedIngest, GuardedTree};
+
+// ── Ingest ───────────────────────────────────────────────────────────────────
+
+impl GuardedIngest {
+ /// Steps 3 + 4 over one ingest item: stamp provenance, redact on egress.
+ fn admit(&self, mut item: IngestItem) -> IngestItem {
+ item.taint = self.policy.stamp_taint(item.taint);
+ item.content = self.policy.redact_outbound(&item.content).into_owned();
+ item
+ }
+}
+
+#[async_trait]
+impl MemoryIngest for GuardedIngest {
+ async fn ingest_document(&self, item: IngestItem) -> Result<IngestOutcome, MemoryError> {
+ let namespace = item.namespace.clone().unwrap_or_else(|| "-".to_string());
+ self.policy.admit_write(
+ Capability::Ingest,
+ "ingest.ingest_document",
+ &namespace,
+ true,
+ )?;
+ let item = self.admit(item);
+ trace_allowed(
+ &self.policy,
+ "ingest.ingest_document",
+ &namespace,
+ item.content.chars().count(),
+ );
+ self.family()?.ingest_document(item).await
+ }
+
+ async fn ingest_chat(&self, messages: Vec<IngestItem>) -> Result<IngestOutcome, MemoryError> {
+ self.policy
+ .admit_write(Capability::Ingest, "ingest.ingest_chat", NO_NAMESPACE, true)?;
+ let messages: Vec<IngestItem> = messages.into_iter().map(|m| self.admit(m)).collect();
+ trace_allowed(
+ &self.policy,
+ "ingest.ingest_chat",
+ NO_NAMESPACE,
+ messages.iter().map(|m| m.content.chars().count()).sum(),
+ );
+ self.family()?.ingest_chat(messages).await
+ }
+
+ async fn ingest_email(&self, messages: Vec<IngestItem>) -> Result<IngestOutcome, MemoryError> {
+ // Admitted exactly like chat: a thread is one conversation with no
+ // namespace of its own, and every message is taint-stamped and
+ // redacted before it reaches the driver.
+ self.policy.admit_write(
+ Capability::Ingest,
+ "ingest.ingest_email",
+ NO_NAMESPACE,
+ true,
+ )?;
+ let messages: Vec<IngestItem> = messages.into_iter().map(|m| self.admit(m)).collect();
+ trace_allowed(
+ &self.policy,
+ "ingest.ingest_email",
+ NO_NAMESPACE,
+ messages.iter().map(|m| m.content.chars().count()).sum(),
+ );
+ self.family()?.ingest_email(messages).await
+ }
+}
+
+// ── Documents ────────────────────────────────────────────────────────────────
+
+#[async_trait]
+impl MemoryDocuments for GuardedDocuments {
+ async fn put_document(&self, mut input: NamespaceDocumentInput) -> Result<String, MemoryError> {
+ self.policy.admit_write(
+ Capability::Documents,
+ "documents.put_document",
+ &input.namespace,
+ true,
+ )?;
+ input.taint = self.policy.stamp_taint(input.taint);
+ input.title = self.policy.redact_outbound(&input.title).into_owned();
+ input.content = self.policy.redact_outbound(&input.content).into_owned();
+ input.metadata = self.policy.redact_outbound_json(input.metadata);
+ trace_allowed(
+ &self.policy,
+ "documents.put_document",
+ &input.namespace,
+ input.content.chars().count(),
+ );
+ self.family()?.put_document(input).await
+ }
+
+ async fn get_document(
+ &self,
+ namespace: &str,
+ key: &str,
+ ) -> Result<Option<StoredMemoryDocument>, MemoryError> {
+ self.policy.admit_read(
+ Capability::Documents,
+ "documents.get_document",
+ namespace,
+ false,
+ )?;
+ self.family()?.get_document(namespace, key).await
+ }
+
+ async fn list_documents(
+ &self,
+ namespace: Option<&str>,
+ ) -> Result<serde_json::Value, MemoryError> {
+ self.policy.admit_read(
+ Capability::Documents,
+ "documents.list_documents",
+ namespace.unwrap_or(NO_NAMESPACE),
+ false,
+ )?;
+ self.family()?.list_documents(namespace).await
+ }
+
+ async fn list_namespaces(&self) -> Result<Vec<String>, MemoryError> {
+ self.policy.admit_read(
+ Capability::Documents,
+ "documents.list_namespaces",
+ NO_NAMESPACE,
+ false,
+ )?;
+ self.family()?.list_namespaces().await
+ }
+
+ async fn delete_document(
+ &self,
+ namespace: &str,
+ document_id: &str,
+ ) -> Result<serde_json::Value, MemoryError> {
+ self.policy.admit_write(
+ Capability::Documents,
+ "documents.delete_document",
+ namespace,
+ false,
+ )?;
+ self.family()?.delete_document(namespace, document_id).await
+ }
+
+ async fn clear_namespace(&self, namespace: &str) -> Result<(), MemoryError> {
+ self.policy.admit_write(
+ Capability::Documents,
+ "documents.clear_namespace",
+ namespace,
+ false,
+ )?;
+ self.family()?.clear_namespace(namespace).await
+ }
+
+ async fn query_documents(
+ &self,
+ namespace: &str,
+ query: &str,
+ limit: usize,
+ ) -> Result<NamespaceRetrievalContext, MemoryError> {
+ // The query text itself crosses the boundary on an external driver.
+ self.policy.admit_read(
+ Capability::Documents,
+ "documents.query_documents",
+ namespace,
+ true,
+ )?;
+ let query = self.policy.redact_outbound(query).into_owned();
+ self.family()?
+ .query_documents(namespace, &query, limit)
+ .await
+ }
+
+ async fn recall_documents(
+ &self,
+ namespace: &str,
+ limit: usize,
+ ) -> Result<NamespaceRetrievalContext, MemoryError> {
+ self.policy.admit_read(
+ Capability::Documents,
+ "documents.recall_documents",
+ namespace,
+ false,
+ )?;
+ self.family()?.recall_documents(namespace, limit).await
+ }
+}
+
+// ── Tree ─────────────────────────────────────────────────────────────────────
+
+#[async_trait]
+impl MemoryTree for GuardedTree {
+ async fn append(&self, mut request: IngestRequest) -> Result<(), MemoryError> {
+ self.policy
+ .admit_write(Capability::Tree, "tree.append", &request.namespace, true)?;
+ request.content = self.policy.redact_outbound(&request.content).into_owned();
+ trace_allowed(
+ &self.policy,
+ "tree.append",
+ &request.namespace,
+ request.content.chars().count(),
+ );
+ self.family()?.append(request).await
+ }
+
+ /// **Step 2 lives here.** This is the only contract method in the tree
+ /// today that both takes a [`SourceScope`] and applies it as a real query
+ /// predicate: the embedded driver pushes `scope.allow` into
+ /// `ListChunksQuery.source_scope`, which reaches SQL *before* `LIMIT`.
+ ///
+ /// The ambient allowlist
+ /// ([`source_scope::current_source_scope`](crate::memory::source_scope::current_source_scope))
+ /// is therefore read at this boundary and passed down, rather than being
+ /// applied to the returned rows. An explicit `scope` argument may only
+ /// *narrow* it: the two are intersected by
+ /// [`GuardPolicy::narrow_scope`](crate::memory::guard::GuardPolicy::narrow_scope),
+ /// so a caller that computed a tighter scope than the task-local still wins,
+ /// while one that names a collection outside the ambient allowlist cannot
+ /// widen the turn back out.
+ ///
+ /// There is **no double application**: the embedded `query_source` does not
+ /// itself read the task-local (only the deeper `tree::retrieval` and
+ /// `list_chunks` paths do, and the guard does not sit in front of those),
+ /// so this fills a predicate that would otherwise be `None`.
+ async fn query_source(
+ &self,
+ namespace: &str,
+ source_id: &str,
+ limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<Vec<Chunk>, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.query_source", namespace, false)?;
+ let ambient = self.policy.ambient_scope();
+ let effective = self.policy.narrow_scope(scope);
+ log::debug!(
+ "[memory:guard] tree.query_source namespace={namespace} limit={limit} \
+ scoped={} scope_from={}",
+ effective.is_some(),
+ match (scope.is_some(), ambient.is_some()) {
+ (true, true) => "argument∩ambient",
+ (true, false) => "argument",
+ (false, true) => "ambient",
+ (false, false) => "none",
+ }
+ );
+ self.family()?
+ .query_source(namespace, source_id, limit, effective.as_ref())
+ .await
+ }
+
+ async fn drill_down(&self, namespace: &str, node_id: &str) -> Result<QueryResult, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.drill_down", namespace, false)?;
+ self.family()?.drill_down(namespace, node_id).await
+ }
+
+ async fn seal(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.policy
+ .admit_write(Capability::Tree, "tree.seal", namespace, false)?;
+ self.family()?.seal(namespace).await
+ }
+
+ async fn cascade(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.policy
+ .admit_write(Capability::Tree, "tree.cascade", namespace, false)?;
+ self.family()?.cascade(namespace).await
+ }
+
+ /// Enumerates the sealed forest, so it narrows by the ambient scope for the
+ /// same reason [`Self::query_source`] does: a summary is derived from the
+ /// chunks beneath it, and handing back a node built from sources the caller
+ /// may not read discloses their contents in condensed form.
+ async fn summary_forest(
+ &self,
+ limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<SummaryForest, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.summary_forest", NO_NAMESPACE, false)?;
+ let effective = self.policy.narrow_scope(scope);
+ self.family()?
+ .summary_forest(limit, effective.as_ref())
+ .await
+ }
+
+ /// Sealing one source's tree is a write, and it names the scope it acts on
+ /// — so unlike the reads above it is admitted against that scope rather
+ /// than `NO_NAMESPACE`. `carries_content: false`: the caller supplies a
+ /// scope label, never prose, and the seals it fires write content the
+ /// driver already holds.
+ async fn flush_source_tree(&self, source_scope: &str) -> Result<u64, MemoryError> {
+ self.policy.admit_write(
+ Capability::Tree,
+ "tree.flush_source_tree",
+ source_scope,
+ false,
+ )?;
+ self.family()?.flush_source_tree(source_scope).await
+ }
+
+ /// Leaves are chunks, so this is the same disclosure as
+ /// [`Self::query_source`] with a different ordering, and takes the same
+ /// intersection.
+ async fn recent_leaves(
+ &self,
+ limit: usize,
+ scope: Option<&SourceScope>,
+ ) -> Result<Vec<TreeLeaf>, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.recent_leaves", NO_NAMESPACE, false)?;
+ let effective = self.policy.narrow_scope(scope);
+ self.family()?
+ .recent_leaves(limit, effective.as_ref())
+ .await
+ }
+
+ /// A **read** tier check even though the fold costs a provider call: it
+ /// writes nothing. `seal` and `cascade` take the write tier because they
+ /// persist the nodes they produce; this hands the summary back and leaves
+ /// the tree exactly as it found it, so refusing it under `readonly` would
+ /// stop a recap that stores nothing.
+ ///
+ /// It is nevertheless the only member of this family besides
+ /// [`Self::append`] that carries prose *outbound* — every input's body
+ /// crosses to the driver's own chat provider — so it declares
+ /// `carries_content: true` and applies `append`'s scrub to each of them.
+ /// Admitted against [`SummaryContext::tree_id`] rather than
+ /// `NO_NAMESPACE` for the reason [`Self::flush_source_tree`] gives: it
+ /// names the tree it acts on.
+ async fn summarise(
+ &self,
+ inputs: &[SummaryInput],
+ context: &SummaryContext,
+ ) -> Result<SummaryOutput, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.summarise", &context.tree_id, true)?;
+ // `redact_outbound` borrows for every driver class but `External`, so
+ // the re-owned slice is built only when the scrubber actually rewrote
+ // something — a recap folds every turn of a segment, and cloning them
+ // to hand back the same bytes is the one cost this can avoid.
+ let mut scrubbed: Option<Vec<SummaryInput>> = None;
+ for (index, input) in inputs.iter().enumerate() {
+ if let Cow::Owned(content) = self.policy.redact_outbound(&input.content) {
+ scrubbed.get_or_insert_with(|| inputs.to_vec())[index].content = content;
+ }
+ }
+ let effective = scrubbed.as_deref().unwrap_or(inputs);
+ trace_allowed(
+ &self.policy,
+ "tree.summarise",
+ &context.tree_id,
+ effective
+ .iter()
+ .map(|input| input.content.chars().count())
+ .sum(),
+ );
+ self.family()?.summarise(effective, context).await
+ }
+
+ /// The markdown time tree's roots, one body per namespace.
+ ///
+ /// Takes no [`SourceScope`], so unlike [`Self::summary_forest`] there is
+ /// nothing here to intersect with the ambient allowlist — the contract
+ /// member has no scope parameter and the guard does not invent one. Both
+ /// caps are the caller's and cross unchanged: they bound the *response*,
+ /// and clipping them here would produce a body the driver did not choose
+ /// the truncation point of.
+ async fn root_summaries_with_caps(
+ &self,
+ per_namespace_cap: usize,
+ total_cap: usize,
+ ) -> Result<Vec<RootSummary>, MemoryError> {
+ self.policy.admit_read(
+ Capability::Tree,
+ "tree.root_summaries_with_caps",
+ NO_NAMESPACE,
+ false,
+ )?;
+ self.family()?
+ .root_summaries_with_caps(per_namespace_cap, total_cap)
+ .await
+ }
+
+ // ── The runtime-tree and flavour doors ──────────────────────────────────
+ //
+ // **Forwarding these is not optional.** All seven are defaulted on
+ // [`MemoryTree`], so a decorator that omits one still compiles — and then
+ // answers `Err(Unsupported)` for a driver that serves the member perfectly
+ // well, because the guard *is* the handle every product caller holds and
+ // its own default is what runs. That exact bug shipped once, on
+ // `MemoryMaintenance::diagnose`. The rule this family follows: a new
+ // defaulted member on a wrapped trait is a new override here, in the same
+ // change.
+ //
+ // None of them takes a [`SourceScope`], so step 2 does not apply — the
+ // contract members carry no scope parameter and the guard does not invent
+ // one; see [`Self::root_summaries_with_caps`] for the same reasoning.
+
+ /// Buffering raw content is [`Self::append`]'s write at a finer grain, so
+ /// it takes `append`'s admission exactly: the write tier, against the
+ /// namespace it names, `carries_content: true`, and the same outbound
+ /// scrub applied to the body before it crosses.
+ async fn runtime_buffer_write(
+ &self,
+ namespace: &str,
+ content: &str,
+ timestamp: chrono::DateTime<chrono::Utc>,
+ metadata: Option<serde_json::Value>,
+ ) -> Result<String, MemoryError> {
+ self.policy.admit_write(
+ Capability::Tree,
+ "tree.runtime_buffer_write",
+ namespace,
+ true,
+ )?;
+ let content = self.policy.redact_outbound(content);
+ trace_allowed(
+ &self.policy,
+ "tree.runtime_buffer_write",
+ namespace,
+ content.chars().count(),
+ );
+ self.family()?
+ .runtime_buffer_write(namespace, &content, timestamp, metadata)
+ .await
+ }
+
+ /// A single node read, admitted like [`Self::drill_down`] — the same tree
+ /// at the same grain, minus the child list.
+ async fn runtime_read_node(
+ &self,
+ namespace: &str,
+ node_id: &str,
+ ) -> Result<Option<TreeNode>, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.runtime_read_node", namespace, false)?;
+ self.family()?.runtime_read_node(namespace, node_id).await
+ }
+
+ /// The other half of [`Self::drill_down`], admitted identically.
+ async fn runtime_read_children(
+ &self,
+ namespace: &str,
+ parent_id: &str,
+ ) -> Result<Vec<TreeNode>, MemoryError> {
+ self.policy.admit_read(
+ Capability::Tree,
+ "tree.runtime_read_children",
+ namespace,
+ false,
+ )?;
+ self.family()?
+ .runtime_read_children(namespace, parent_id)
+ .await
+ }
+
+ /// Counts and timestamps for one namespace: a read, and one that carries
+ /// no prose either way.
+ async fn runtime_tree_status(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.policy.admit_read(
+ Capability::Tree,
+ "tree.runtime_tree_status",
+ namespace,
+ false,
+ )?;
+ self.family()?.runtime_tree_status(namespace).await
+ }
+
+ /// The **write** tier, unlike [`Self::summarise`]: this drains the buffer
+ /// into hour leaves and persists them, which is what [`Self::seal`] does
+ /// and why `seal` takes the write tier too. `summarise` hands a fold back
+ /// and leaves the tree as it found it; this one does not.
+ ///
+ /// `carries_content: false`: the caller supplies a namespace and an
+ /// instant, never prose. The content the pass folds is already in the
+ /// driver's own buffer, put there by [`Self::runtime_buffer_write`], which
+ /// scrubbed it on the way in.
+ async fn runtime_summarize(
+ &self,
+ namespace: &str,
+ timestamp: chrono::DateTime<chrono::Utc>,
+ ) -> Result<Option<TreeNode>, MemoryError> {
+ self.policy
+ .admit_write(Capability::Tree, "tree.runtime_summarize", namespace, false)?;
+ self.family()?.runtime_summarize(namespace, timestamp).await
+ }
+
+ /// As [`Self::runtime_summarize`], on [`Self::cascade`]'s terms.
+ async fn runtime_rebuild(&self, namespace: &str) -> Result<TreeStatus, MemoryError> {
+ self.policy
+ .admit_write(Capability::Tree, "tree.runtime_rebuild", namespace, false)?;
+ self.family()?.runtime_rebuild(namespace).await
+ }
+
+ /// A compiled profile read. The scope is the caller's naming scheme rather
+ /// than a namespace, and it is what this call acts on, so it is what the
+ /// admission names — the reasoning [`Self::flush_source_tree`] gives for
+ /// admitting against its own label instead of `NO_NAMESPACE`.
+ async fn flavour_profile(&self, scope: &str) -> Result<Option<String>, MemoryError> {
+ self.policy
+ .admit_read(Capability::Tree, "tree.flavour_profile", scope, false)?;
+ self.family()?.flavour_profile(scope).await
+ }
+}
diff --git a/crates/openhuman-core/src/modules/registry.rs b/crates/openhuman-core/src/modules/registry.rs
index f4b434d732..cd6bda2b7f 100644
--- a/crates/openhuman-core/src/modules/registry.rs
+++ b/crates/openhuman-core/src/modules/registry.rs
@@ -23,9 +23,16 @@
//! Take the values verbatim from the release's `checksum.toml`. Do not compute
//! them from a local build — the point is to pin what the release publishes, and
//! a locally recomputed digest would agree with itself no matter what was served.
+//!
+//! # Module layout
+//!
+//! Records are grouped into one file per module family rather than by line
+//! count — see `registry/records_*.rs`. This file only wires them into
+//! [`ALL`] and answers [`find`].
#[cfg(test)]
#[path = "registry_tests.rs"]
mod tests;
-include!("registry_part_01.rs");
-include!("registry_part_02.rs");
+
+mod records_docs_wallet;
+mod records_マcp_connectors_placeholder; // removed below