Skip to content

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

feat(skills): keep an embedded agent's user-scope skills under its own directory (#7032)

oxoxDev65ddad62175a
diff --git a/crates/openhuman-core/src/skills/mod.rs b/crates/openhuman-core/src/skills/mod.rs
index b6a443c49e..35e5594d66 100644
--- a/crates/openhuman-core/src/skills/mod.rs
+++ b/crates/openhuman-core/src/skills/mod.rs
@@ -73,6 +73,8 @@ pub mod schemas;
pub mod search;
#[cfg(feature = "skills")]
pub mod tools;
+#[cfg(feature = "skills")]
+pub mod write_root;
#[cfg(all(test, feature = "skills"))]
#[path = "e2e_plumbing_tests.rs"]
diff --git a/crates/openhuman-core/src/skills/ops_create.rs b/crates/openhuman-core/src/skills/ops_create.rs
index d93834a525..c6c212ee53 100644
--- a/crates/openhuman-core/src/skills/ops_create.rs
+++ b/crates/openhuman-core/src/skills/ops_create.rs
@@ -172,9 +172,8 @@ pub(crate) fn create_workflow_inner(
let scope_root = match params.scope {
WorkflowScope::User => {
- let home =
- home_dir.ok_or_else(|| "could not resolve user home directory".to_string())?;
- home.join(".openhuman").join("workflows")
+ crate::skills::write_root::user_workflow_root(workspace_dir, home_dir)
+ .ok_or_else(|| "could not resolve user home directory".to_string())?
}
WorkflowScope::Project => {
if !is_workspace_trusted(workspace_dir) {
diff --git a/crates/openhuman-core/src/skills/ops_discover/api.rs b/crates/openhuman-core/src/skills/ops_discover/api.rs
index b3553f2a30..8a7cc4002c 100644
--- a/crates/openhuman-core/src/skills/ops_discover/api.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/api.rs
@@ -11,7 +11,7 @@ use crate::skills::ops_types::{Workflow, TRUST_MARKER};
use super::scan::{discover_filtered, ALL_ROOT_KINDS, WORKFLOW_ROOT_KINDS};
-type MetadataCacheKey = (PathBuf, Option<PathBuf>, bool);
+type MetadataCacheKey = (PathBuf, Option<PathBuf>, bool, Option<String>);
static METADATA_CACHE: LazyLock<RwLock<HashMap<MetadataCacheKey, Vec<Workflow>>>> =
LazyLock::new(|| RwLock::new(HashMap::new()));
static METADATA_GENERATION: AtomicU64 = AtomicU64::new(0);
@@ -83,7 +83,12 @@ pub fn discovery_home_dir() -> Option<PathBuf> {
pub fn load_workflow_metadata(workspace_dir: &Path) -> Vec<Workflow> {
let trusted = is_workspace_trusted(workspace_dir);
let home = discovery_home_dir();
- let key = (workspace_dir.to_path_buf(), home.clone(), trusted);
+ let key = (
+ workspace_dir.to_path_buf(),
+ home.clone(),
+ trusted,
+ crate::core::runtime::agent_scope::current_agent_id(),
+ );
if let Ok(cache) = METADATA_CACHE.read() {
if let Some(workflows) = cache.get(&key) {
return workflows.clone();
diff --git a/crates/openhuman-core/src/skills/ops_discover/scan.rs b/crates/openhuman-core/src/skills/ops_discover/scan.rs
index 647519880a..f9e8ddfeed 100644
--- a/crates/openhuman-core/src/skills/ops_discover/scan.rs
+++ b/crates/openhuman-core/src/skills/ops_discover/scan.rs
@@ -81,6 +81,21 @@ pub(super) fn discover_filtered(
}
}
+ if let Some(agent_home) = workspace_dir.and_then(crate::skills::write_root::agent_skill_home) {
+ let [skills, workflows] = crate::skills::write_root::agent_user_roots(&agent_home);
+ for (root, kind) in [(skills, RootKind::Skill), (workflows, RootKind::Workflow)] {
+ if kinds.contains(&kind) {
+ tracing::trace!(
+ root = %root.display(),
+ ?kind,
+ scope = ?WorkflowScope::User,
+ "[workflows] discover:branch:agent"
+ );
+ discovered.extend(scan_root(&root, WorkflowScope::User));
+ }
+ }
+ }
+
if let Some(ws) = workspace_dir {
if trusted {
for (root, kind) in project_roots(ws) {
diff --git a/crates/openhuman-core/src/skills/ops_install/fetch.rs b/crates/openhuman-core/src/skills/ops_install/fetch.rs
index 5b1af02d8e..01652b29da 100644
--- a/crates/openhuman-core/src/skills/ops_install/fetch.rs
+++ b/crates/openhuman-core/src/skills/ops_install/fetch.rs
@@ -293,10 +293,8 @@ pub(crate) async fn install_workflow_from_url_with_home(
// scans unconditionally. Project scope (`<ws>/.openhuman/skills/`) is gated on
// a `<ws>/.openhuman/trust` marker and would render the install invisible to the
// skills list until the user opts the workspace into trust.
- let skills_root = home
- .ok_or_else(|| "write failed: unable to resolve home directory".to_string())?
- .join(".openhuman")
- .join("skills");
+ let skills_root = crate::skills::write_root::user_skill_install_root(workspace_dir, home)
+ .ok_or_else(|| "write failed: unable to resolve home directory".to_string())?;
let target_file =
match write_installed_document(&skills_root, &slug, &content).map_err(|e| e.to_string())? {
diff --git a/crates/openhuman-core/src/skills/ops_install/uninstall.rs b/crates/openhuman-core/src/skills/ops_install/uninstall.rs
index d4239a9b4f..4416884cdf 100644
--- a/crates/openhuman-core/src/skills/ops_install/uninstall.rs
+++ b/crates/openhuman-core/src/skills/ops_install/uninstall.rs
@@ -54,11 +54,17 @@ pub fn uninstall_workflow(
// uninstalled). Slug validation and the symlink/containment/bundle checks
// are owned by `tinyskills::remove_bundle`.
let openhuman_dir = home.join(".openhuman");
- let roots = [
- openhuman_dir.join("workflows"),
- openhuman_dir.join("skills"),
- home.join(".agents").join("skills"),
- ];
+ let roots: Vec<_> = match crate::skills::write_root::current_agent_skill_home() {
+ Some(agent_home) => crate::skills::write_root::agent_user_roots(&agent_home)
+ .into_iter()
+ .rev()
+ .collect(),
+ None => vec![
+ openhuman_dir.join("workflows"),
+ openhuman_dir.join("skills"),
+ home.join(".agents").join("skills"),
+ ],
+ };
let removed = tinyskills::remove_bundle(&roots, &trimmed).map_err(|e| {
log::warn!("[skills] uninstall_workflow: refused name={trimmed:?} error={e}");
diff --git a/crates/openhuman-core/src/skills/write_root.rs b/crates/openhuman-core/src/skills/write_root.rs
new file mode 100644
index 0000000000..1d996853cb
--- /dev/null
+++ b/crates/openhuman-core/src/skills/write_root.rs
@@ -0,0 +1,56 @@
+//! Where an embedded agent's own skills live.
+//!
+//! An agent derived on a shared workspace keeps the skills it installs or
+//! creates under `<workspace>/agents/<id>/`, in place of the operator's home
+//! directory: `skills/` for SKILL.md bundles, `workflows/` for automations.
+//! Discovery scans those roots for that agent only, so a skill one agent
+//! writes is neither seen by its siblings nor written into the operator's
+//! `~/.openhuman`.
+
+use std::path::{Path, PathBuf};
+
+/// The current agent's skills home under `workspace_dir`, or `None` outside
+/// an embedded agent's context.
+#[must_use]
+pub fn agent_skill_home(workspace_dir: &Path) -> Option<PathBuf> {
+ let agent = crate::core::runtime::agent_scope::current_agent_id()?;
+ Some(workspace_dir.join("agents").join(agent))
+}
+
+/// The current agent's skills home under its context's workspace, or `None`
+/// outside an embedded agent's context — for callers that hold no workspace
+/// path.
+#[must_use]
+pub fn current_agent_skill_home() -> Option<PathBuf> {
+ let workspace = crate::core::runtime::CoreContext::current()?
+ .workspace_dir()
+ .ok()?;
+ agent_skill_home(&workspace)
+}
+
+/// The roots an agent's user-scope bundles are discovered from and removed
+/// from, newest layout last so it wins a name collision.
+#[must_use]
+pub fn agent_user_roots(agent_home: &Path) -> [PathBuf; 2] {
+ [agent_home.join("skills"), agent_home.join("workflows")]
+}
+
+/// Where a user-scope SKILL.md bundle is installed: the agent's `skills/`
+/// under an embedded agent's context, else `~/.openhuman/skills`.
+#[must_use]
+pub fn user_skill_install_root(workspace_dir: &Path, home: Option<&Path>) -> Option<PathBuf> {
+ match agent_skill_home(workspace_dir) {
+ Some(agent_home) => Some(agent_home.join("skills")),
+ None => home.map(|home| home.join(".openhuman").join("skills")),
+ }
+}
+
+/// Where a user-scope workflow is created: the agent's `workflows/` under an
+/// embedded agent's context, else `~/.openhuman/workflows`.
+#[must_use]
+pub fn user_workflow_root(workspace_dir: &Path, home: Option<&Path>) -> Option<PathBuf> {
+ match agent_skill_home(workspace_dir) {
+ Some(agent_home) => Some(agent_home.join("workflows")),
+ None => home.map(|home| home.join(".openhuman").join("workflows")),
+ }
+}