Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
feat(identity): add the path-only key normaliser and identity style (#1033)
AkitaOnRailsa945bc479d3b
diff --git a/crates/ai-memory-core/fixtures/remote_identity_cases.json b/crates/ai-memory-core/fixtures/remote_identity_cases.jsonindex 7b5cfc9b..51904f99 100644--- a/crates/ai-memory-core/fixtures/remote_identity_cases.json+++ b/crates/ai-memory-core/fixtures/remote_identity_cases.json@@ -41,5 +41,12 @@{ "identity": "github.com/acme/api.git", "name": "acme-api.git" },{ "identity": "acme platform", "name": "acme-platform" },{ "identity": "ana/personal notes", "name": "ana-personal-notes" }+ ],+ "styled_key": [+ { "identity": "github.com/akitaonrails/ai-memory", "source": "git_remote", "path": "akitaonrails/ai-memory", "host_path": "github.com/akitaonrails/ai-memory" },+ { "identity": "gitlab.com/acme/group/api", "source": "git_remote", "path": "acme/group/api", "host_path": "gitlab.com/acme/group/api" },+ { "identity": "ssh.dev.azure.com/v3/acme/proj/api", "source": "git_remote", "path": "v3/acme/proj/api", "host_path": "ssh.dev.azure.com/v3/acme/proj/api" },+ { "identity": "acme/platform", "source": "explicit", "path": "acme/platform", "host_path": "acme/platform" },+ { "identity": "api", "source": "folder_name", "path": "api", "host_path": "api" }]}diff --git a/crates/ai-memory-core/src/repository_identity.rs b/crates/ai-memory-core/src/repository_identity.rsindex 6bccb67e..241d2f29 100644--- a/crates/ai-memory-core/src/repository_identity.rs+++ b/crates/ai-memory-core/src/repository_identity.rs@@ -289,6 +289,61 @@ pub fn split_name_base(identity: &str) -> String {}}+/// How a remote-derived key spells a repository (#1033).+///+/// `HostPath` is the #708 identity exactly as it is stored and routed today,+/// and stays the default: nothing changes until a later step adopts `Path` as+/// a project's name. `Path` drops the host, so worktrees and clones of one+/// repository share a short `owner/repo` key; two forges hosting the same path+/// must still never share a project, which is why adoption has to detect that+/// collision rather than trust the key alone.+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]+pub enum IdentityStyle {+ /// `acme/api` — the repository path without its host.+ Path,+ /// `github.com/acme/api` — the full #708 identity.+ #[default]+ HostPath,+}++impl IdentityStyle {+ /// The marker spelling.+ #[must_use]+ pub fn as_str(self) -> &'static str {+ match self {+ Self::Path => "path",+ Self::HostPath => "host_path",+ }+ }++ /// Parse the marker spelling. Unknown values are `None`, so a typo is+ /// reported instead of silently picking a style.+ #[must_use]+ pub fn from_str_opt(s: &str) -> Option<Self> {+ match s.trim() {+ "path" => Some(Self::Path),+ "host_path" => Some(Self::HostPath),+ _ => None,+ }+ }+}++/// The key `identity` takes under `style`.+///+/// Only a git-remote identity has a host to drop. A declared identity, a+/// manifest name or a folder name is already the key a person chose (or the+/// only one there is), so every style returns it unchanged.+#[must_use]+pub fn styled_key(identity: &RepositoryIdentity, style: IdentityStyle) -> String {+ if style == IdentityStyle::HostPath || identity.source != IdentitySource::GitRemote {+ return identity.identity.clone();+ }+ match identity.identity.split_once('/') {+ Some((_host, path)) if !path.is_empty() => path.to_owned(),+ _ => identity.identity.clone(),+ }+}+fn non_empty(s: &str) -> Option<&str> {let t = s.trim();(!t.is_empty()).then_some(t)@@ -733,6 +788,61 @@ mod tests {const CASES: &str = include_str!("../fixtures/remote_identity_cases.json");+ /// #1033: `path` drops only a git remote's host, `host_path` is the #708+ /// identity unchanged, and declared or folder keys never change.+ #[test]+ fn styled_keys_match_the_shared_fixture() {+ let cases: serde_json::Value = serde_json::from_str(CASES).unwrap();+ for case in cases["styled_key"].as_array().unwrap() {+ let identity = RepositoryIdentity {+ identity: case["identity"].as_str().unwrap().to_owned(),+ source: IdentitySource::from_str_opt(case["source"].as_str().unwrap()).unwrap(),+ };+ for (style, field) in [+ (IdentityStyle::Path, "path"),+ (IdentityStyle::HostPath, "host_path"),+ ] {+ assert_eq!(+ styled_key(&identity, style),+ case[field].as_str().unwrap(),+ "{} as {field}",+ identity.identity+ );+ }+ }+ }++ /// The same path on two forges keeps two `host_path` keys but shares one+ /// `path` key — the collision adoption must detect, never merge.+ #[test]+ fn the_path_style_alone_cannot_tell_two_forges_apart() {+ let remote = |identity: &str| RepositoryIdentity {+ identity: identity.to_owned(),+ source: IdentitySource::GitRemote,+ };+ let github = remote("github.com/acme/api");+ let gitlab = remote("gitlab.com/acme/api");+ assert_eq!(+ styled_key(&github, IdentityStyle::Path),+ styled_key(&gitlab, IdentityStyle::Path)+ );+ assert_ne!(+ styled_key(&github, IdentityStyle::HostPath),+ styled_key(&gitlab, IdentityStyle::HostPath)+ );+ }++ #[test]+ fn identity_style_parses_only_its_marker_spellings() {+ assert_eq!(IdentityStyle::default(), IdentityStyle::HostPath);+ for style in [IdentityStyle::Path, IdentityStyle::HostPath] {+ assert_eq!(IdentityStyle::from_str_opt(style.as_str()), Some(style));+ }+ for bad in ["", "Path", "host-path", "hostpath", "owner_repo"] {+ assert_eq!(IdentityStyle::from_str_opt(bad), None, "{bad}");+ }+ }+/// The fixture every client normaliser is checked against. The Rust core/// is the reference: a case that fails here is a wrong fixture, a case/// that fails in a script client is a drifted port.diff --git a/docs/design-per-project-authz.md b/docs/design-per-project-authz.mdindex a7c86700..4a5686fc 100644--- a/docs/design-per-project-authz.md+++ b/docs/design-per-project-authz.md@@ -220,3 +220,33 @@ flag. Opt-in would leave the same-basename grant hole open for anyone who didnot opt in, defeating the authorization slices. The trade-off — that an upgradinginstall's captures re-bucket by repository identity (two same-name repos split; onerepo opened from two folders converges) — is documented in the CHANGELOG.++## Path-keyed coordinates (#1033 — staged)++Identity routing already converges worktrees and clones of one repository into+one project for **captures**. Two gaps remain: the project's **name** is still+the first-seen folder basename, and MCP tools resolve `(workspace, project)` by+that name, so a static client that passes a worktree folder misses the merged+project. #1033 makes a remote-derived key the default name, landing in steps on+`release/2.6`:++1. **Normaliser and style (landed first).** `repository_identity::styled_key`+ turns an identity into a key under `IdentityStyle`: `path` drops a git+ remote's host (`github.com/acme/api` → `acme/api`); `host_path` is the #708+ identity unchanged and stays the default. Declared and folder keys never+ change. Checked against the `styled_key` section of+ `fixtures/remote_identity_cases.json`. Nothing routes or names by it yet.+2. **Default naming chain** (`upstream` → `origin` → folder) for **new**+ projects, with marker `project`/`identity` still outranking remotes.+ **Cross-forge collisions are detected, never merged:** when a newcomer's+ `path` key is already held by a project under a different host+ (`github.com/acme/api` vs `gitlab.com/acme/api`), the newcomer takes its+ `host_path` key instead and `doctor` reports it. Needs an adversarial+ isolation test and a security-boundaries row.+3. **Dual-key resolve and in-place rename** (UUID foreign keys kept, no alias+ table) until v3, so existing basename projects are renamed toward their+ canonical key rather than split. Two operators on different clones of one+ repository must land in one project (`multi_session.rs`).+4. Marker `aliases`, then 5. identity- or path-keyed blocks in `~/.ai-memory.toml`.++Paths stay lexically normalised throughout; nothing canonicalises.