Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

feat(config): add optional release base URL for upgrades

Ruben Licio Reis35c29d01ea60
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5adfb4d3..b8f591d6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,7 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
present), then re-runs `install-hooks --apply` for staged agents. Refuses
package-managed paths (Homebrew/AUR/`/usr`), containers, and Windows
self-replace; the Docker wrapper's `upgrade` path is unchanged. Pin with
- `--version` / force a re-download with `--force`. (#801)
+ `--version` / force a re-download with `--force`. Optional
+ `AI_MEMORY_RELEASE_BASE_URL` / `release_base_url` overrides the Releases
+ base for mirrors and hermetic tests (loaded via `Config`, not ad-hoc env).
+ (#801)
## [2.3.2] - 2026-09-20
diff --git a/crates/ai-memory-cli/src/commands/upgrade.rs b/crates/ai-memory-cli/src/commands/upgrade.rs
index 644a6e20..acb40300 100644
--- a/crates/ai-memory-cli/src/commands/upgrade.rs
+++ b/crates/ai-memory-cli/src/commands/upgrade.rs
@@ -55,7 +55,7 @@ async fn run_unix(config: &Config, args: UpgradeArgs) -> Result<()> {
}
let fetcher = ReqwestFetcher::new()?;
- let base = release_base_url();
+ let base = release_base_url(config);
let tag = resolve_tag(&fetcher, &base, args.version.as_deref()).await?;
let current = env!("CARGO_PKG_VERSION");
if !args.force && versions_match(&tag, current) {
@@ -193,9 +193,14 @@ fn is_writable_file(path: &Path) -> bool {
fs::OpenOptions::new().write(true).open(path).is_ok()
}
-fn release_base_url() -> String {
- std::env::var("AI_MEMORY_RELEASE_BASE_URL")
- .unwrap_or_else(|_| format!("https://github.com/{RELEASE_OWNER_REPO}/releases"))
+fn release_base_url(config: &Config) -> String {
+ config
+ .release_base_url
+ .as_deref()
+ .map(str::trim)
+ .filter(|s| !s.is_empty())
+ .map(str::to_string)
+ .unwrap_or_else(|| format!("https://github.com/{RELEASE_OWNER_REPO}/releases"))
}
fn release_asset_name() -> Option<&'static str> {
@@ -688,6 +693,69 @@ mod tests {
assert!(!dest.with_extension("new").exists());
}
+ #[test]
+ fn replace_dir_atomic_swaps_tree_and_cleans_backup() {
+ let dir = tempfile::tempdir().unwrap();
+ let dest = dir.path().join("hooks");
+ let src = dir.path().join("fresh-hooks");
+ fs::create_dir_all(dest.join("claude-code")).unwrap();
+ fs::write(dest.join("claude-code/old.sh"), b"old").unwrap();
+ fs::create_dir_all(src.join("claude-code")).unwrap();
+ fs::write(src.join("claude-code/new.sh"), b"new").unwrap();
+
+ replace_dir_atomic(&src, &dest).unwrap();
+
+ assert_eq!(fs::read(dest.join("claude-code/new.sh")).unwrap(), b"new");
+ assert!(!dest.join("claude-code/old.sh").exists());
+ assert!(!dir.path().join(".hooks.old").exists());
+ assert!(!dir.path().join(".hooks.new").exists());
+ }
+
+ #[test]
+ fn release_base_url_prefers_config_override() {
+ let mut config = Config::default();
+ assert!(
+ release_base_url(&config).contains("github.com/akitaonrails/ai-memory/releases")
+ );
+ config.release_base_url = Some(" http://127.0.0.1:9/releases ".into());
+ assert_eq!(release_base_url(&config), "http://127.0.0.1:9/releases");
+ }
+
+ #[tokio::test]
+ async fn resolve_tag_reads_latest_tag_from_non_github_base() {
+ use tokio::io::{AsyncReadExt as _, AsyncWriteExt as _};
+
+ let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
+ let addr = listener.local_addr().unwrap();
+ tokio::spawn(async move {
+ let Ok((mut stream, _)) = listener.accept().await else {
+ return;
+ };
+ let mut buf = [0_u8; 4096];
+ let _ = stream.read(&mut buf).await;
+ let body = "v9.9.9";
+ let response = format!(
+ "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
+ body.len()
+ );
+ let _ = stream.write_all(response.as_bytes()).await;
+ });
+
+ let fetcher = ReqwestFetcher::new().unwrap();
+ let base = format!("http://{addr}/releases");
+ let tag = resolve_tag(&fetcher, &base, None).await.unwrap();
+ assert_eq!(tag, "v9.9.9");
+ }
+
+ #[tokio::test]
+ async fn resolve_tag_honors_pinned_version_without_network() {
+ let fetcher = ReqwestFetcher::new().unwrap();
+ let tag = resolve_tag(&fetcher, "http://127.0.0.1:1/unused", Some("2.3.2"))
+ .await
+ .unwrap();
+ assert_eq!(tag, "v2.3.2");
+ }
+
#[test]
fn is_loopback_detects_common_forms() {
assert!(is_loopback_url("http://127.0.0.1:49374"));
diff --git a/crates/ai-memory-cli/src/config.rs b/crates/ai-memory-cli/src/config.rs
index 5145cc1b..47b3b05a 100644
--- a/crates/ai-memory-cli/src/config.rs
+++ b/crates/ai-memory-cli/src/config.rs
@@ -161,6 +161,13 @@ pub struct Config {
pub bind: String,
/// Base URL used by thin-client CLI commands to contact the running server.
pub server_url: String,
+ /// Optional override for the GitHub Releases base URL used by
+ /// `ai-memory upgrade` (archive + `.sha256` download). Empty/unset
+ /// means `https://github.com/akitaonrails/ai-memory/releases`. Set via
+ /// `AI_MEMORY_RELEASE_BASE_URL` or `release_base_url` in config.toml —
+ /// intended for hermetic tests and mirrors, not day-to-day installs.
+ #[serde(default)]
+ pub release_base_url: Option<String>,
/// URL subpath the server is mounted under (e.g. `/wiki`). Thin-client
/// CLI commands prepend it to every `/admin/*` request so deployments
/// hosted behind a reverse proxy under a subpath don't 404. Settable via
@@ -734,6 +741,7 @@ impl Default for Config {
data_dir: default_data_dir(),
bind: DEFAULT_BIND.into(),
server_url: DEFAULT_SERVER_URL.into(),
+ release_base_url: None,
base_path: String::new(),
home_dir: None,
log_level: "info".into(),
diff --git a/docs/install.md b/docs/install.md
index a29e60c1..850c546f 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -2395,7 +2395,10 @@ the on-disk binary (and a sibling `hooks/` directory when present), then
re-stages hooks for agents already under the data-dir hooks tree. It refuses
Homebrew/AUR/`/usr` installs (use the package manager), Windows self-replace
(download the zip manually), and in-container binaries (upgrade the host
-wrapper/image instead).
+wrapper/image instead). For mirrors or hermetic tests, set
+`AI_MEMORY_RELEASE_BASE_URL` (or `release_base_url` in config.toml) to a
+Releases-compatible base that serves `{base}/latest/tag` and
+`{base}/download/<tag>/<asset>` (+ `.sha256`).
### Shared notes