Skip to content

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

Rust

fixup(devin): audit follow-ups — APPDATA uninstall sweep, docs, nits

AkitaOnRails62125207fe9c
diff --git a/.gitignore b/.gitignore
index 68921328..a17aab5b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -36,6 +36,3 @@ evals/runs/
# ai-memory atomic-write backups (apply_atomic in apply_shared.rs)
*.bak-*
-
-# SonarQube scanner working directory.
-.scannerwork/
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b7adf504..fb7897d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
payload `cwd` still wins, followed by `DEVIN_PROJECT_DIR`, then the hook
process working directory. This keeps real Devin `SessionStart` /
`PostToolUse` fixtures routable without inventing a payload field.
+ Payloads without a `session_id` are bridged the same way: a per-host id is
+ minted at `SessionStart`, reused for later events, and cleared at
+ `SessionEnd`; set `AI_MEMORY_SESSION_ID` in the hook environment to pin an
+ externally managed run id. A payload-supplied id always wins.
## [1.12.0] - 2026-07-12
@@ -282,6 +286,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
'{{.SecurityOptions}}'` and runs as `-u 0:0` for just the commands that
write host-side files; thin-client commands (`status`, `bootstrap`, …)
are unaffected since they only touch the `/data` named volume.
+
## [1.8.0] - 2026-07-04
### Added
diff --git a/crates/ai-memory-cli/src/commands/install_mcp.rs b/crates/ai-memory-cli/src/commands/install_mcp.rs
index 42ccf3bf..75c0509c 100644
--- a/crates/ai-memory-cli/src/commands/install_mcp.rs
+++ b/crates/ai-memory-cli/src/commands/install_mcp.rs
@@ -309,14 +309,14 @@ fn render_json_mcp_fragment(args: &InstallMcpArgs) -> Result<String> {
/// `httpUrl` plus optional `headers`. Returns the per-client variant.
fn build_mcp_entry(args: &InstallMcpArgs) -> Result<serde_json::Value> {
let bearer = bearer_header_value(args.auth_token.as_deref());
+ // `run()` resolves the URL before dispatch; the fallback only fires for
+ // direct callers (tests, uninstall re-render) that skip that step.
+ let server_url = args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL);
let mut entry = serde_json::Map::new();
match args.client {
McpClient::ClaudeCode => {
entry.insert("type".into(), json!("http"));
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
}
@@ -324,11 +324,7 @@ fn build_mcp_entry(args: &InstallMcpArgs) -> Result<serde_json::Value> {
McpClient::ClaudeDesktop => {
// Stdio shim via mcp-remote — Claude Desktop's JSON
// doesn't accept HTTP transport directly.
- let mut cmd_args = vec![
- json!("-y"),
- json!("mcp-remote"),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- ];
+ let mut cmd_args = vec![json!("-y"), json!("mcp-remote"), json!(server_url)];
if let Some(b) = &bearer {
cmd_args.push(json!("--header"));
cmd_args.push(json!("Authorization:${AI_MEMORY_AUTH_HEADER}"));
@@ -338,19 +334,13 @@ fn build_mcp_entry(args: &InstallMcpArgs) -> Result<serde_json::Value> {
entry.insert("args".into(), serde_json::Value::Array(cmd_args));
}
McpClient::Cursor => {
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
}
}
McpClient::GeminiCli => {
- entry.insert(
- "httpUrl".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("httpUrl".into(), json!(server_url));
entry.insert("timeout".into(), json!(GEMINI_MCP_TIMEOUT_MS));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
@@ -358,30 +348,21 @@ fn build_mcp_entry(args: &InstallMcpArgs) -> Result<serde_json::Value> {
}
McpClient::Omp => {
entry.insert("type".into(), json!("http"));
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
entry.insert("enabled".into(), json!(true));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
}
}
McpClient::AntigravityCli => {
- entry.insert(
- "serverUrl".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("serverUrl".into(), json!(server_url));
entry.insert("timeout".into(), json!(GEMINI_MCP_TIMEOUT_MS));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
}
}
McpClient::Devin => {
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
entry.insert("transport".into(), json!("http"));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
@@ -394,10 +375,7 @@ fn build_mcp_entry(args: &InstallMcpArgs) -> Result<serde_json::Value> {
// The `mcpServers` key (used by Claude Code/Cursor/Gemini)
// is silently ignored here — VS Code reads `servers`.
entry.insert("type".into(), json!("http"));
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
if let Some(b) = &bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
}
@@ -409,12 +387,10 @@ fn build_mcp_entry(args: &InstallMcpArgs) -> Result<serde_json::Value> {
fn build_mcp_entry_opencode(args: &InstallMcpArgs) -> Result<serde_json::Value> {
let bearer = bearer_header_value(args.auth_token.as_deref());
+ let server_url = args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL);
let mut entry = serde_json::Map::new();
entry.insert("type".into(), json!("remote"));
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
entry.insert("enabled".into(), json!(true));
if let Some(b) = bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
@@ -424,11 +400,9 @@ fn build_mcp_entry_opencode(args: &InstallMcpArgs) -> Result<serde_json::Value>
fn build_mcp_entry_openclaw(args: &InstallMcpArgs) -> Result<serde_json::Value> {
let bearer = bearer_header_value(args.auth_token.as_deref());
+ let server_url = args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL);
let mut entry = serde_json::Map::new();
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
entry.insert("transport".into(), json!("streamable-http"));
if let Some(b) = bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
@@ -441,12 +415,10 @@ fn build_mcp_entry_openclaw(args: &InstallMcpArgs) -> Result<serde_json::Value>
/// `type: "http"` + `url` + a `headers` map (issue #156).
fn build_mcp_entry_zero(args: &InstallMcpArgs) -> Result<serde_json::Value> {
let bearer = bearer_header_value(args.auth_token.as_deref());
+ let server_url = args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL);
let mut entry = serde_json::Map::new();
entry.insert("type".into(), json!("http"));
- entry.insert(
- "url".into(),
- json!(args.server_url.as_deref().unwrap_or(DEFAULT_MCP_URL)),
- );
+ entry.insert("url".into(), json!(server_url));
if let Some(b) = bearer {
entry.insert("headers".into(), json!({"Authorization": b}));
}
diff --git a/crates/ai-memory-cli/src/commands/uninstall.rs b/crates/ai-memory-cli/src/commands/uninstall.rs
index b0daabaa..760a963f 100644
--- a/crates/ai-memory-cli/src/commands/uninstall.rs
+++ b/crates/ai-memory-cli/src/commands/uninstall.rs
@@ -307,7 +307,8 @@ fn build_plan(args: &UninstallArgs) -> anyhow::Result<Vec<PlannedChange>> {
if want(crate::cli::UninstallOnly::Skills) {
let cwd = std::env::current_dir().context("getting CWD for skill removal")?;
let home = home_dir();
- for root in skill_roots(&cwd, home.as_deref()) {
+ let appdata = std::env::var_os("APPDATA").map(PathBuf::from);
+ for root in skill_roots(&cwd, home.as_deref(), appdata.as_deref()) {
for skill in MANAGED_SKILLS {
push_generated_delete(
&mut plan,
@@ -321,8 +322,8 @@ fn build_plan(args: &UninstallArgs) -> anyhow::Result<Vec<PlannedChange>> {
Ok(plan)
}
-fn skill_roots(cwd: &Path, home: Option<&Path>) -> Vec<PathBuf> {
- let mut roots = Vec::with_capacity(6);
+fn skill_roots(cwd: &Path, home: Option<&Path>, appdata: Option<&Path>) -> Vec<PathBuf> {
+ let mut roots = Vec::with_capacity(7);
push_unique_skill_root(&mut roots, cwd.join(CLAUDE_SKILL_DIR).join(SKILLS_DIR));
push_unique_skill_root(&mut roots, cwd.join(AGENTS_SKILL_DIR).join(SKILLS_DIR));
push_unique_skill_root(&mut roots, cwd.join(DEVIN_SKILL_DIR).join(SKILLS_DIR));
@@ -331,6 +332,11 @@ fn skill_roots(cwd: &Path, home: Option<&Path>) -> Vec<PathBuf> {
push_unique_skill_root(&mut roots, home.join(AGENTS_SKILL_DIR).join(SKILLS_DIR));
push_unique_skill_root(&mut roots, home.join(DEVIN_SKILL_DIR).join(SKILLS_DIR));
}
+ // Windows global Devin installs live under %APPDATA%\devin\skills, not
+ // $HOME/.devin/skills — sweep it too or uninstall orphans those skills.
+ if let Some(appdata) = appdata {
+ push_unique_skill_root(&mut roots, appdata.join("devin").join(SKILLS_DIR));
+ }
roots
}
@@ -962,6 +968,25 @@ fn strip_mcp_toml(content: &str, name: Option<&str>, url: &str) -> Result<(Strin
mod tests {
use super::*;
+ /// The Windows global Devin skill root (`%APPDATA%\devin\skills`) is
+ /// swept alongside the cwd/home roots — `install-skills --scope global`
+ /// writes there on Windows, so uninstall must plan its removal too.
+ #[test]
+ fn skill_roots_include_windows_appdata_devin_root() {
+ let cwd = Path::new("/repo");
+ let home = Path::new("/home/alice");
+ let appdata = Path::new("C:/Users/Alice/AppData/Roaming");
+
+ let roots = skill_roots(cwd, Some(home), Some(appdata));
+ assert!(
+ roots.contains(&appdata.join("devin").join(SKILLS_DIR)),
+ "{roots:?}"
+ );
+
+ let without = skill_roots(cwd, Some(home), None);
+ assert_eq!(without.len(), 6, "no phantom root when APPDATA is unset");
+ }
+
#[test]
fn strip_instructions_round_trips_with_install_append() {
let original = "# Title\n";
diff --git a/crates/ai-memory-hooks/src/router.rs b/crates/ai-memory-hooks/src/router.rs
index a8296652..3dd7e3d6 100644
--- a/crates/ai-memory-hooks/src/router.rs
+++ b/crates/ai-memory-hooks/src/router.rs
@@ -5453,11 +5453,8 @@ mod tests {
);
}
- #[tokio::test]
- async fn post_compaction_captures_summary_field() {
- let tmp = TempDir::new().unwrap();
- let _state = make_state(&tmp).await;
-
+ #[test]
+ fn post_compaction_captures_summary_field() {
let query = HookQuery {
event: "post-compaction".into(),
agent: Some("devin".into()),
@@ -5481,11 +5478,8 @@ mod tests {
);
}
- #[tokio::test]
- async fn post_compaction_priority_is_mapped() {
- let tmp = TempDir::new().unwrap();
- let _state = make_state(&tmp).await;
-
+ #[test]
+ fn post_compaction_priority_is_mapped() {
let query = HookQuery {
event: "post-compaction".into(),
agent: Some("devin".into()),
@@ -5504,72 +5498,6 @@ mod tests {
);
}
- #[test]
- fn post_compaction_router_branch_exists() {
- // Verify that PostCompaction is handled in the router
- // by checking that the importance_for function includes it.
- // The consolidation branch is covered by the importance check
- // and by the explicit branch in process() that calls consolidate_or_synth.
- assert_eq!(importance_for(HookEvent::PostCompaction), 6);
- }
-
- #[tokio::test]
- async fn post_compaction_triggers_consolidation() {
- let tmp = TempDir::new().unwrap();
- let state = make_state(&tmp).await;
- let sid = "44444444-4444-4444-4444-444444444444";
- let session_path = format!("sessions/{sid}.md");
- let summary = "Context compacted: 15000/20000 tokens used";
-
- let start = HookEnvelope::from_query_and_body(
- HookQuery {
- event: "session-start".into(),
- agent: Some("devin".into()),
- ..Default::default()
- },
- serde_json::json!({
- "hook_event_name": "SessionStart",
- "session_id": sid,
- "source": "startup"
- }),
- );
- process(&state, start, None).await.unwrap();
-
- let pages_before = state
- .reader
- .recent_pages_for_project(state.workspace_id, state.project_id, 20)
- .await
- .unwrap();
- assert!(
- pages_before.iter().all(|p| p.path.as_str() != session_path),
- "SessionStart alone must not write a sessions/<id>.md checkpoint"
- );
-
- let post_compaction = HookEnvelope::from_query_and_body(
- HookQuery {
- event: "post-compaction".into(),
- agent: Some("devin".into()),
- ..Default::default()
- },
- serde_json::json!({
- "hook_event_name": "PostCompaction",
- "session_id": sid,
- "summary": summary
- }),
- );
- process(&state, post_compaction, None).await.unwrap();
-
- let pages_after = state
- .reader
- .recent_pages_for_project(state.workspace_id, state.project_id, 20)
- .await
- .unwrap();
- assert!(
- pages_after.iter().any(|p| p.path.as_str() == session_path),
- "PostCompaction must write a sessions/<id>.md checkpoint"
- );
- }
-
#[tokio::test]
async fn post_compaction_writes_rule_based_session_checkpoint_without_consolidator() {
let tmp = TempDir::new().unwrap();
diff --git a/docs/mcp-install.md b/docs/mcp-install.md
index 0a7620c1..d1772736 100644
--- a/docs/mcp-install.md
+++ b/docs/mcp-install.md
@@ -492,6 +492,23 @@ Session-start handoff injection is built in: the generated Devin SessionStart
hook returns `hookSpecificOutput.additionalContext` when a pending handoff is
available.
+Real Devin hook payloads may omit `session_id` and `cwd`; the installed hooks
+fill both in:
+
+- **cwd** — the payload's `cwd` wins when present, then the
+ `DEVIN_PROJECT_DIR` environment variable (when Devin's launcher provides
+ it), then the hook process working directory.
+- **session id** — when the payload has none, the hook mints one at
+ `SessionStart`, stores it in a single per-host slot
+ (`<data-dir>/hook-state/devin-session-id`), reuses it for every later
+ event, and clears it at `SessionEnd`. Set `AI_MEMORY_SESSION_ID` in the
+ hook environment to pin an externally managed run id instead. Because the
+ slot is per host+agent, two Devin sessions running *concurrently* on the
+ same machine share it — the newest `SessionStart` wins and earlier
+ sessions' remaining events are attributed to it (same graceful-degradation
+ stance as the single-slot `/handoff` fallback). A payload that does carry
+ its own `session_id` always wins over both.
+
## OpenClaw
**Status:** ✅ MCP supported. ✅ Lifecycle hooks supported via a native