Skip to content

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

feat(skills): add catalog registry and store

Steven Enamakel16c8405f2949
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index 932050630e..eef5a85036 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -248,6 +248,10 @@ tinysearch-bus = { path = "../../vendor/tinysearch/crates/tinysearch-bus", featu
tinycomputer-bus = { path = "../../vendor/tinycomputer/crates/tinycomputer-bus" }
# Portable skill metadata, parsing, discovery, and filesystem hardening.
tinyskills = { path = "../../vendor/tinyskills/crates/tinyskills" }
+# The fetched skill-registry catalog on the storage ports (a `CatalogStore`
+# over `DocumentStore`); ports only, the host picks the backend. Only the
+# `skills` feature compiles the registry that uses it.
+tinyskills-drivers = { path = "../../vendor/tinyskills/crates/tinyskills-drivers", optional = true }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
serde_path_to_error = "0.1"
@@ -757,7 +761,7 @@ flows = ["modules", "dep:tinyflows", "dep:tinyflows-catalog", "dep:tinyflows-cop
# Workflow metadata in `openhuman::skills::ops_types` remains compiled with
# this feature OFF; generic tool-result types come directly from tinytools.
# Neither is part of the gated behavior. See src/skills/stub.rs.
-skills = ["tinyskills/registry"]
+skills = ["tinyskills/registry", "dep:tinyskills-drivers"]
# MCP domains, all under the `mcp/` family: `mcp::server` (the `openhuman mcp`
# stdio/HTTP server exposing our tool surface), `mcp::registry` (dynamic
# Smithery installs — SQLite, lifecycle, `mcp_clients` RPC namespace),
diff --git a/crates/openhuman-core/src/skills/catalog/registry.rs b/crates/openhuman-core/src/skills/catalog/registry.rs
index 9071323e1d..9c4a1510a6 100644
--- a/crates/openhuman-core/src/skills/catalog/registry.rs
+++ b/crates/openhuman-core/src/skills/catalog/registry.rs
@@ -5,7 +5,7 @@
//! | `OPENHUMAN_SKILL_REGISTRY_CATALOG_URL` | Read the Hermes index from this URL instead of the public one |
//! | `OPENHUMAN_SKILL_REGISTRY_DOWNLOAD_BASE_URL` | Serve every `SKILL.md` from `<base>/<name>/SKILL.md` |
//! | `OPENHUMAN_SKILL_INSTALL_ALLOW_LOCAL_HTTP=1` | Allow plain `http` to loopback (fixtures, local mirrors) |
-//! | `OPENHUMAN_SKILL_REGISTRY_CACHE_DIR` | Catalog store directory; default `~/.openhuman/skill-registry` |
+//! | `OPENHUMAN_SKILL_REGISTRY_CACHE_DIR` | Cache directory (legacy catalog files to import; default `~/.openhuman/skill-registry`) |
//!
//! A failed catalog refresh is not attempted again for [`REFRESH_COOLDOWN`]
//! (or longer when the upstream sends `Retry-After`); reads in that window
@@ -20,10 +20,10 @@ use std::sync::{Arc, PoisonError, RwLock};
use std::time::Duration;
use tinyskills::{
- FetchPolicy, FileCatalogStore, HermesIndexSource, RegistryLimits, RegistryTimeouts,
- SkillRegistry,
+ FetchPolicy, HermesIndexSource, RegistryLimits, RegistryTimeouts, SkillRegistry,
};
+use super::store::HostCatalogStore;
use super::transport::ReqwestTransport;
const CATALOG_URL_ENV: &str = "OPENHUMAN_SKILL_REGISTRY_CATALOG_URL";
@@ -115,7 +115,7 @@ impl RegistryConfig {
match &self.cache_dir {
Some(dir) => {
remove_legacy_cache(dir);
- builder.store(FileCatalogStore::new(dir.clone())).build()
+ builder.store(HostCatalogStore::new(dir.clone())).build()
}
None => {
tracing::warn!("[skill_registry] no home directory; catalog cached in memory only");
diff --git a/crates/openhuman-core/src/skills/catalog/store.rs b/crates/openhuman-core/src/skills/catalog/store.rs
new file mode 100644
index 0000000000..60dfd92488
--- /dev/null
+++ b/crates/openhuman-core/src/skills/catalog/store.rs
@@ -0,0 +1,157 @@
+//! The skill-registry catalog cache on the host's storage ports.
+//!
+//! Fetched catalogs used to be one JSON file per registry under the cache
+//! directory (`~/.openhuman/skill-registry/hermes.json`, tinyskills'
+//! `FileCatalogStore`). They are now documents (`tinyskills_catalogs/<registry>`,
+//! tinyskills-drivers' `DocumentCatalogStore`) in the process's storage backend
+//! under the acting scope, so a SQLite desktop, a MongoDB deployment and a
+//! tenant each keep their own cache without a second layout.
+//!
+//! The cache directory is still the registry's identity: it names the legacy
+//! files to import and, when no backend is installed (a unit test, an embedder
+//! that skipped the host boot), the workspace whose default backend holds the
+//! documents ([`crate::storage::local`]).
+//!
+//! # Legacy files
+//!
+//! A catalog with no document is looked up as `<cache dir>/<registry>.json`
+//! the first time it is read. The file is parsed, written with
+//! `Precondition::Absent` (so a catalog a refresh saved since is never
+//! overwritten) and left in place; it is never modified or deleted. Once the
+//! document exists it is the only copy read, so a refreshed catalog is not
+//! replaced by the older file. A file that is a symlink, oversized, unparseable
+//! or in another format is ignored: the catalog is a cache and is refetched.
+
+use std::path::{Path, PathBuf};
+use std::sync::Arc;
+
+use tinyskills::{is_safe_segment, BoxFuture, CatalogStore, StoreError, StoredCatalog};
+use tinyskills_drivers::{DocumentCatalogStore, CATALOG_COLLECTION};
+use tinystoragedrivers::{DocumentStore, ErrorKind, Precondition};
+
+const DOMAIN: &str = "skill_registry";
+const LOG_PREFIX: &str = "[skill_registry][store]";
+/// The largest legacy catalog file read; matches the cap the file store had.
+const MAX_LEGACY_BYTES: u64 = 512 * 1024 * 1024;
+
+/// The catalog cache of the process-wide registry.
+#[derive(Debug, Clone)]
+pub(crate) struct HostCatalogStore {
+ /// The cache directory: legacy files live here and, with no backend
+ /// installed, so does the workspace default's `storage/` directory.
+ dir: PathBuf,
+}
+
+impl HostCatalogStore {
+ pub(crate) fn new(dir: impl Into<PathBuf>) -> Self {
+ Self { dir: dir.into() }
+ }
+
+ /// The document store for this call's scope.
+ async fn documents(&self) -> Result<Arc<dyn DocumentStore>, StoreError> {
+ let dir = self.dir.clone();
+ tokio::task::spawn_blocking(move || {
+ crate::storage::local::open(DOMAIN, &dir).and_then(|opened| opened.scoped())
+ })
+ .await
+ .map_err(|error| StoreError::Io(format!("storage open task failed: {error}")))?
+ .map(|scoped| Arc::clone(scoped.documents()))
+ .map_err(|error| StoreError::Io(error.to_string()))
+ }
+
+ /// Imports `<dir>/<registry>.json` once a read finds no document.
+ async fn import_legacy(
+ &self,
+ registry: &str,
+ documents: &Arc<dyn DocumentStore>,
+ store: &DocumentCatalogStore,
+ ) -> Result<Option<StoredCatalog>, StoreError> {
+ let path = self.dir.join(format!("{registry}.json"));
+ let Some(catalog) = read_legacy(&path).await else {
+ return Ok(None);
+ };
+ let doc =
+ serde_json::to_value(&catalog).map_err(|error| StoreError::Io(error.to_string()))?;
+ match documents
+ .put(CATALOG_COLLECTION, registry, doc, Precondition::Absent)
+ .await
+ {
+ Ok(_) => {
+ tracing::info!(
+ registry,
+ entries = catalog.entries.len(),
+ "{LOG_PREFIX} imported the legacy catalog file"
+ );
+ Ok(Some(catalog))
+ }
+ // A refresh saved a catalog between the read and the import: that
+ // one is newer than the file, so it wins.
+ Err(error) if error.kind() == ErrorKind::AlreadyExists => store.load(registry).await,
+ Err(error) => Err(StoreError::Io(error.to_string())),
+ }
+ }
+}
+
+/// The legacy catalog file, or `None` when it is absent or unusable.
+async fn read_legacy(path: &Path) -> Option<StoredCatalog> {
+ let meta = match tokio::fs::symlink_metadata(path).await {
+ Ok(meta) => meta,
+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => return None,
+ Err(error) => {
+ tracing::debug!(error = %error, "{LOG_PREFIX} legacy catalog file unreadable");
+ return None;
+ }
+ };
+ if !meta.is_file() || meta.len() > MAX_LEGACY_BYTES {
+ tracing::warn!("{LOG_PREFIX} legacy catalog file is not a plain, bounded file; ignored");
+ return None;
+ }
+ let bytes = tokio::fs::read(path).await.ok()?;
+ match serde_json::from_slice::<StoredCatalog>(&bytes) {
+ Ok(catalog) if catalog.format == StoredCatalog::FORMAT => Some(catalog),
+ Ok(_) => {
+ tracing::debug!("{LOG_PREFIX} legacy catalog file is in another format; ignored");
+ None
+ }
+ Err(error) => {
+ tracing::warn!(error = %error, "{LOG_PREFIX} legacy catalog file is corrupt; ignored");
+ None
+ }
+ }
+}
+
+impl CatalogStore for HostCatalogStore {
+ fn load<'a>(
+ &'a self,
+ registry: &'a str,
+ ) -> BoxFuture<'a, Result<Option<StoredCatalog>, StoreError>> {
+ Box::pin(async move {
+ if !is_safe_segment(registry) {
+ return Err(StoreError::InvalidId(registry.to_owned()));
+ }
+ let documents = self.documents().await?;
+ let store = DocumentCatalogStore::new(Arc::clone(&documents));
+ if let Some(found) = store.load(registry).await? {
+ return Ok(Some(found));
+ }
+ self.import_legacy(registry, &documents, &store).await
+ })
+ }
+
+ fn save<'a>(
+ &'a self,
+ registry: &'a str,
+ catalog: &'a StoredCatalog,
+ ) -> BoxFuture<'a, Result<(), StoreError>> {
+ Box::pin(async move {
+ let documents = self.documents().await?;
+ DocumentCatalogStore::new(documents)
+ .save(registry, catalog)
+ .await
+ })
+ }
+}
+
+#[cfg(test)]
+#[path = "store_tests.rs"]
+mod tests;