Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(run): default the jail's ssh toggle from the push URL and host aliases
Jovinull3236aea8c1b3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4ce62d08..d7b8b0a5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]+### Fixed+- Fixed `ai-memory run --jail` leaving the `ssh` toggle unchecked when+ `git push` goes over SSH but `origin`'s fetch URL does not show it: an HTTPS+ `origin` with an SSH `pushurl` or `pushInsteadOf`, or a `host:path` remote+ using an `~/.ssh/config` alias. (#1024)+## [2.5.2] - 2026-10-01### Addeddiff --git a/crates/ai-memory-workstream/src/jail.rs b/crates/ai-memory-workstream/src/jail.rsindex 180d3629..3a191251 100644--- a/crates/ai-memory-workstream/src/jail.rs+++ b/crates/ai-memory-workstream/src/jail.rs@@ -473,8 +473,8 @@ pub struct JailHostFacts {pub home: Option<PathBuf>,/// Whether `SSH_AUTH_SOCK` is set.pub ssh_agent: bool,- /// The repository's `origin` URL.- pub origin_url: Option<String>,+ /// The URL `git push` to `origin` uses.+ pub origin_push_url: Option<String>,/// Whether the cwd is a linked git worktree.pub linked_worktree: bool,/// Whether the invocation directory holds a project `.ai-jail`. ai-jail@@ -499,7 +499,7 @@ impl JailHostFacts {os: current_jail_os(),home: std::env::var_os("HOME").map(PathBuf::from),ssh_agent: std::env::var_os("SSH_AUTH_SOCK").is_some_and(|sock| !sock.is_empty()),- origin_url: repository.origin_url.clone(),+ origin_push_url: repository.origin_push_url.clone(),linked_worktree: repository.linked_worktree,}}@@ -512,7 +512,8 @@ impl JailHostFacts {}/// Whether `url` reaches its remote over SSH: `ssh://…` (and the `git+ssh`-/// spellings) or scp-style `user@host:path`.+/// spellings) or git's scp-style `[user@]host:path` (a `:` before any `/`),+/// where `host` may be an `~/.ssh/config` alias. A one-letter `C:` is a drive.#[must_use]fn is_ssh_remote(url: &str) -> bool {let url = url.trim();@@ -522,8 +523,10 @@ fn is_ssh_remote(url: &str) -> bool {"ssh" | "git+ssh" | "ssh+git");}- url.split_once(':')- .is_some_and(|(host, _)| host.contains('@') && !host.contains('/'))+ url.split_once(':').is_some_and(|(host, _)| {+ let drive = host.len() == 1 && host.as_bytes()[0].is_ascii_alphabetic();+ !host.is_empty() && !drive && !host.contains(['/', '\\'])+ })}/// One visible checklist row with its smart default.@@ -551,7 +554,7 @@ pub fn jail_checklist(facts: &JailHostFacts, support: &JailSupport) -> Vec<JailC}ToggleRule::Ssh => (facts.home_has(".ssh") || facts.ssh_agent,- facts.origin_url.as_deref().is_some_and(is_ssh_remote),+ facts.origin_push_url.as_deref().is_some_and(is_ssh_remote),),ToggleRule::OptIn { linux_only } => {(!linux_only || facts.os == JailOs::Linux, false)@@ -1096,7 +1099,7 @@ mod tests {os: JailOs::Linux,home: Some(home.to_path_buf()),ssh_agent: false,- origin_url: None,+ origin_push_url: None,linked_worktree: false,project_config: false,}@@ -1226,12 +1229,17 @@ mod tests {("[email protected]:example/repo.git", true),("ssh://[email protected]/repo.git", true),("[email protected]:repo.git", true),+ ("work-gh:example/repo.git", true),+ ("[::1]:repo.git", true),("https://github.com/example/repo.git", false),("https://[email protected]/repo.git", false),("/srv/git/repo.git", false),("file:///srv/git/repo.git", false),+ ("./dir:with-colon/repo.git", false),+ ("C:/src/repo.git", false),+ (r"C:\src\repo.git", false),] {- facts.origin_url = Some(url.to_owned());+ facts.origin_push_url = Some(url.to_owned());assert_eq!(ssh(&facts), Some(("ssh", expected)), "{url}");}}@@ -1278,7 +1286,7 @@ mod tests {fn project_config_unchecks_every_smart_default_but_keeps_explicit_lists() {let home = tempfile::tempdir().unwrap();let mut facts = facts_with(home.path(), &[".config/gh", ".aws", ".ssh"]);- facts.origin_url = Some("[email protected]:example/repo.git".to_owned());+ facts.origin_push_url = Some("[email protected]:example/repo.git".to_owned());facts.linked_worktree = true;let support = support_2_5_0();assert_eq!(@@ -1322,7 +1330,7 @@ mod tests {fn sample_checklist(home: &Path) -> Vec<JailChecklistItem> {let mut facts = facts_with(home, &[".config/gh", ".aws", ".ssh"]);- facts.origin_url = Some("https://example.com/repo.git".to_owned());+ facts.origin_push_url = Some("https://example.com/repo.git".to_owned());jail_checklist(&facts, &support_2_5_0())}diff --git a/crates/ai-memory-workstream/src/repository.rs b/crates/ai-memory-workstream/src/repository.rsindex 69fc2a54..73646994 100644--- a/crates/ai-memory-workstream/src/repository.rs+++ b/crates/ai-memory-workstream/src/repository.rs@@ -18,9 +18,9 @@ pub struct RepositoryIdentity {pub worktree_fingerprint: String,/// Current non-mutating Git checkpoint.pub checkpoint: WorkstreamCheckpoint,- /// First URL of the `origin` remote, when there is one. The ai-jail- /// toggles read it to decide whether `git push` needs SSH.- pub origin_url: Option<String>,+ /// The URL `git push` to `origin` uses (`pushurl`, or `url` after any+ /// `pushInsteadOf`). The ai-jail `ssh` default reads it.+ pub origin_push_url: Option<String>,/// Whether the cwd is a linked worktree (its git dir differs from the/// repository's common dir), whose metadata ai-jail must mount writable/// for the agent to commit.@@ -60,9 +60,9 @@ pub fn inspect_repository(cwd: &Path) -> Result<RepositoryIdentity> {repo_fingerprint: sha256(&repo_seed),worktree_fingerprint: sha256(&worktree_seed),checkpoint: checkpoint(&canonical),- origin_url: remotes+ origin_push_url: git(&canonical, &["remote", "get-url", "--push", "origin"]).as_deref()- .and_then(|remotes| remotes.lines().next())+ .and_then(|urls| urls.lines().next()).map(str::trim).filter(|url| !url.is_empty()).map(str::to_owned),@@ -161,7 +161,7 @@ mod tests {assert_eq!(first.repo_fingerprint, second.repo_fingerprint);assert_eq!(first.worktree_fingerprint, second.worktree_fingerprint);assert_eq!(first.repo_fingerprint.len(), 64);- assert_eq!(first.origin_url, None);+ assert_eq!(first.origin_push_url, None);assert!(!first.linked_worktree);}@@ -184,7 +184,7 @@ mod tests {/// The ai-jail toggle defaults key off these two facts: an SSH-style/// `origin` pre-checks `ssh`, and only a linked worktree shows `worktree`.#[test]- fn reports_origin_url_and_linked_worktree() {+ fn reports_origin_push_url_and_linked_worktree() {let temp = tempfile::tempdir().unwrap();let main = temp.path().join("main");std::fs::create_dir(&main).unwrap();@@ -206,7 +206,7 @@ mod tests {);let primary = inspect_repository(&main).unwrap();assert_eq!(- primary.origin_url.as_deref(),+ primary.origin_push_url.as_deref(),Some("[email protected]:example/repo.git"));assert!(!primary.linked_worktree, "the main checkout is not linked");@@ -225,7 +225,55 @@ mod tests {);let worktree = inspect_repository(&linked).unwrap();assert!(worktree.linked_worktree);- assert_eq!(worktree.origin_url, primary.origin_url);+ assert_eq!(worktree.origin_push_url, primary.origin_push_url);+ }++ /// The push URL counts, not the fetch URL. The `.invalid` host keeps a+ /// contributor's global `pushInsteadOf` out of the first case.+ #[test]+ fn origin_push_url_follows_push_rewrites() {+ let temp = tempfile::tempdir().unwrap();+ let repo = temp.path();+ git_fixture(repo, &["init", "-q"]);+ git_fixture(+ repo,+ &[+ "remote",+ "add",+ "origin",+ "https://git.example.invalid/example/repo.git",+ ],+ );+ assert_eq!(+ inspect_repository(repo).unwrap().origin_push_url.as_deref(),+ Some("https://git.example.invalid/example/repo.git")+ );++ git_fixture(+ repo,+ &[+ "config",+ "[email protected]:.pushInsteadOf",+ "https://git.example.invalid/",+ ],+ );+ assert_eq!(+ inspect_repository(repo).unwrap().origin_push_url.as_deref(),+ Some("[email protected]:example/repo.git")+ );++ git_fixture(+ repo,+ &[+ "config",+ "remote.origin.pushurl",+ "work-gh:example/repo.git",+ ],+ );+ assert_eq!(+ inspect_repository(repo).unwrap().origin_push_url.as_deref(),+ Some("work-gh:example/repo.git")+ );}#[test]diff --git a/docs/design-yolo-safety-ai-jail.md b/docs/design-yolo-safety-ai-jail.mdindex 2245d24e..7a904acd 100644--- a/docs/design-yolo-safety-ai-jail.md+++ b/docs/design-yolo-safety-ai-jail.md@@ -221,7 +221,7 @@ collision.| `kube` (`~/.kube`) | credential | when present | on when present || `gcloud` (`~/.config/gcloud`) | credential | when present | on when present || `docker-config` (`~/.docker/config.json`) | credential | when present | on when present |-| `ssh` (`~/.ssh` read-only + `SSH_AUTH_SOCK`) | credential | when `~/.ssh` exists or an agent socket is set | on only when `origin` is SSH-style (`git@host:…`, `ssh://…`) |+| `ssh` (`~/.ssh` read-only + `SSH_AUTH_SOCK`) | credential | when `~/.ssh` exists or an agent socket is set | on only when `git push` to `origin` goes over SSH (`git@host:…`, an `~/.ssh/config` alias `host:…`, `ssh://…`), read from the push URL so an HTTPS fetch URL with an SSH `pushurl`/`pushInsteadOf` still counts || `worktree` | capability | only in a linked git worktree | on there || `docker` (socket — ⚠ grants host root) | capability | always | off || `gpu`, `display` | capability | Linux only | off |@@ -377,7 +377,7 @@ directly.`is_terminal` gate and a `confirm`-style reader.- `ai-memory-cli/src/config.rs`: `[run] claude_true_yolo: bool` (default false).- §5: the toggle table, `--help` support detection (`JailSupport`), host facts- (`JailHostFacts`, fed by `inspect_repository`'s `origin_url` /+ (`JailHostFacts`, fed by `inspect_repository`'s `origin_push_url` /`linked_worktree`), `jail_checklist`, and `parse_jail_toggles` live in`jail.rs`; `run.rs` owns `--jail`/`--no-jail` parsing, the `jail_decision`table, and the checklist reader.