Skip to content

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

fix(memory): keep two repositories out of one GitHub collection

M3gA-Mindbe464efc03f6
diff --git a/crates/openhuman-core/src/config/schema/memory.rs b/crates/openhuman-core/src/config/schema/memory.rs
index 9dacd422bd..1d883ba335 100644
--- a/crates/openhuman-core/src/config/schema/memory.rs
+++ b/crates/openhuman-core/src/config/schema/memory.rs
@@ -135,7 +135,7 @@ pub struct MemoryConfig {
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
pub agents: BTreeMap<String, MemoryAgentConfig>,
/// File GitHub documents one scope per repository
- /// (`source:github/project:<owner>-<repo>`) rather than all in
+ /// (`source:github/project:<owner>--<repo>`) rather than all in
/// `source:github`. Off by default: every turn reads each brain scope,
/// so each repository adds a recall to every turn.
#[serde(skip_serializing_if = "std::ops::Not::not")]
diff --git a/crates/openhuman-core/src/memory/brain.rs b/crates/openhuman-core/src/memory/brain.rs
index a80f21f864..926de2375a 100644
--- a/crates/openhuman-core/src/memory/brain.rs
+++ b/crates/openhuman-core/src/memory/brain.rs
@@ -54,8 +54,11 @@ pub fn brain_source(kind: MemorySourceKind, target: &str) -> BrainSource {
}
/// The repository a GitHub document belongs to, as the collection id
-/// `<owner>-<repo>` (lowercase, as GitHub's names are case-insensitive):
-/// from its `repo` (`owner/name` or a URL), else its URL.
+/// `<owner>--<repo>` (lowercase, as GitHub's names are case-insensitive):
+/// from its `repo` (`owner/name` or a URL), else its URL. An owner name
+/// never holds `--` nor ends in `-`, so the first `--` always splits the
+/// two and no two repositories share an id (`foo-bar/repo` and
+/// `foo/bar-repo` stay apart).
#[must_use]
pub fn github_collection(item: &StoreItem) -> Option<String> {
let meta = item.meta();
@@ -69,11 +72,13 @@ pub fn github_collection(item: &StoreItem) -> Option<String> {
.trim_start_matches("http://")
.trim_start_matches("www.")
.trim_start_matches("github.com/");
+ // A URL's query or fragment is not part of the path.
+ let path = path.split(['?', '#']).next().unwrap_or_default();
let mut parts = path.split('/').filter(|part| !part.is_empty());
let (owner, repo) = (parts.next()?, parts.next()?);
let repo = repo.trim_end_matches(".git");
(!owner.contains('.') && !repo.is_empty())
- .then(|| format!("{owner}-{repo}").to_ascii_lowercase())
+ .then(|| format!("{owner}--{repo}").to_ascii_lowercase())
})
}
diff --git a/crates/openhuman-core/src/memory/brain_tests.rs b/crates/openhuman-core/src/memory/brain_tests.rs
index b3a9bdc97d..3d0ff07107 100644
--- a/crates/openhuman-core/src/memory/brain_tests.rs
+++ b/crates/openhuman-core/src/memory/brain_tests.rs
@@ -53,10 +53,10 @@ fn a_github_document_names_its_repository() {
item.meta_mut().url = url.map(str::to_string);
github_collection(&item)
};
- assert_eq!(with(Some("Acme/API"), None).as_deref(), Some("acme-api"));
+ assert_eq!(with(Some("Acme/API"), None).as_deref(), Some("acme--api"));
assert_eq!(
with(Some("https://github.com/acme/api.git"), None).as_deref(),
- Some("acme-api")
+ Some("acme--api")
);
// A Composio issue carries only its URL.
assert_eq!(
@@ -65,11 +65,21 @@ fn a_github_document_names_its_repository() {
Some("https://github.com/tinyhumansai/openhuman/issues/12")
)
.as_deref(),
- Some("tinyhumansai-openhuman")
+ Some("tinyhumansai--openhuman")
);
assert_eq!(with(None, Some("https://example.com/a/b")), None);
assert_eq!(with(Some("acme"), None), None);
assert_eq!(with(None, None), None);
+ // A query or fragment is not part of the repository.
+ assert_eq!(
+ with(None, Some("https://github.com/acme/api?tab=readme#top")).as_deref(),
+ Some("acme--api")
+ );
+ // Hyphens on either side never make two repositories one collection.
+ assert_ne!(
+ with(Some("foo-bar/repo"), None),
+ with(Some("foo/bar-repo"), None)
+ );
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/memory/sources/sync_tests.rs b/crates/openhuman-core/src/memory/sources/sync_tests.rs
index 45b48dc55d..f1f7486624 100644
--- a/crates/openhuman-core/src/memory/sources/sync_tests.rs
+++ b/crates/openhuman-core/src/memory/sources/sync_tests.rs
@@ -401,8 +401,8 @@ async fn github_files_per_repository_only_when_switched_on() {
nodes().await,
[
"source:github",
- "source:github/project:acme-api",
- "source:github/project:acme-web"
+ "source:github/project:acme--api",
+ "source:github/project:acme--web"
]
);
assert_eq!(