Skip to content

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

Rust

fix(cli): lift thin-client base-path env read into Config (post-#82 invariant)

AkitaOnRails2a600ec6a21b
diff --git a/crates/ai-memory-cli/src/config.rs b/crates/ai-memory-cli/src/config.rs
index 4c3f7dc4..c9d48eec 100644
--- a/crates/ai-memory-cli/src/config.rs
+++ b/crates/ai-memory-cli/src/config.rs
@@ -51,6 +51,16 @@ pub struct Config {
pub bind: String,
/// Base URL used by thin-client CLI commands to contact the running server.
pub server_url: 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
+ /// `AI_MEMORY_BASE_PATH`. Empty for root-mounted deployments (the
+ /// default). The `serve` subcommand reads the same env var via clap and
+ /// nests its router accordingly; this field is what the thin-client
+ /// path needs to discover the same prefix without a second
+ /// `std::env::var` call (invariant: one config-read path).
+ #[serde(default)]
+ pub base_path: String,
/// Per-subsystem log filter (overridable by `RUST_LOG`).
pub log_level: String,
/// Optional LLM provider (`anthropic`, `openai`, `gemini`, `openai-compat`, `openai-oauth`, `copilot`).
@@ -319,6 +329,7 @@ impl Default for Config {
data_dir: default_data_dir(),
bind: DEFAULT_BIND.into(),
server_url: DEFAULT_SERVER_URL.into(),
+ base_path: String::new(),
log_level: "info".into(),
llm_provider: None,
llm_model: None,
diff --git a/crates/ai-memory-cli/src/http_client.rs b/crates/ai-memory-cli/src/http_client.rs
index 0f0aa3e6..2eed5aa1 100644
--- a/crates/ai-memory-cli/src/http_client.rs
+++ b/crates/ai-memory-cli/src/http_client.rs
@@ -44,16 +44,18 @@ impl ServerEndpoint {
/// 1. the **path component of `AI_MEMORY_SERVER_URL`** (the remote-client
/// case — `http://host:49374/wiki` → origin `http://host:49374`,
/// base `/wiki`), then
- /// 2. **`AI_MEMORY_BASE_PATH`** (the in-pod case — the CLI runs in the
- /// same container as `serve`, which already reads this var to nest
- /// its router).
+ /// 2. **`Config::base_path`** (the in-pod case — figment populates the
+ /// field from `AI_MEMORY_BASE_PATH` inside `Config::load`, keeping the
+ /// "one config-read path" invariant; the CLI runs in the same
+ /// container as `serve`, which already reads the same env var via
+ /// clap to nest its router).
#[must_use]
pub fn from_config(config: &Config) -> Self {
Self::build(
Some(config.server_url.clone()),
config.auth.bearer_token.clone(),
config.server_url_configured(),
- std::env::var("AI_MEMORY_BASE_PATH").ok(),
+ Some(config.base_path.clone()).filter(|s| !s.is_empty()),
)
}