Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
docs(mcp): document handoff workspace scoping
AkitaOnRails9a5f9070b7ae
diff --git a/crates/ai-memory-core/src/routing_snippet.rs b/crates/ai-memory-core/src/routing_snippet.rsindex 573e9426..129c511b 100644--- a/crates/ai-memory-core/src/routing_snippet.rs+++ b/crates/ai-memory-core/src/routing_snippet.rs@@ -34,7 +34,7 @@ for cross-session continuity.**Default to the current project — always.** Every ai-memory toolauto-scopes to the project resolved from your session's working-directory. **Do NOT pass `project` or `cwd` arguments unless the user+directory. **Do NOT pass `project`, `workspace`, or `cwd` arguments unless the userexplicitly references a *different* project by name** (e.g. "what did wedecide in the `other-app` project?"). Phrases like "this project","here", "we", "our work", "where did we leave off" all mean the *current*@@ -66,8 +66,8 @@ match the intent to the tool. They do not need to name the tool.| "give me the stats" / structured snapshot for the agent to consume | `memory_briefing` (read-only; never creates handoffs) || "catch me up" / "I've been away" / "what's important right now?" / open-ended exploration | `memory_explore` || "where did we leave off?" — and you see a `📥 ai-memory: pending handoff` block in your context | already done — answer from that block; do NOT re-call `memory_handoff_accept` |-| "where did we leave off?" — and no such block is visible | `memory_handoff_accept` (rare; the SessionStart hook usually got there first) |-| "save context for the next session" / wrapping up / ending this session | `memory_handoff_begin` (session-end only; do **not** use for status/briefing; single-use handoff; terse summary; put detail in `open_questions` + `next_steps` bullets) |+| "where did we leave off?" — and no such block is visible | `memory_handoff_accept` (rare; the SessionStart hook usually got there first; pass `workspace` + `project` together only for a named sibling workspace/project) |+| "save context for the next session" / wrapping up / ending this session | `memory_handoff_begin` (session-end only; do **not** use for status/briefing; single-use handoff; terse summary; put detail in `open_questions` + `next_steps` bullets; pass `workspace` + `project` together only for a named sibling workspace/project) || "discard that handoff" / "I created a handoff by mistake" | `memory_handoff_cancel` (requires exact `handoff_id` from `memory_handoff_begin`; marks it expired before the next session sees it) || "consolidate this session" / "compile what we learned" (also runs on PreCompact; at session end only if `AI_MEMORY_CONSOLIDATE_ON_SESSION_END` is set) | `memory_consolidate` || "remember this permanently" / "save a note" / "add an annotation" / durable project knowledge | `memory_write_page` (write a wiki page; do **not** use handoff for permanent notes; put the title as a `# H1` on the first line of `body` and omit the `title` arg — ai-memory derives it from the H1) |diff --git a/crates/ai-memory-mcp/src/server.rs b/crates/ai-memory-mcp/src/server.rsindex 2ce71472..2e5ae42e 100644--- a/crates/ai-memory-mcp/src/server.rs+++ b/crates/ai-memory-mcp/src/server.rs@@ -31,7 +31,7 @@ Long-term memory for the current project.\n\\n\**Default to the current project — always.** Every tool here \auto-scopes to the project resolved from your session's working \-directory. **Do NOT pass `project` or `cwd` arguments unless the user \+directory. **Do NOT pass `project`, `workspace`, or `cwd` arguments unless the user \explicitly references a *different* project by name** (e.g. 'what did \we decide in the other-app project?'). Phrases like 'this project', \'here', 'we', 'our work', 'where did we leave off' all mean the \@@ -70,13 +70,17 @@ the conversation calls for them:\n\before you see your first prompt; if a block starting with \'📥 ai-memory: pending handoff' is anywhere in your context, \THAT is the handoff — answer from it directly, don't re-call \- this tool (it'll return null because handoffs are single-use).\n\+ this tool (it'll return null because handoffs are single-use). Pass \+ `workspace` + `project` together only when the user names a handoff \+ in a sibling workspace/project.\n\- `memory_handoff_begin` — ONLY when the user is wrapping up / ending \the current session and you want to ensure the next agent has context \(the SessionEnd hook also auto-captures this). DO NOT use this to \summarize work mid-session, check project status, or answer a request \for a briefing. Keep the summary terse (2-3 sentences); put detail \- in open_questions + next_steps bullets.\n\+ in open_questions + next_steps bullets. Pass `workspace` + `project` \+ together only when leaving a handoff for a named sibling \+ workspace/project.\n\- `memory_handoff_cancel` — when you realize you mistakenly called \`memory_handoff_begin`, or the user explicitly asks to discard a \pending handoff. Requires the exact `handoff_id` from the begin call \@@ -2158,6 +2162,27 @@ mod tests {}}+ #[test]+ fn prompts_teach_cross_workspace_handoff_scope() {+ for prompt in [MEMORY_INSTRUCTIONS, ai_memory_core::SNIPPET_BODY] {+ assert!(+ prompt.contains("memory_handoff_begin") && prompt.contains("memory_handoff_accept"),+ "prompt must include handoff lifecycle tools"+ );+ assert!(+ prompt.contains("workspace") && prompt.contains("project"),+ "handoff prompt guidance must mention workspace+project scoping"+ );+ assert!(+ prompt.contains("sibling")+ && (prompt.contains("workspace/project")+ || prompt.contains("workspace + project")+ || prompt.contains("workspace` + `project")),+ "handoff prompt guidance must restrict explicit workspace scope to named siblings"+ );+ }+ }+/// All three prompt surfaces must steer agents toward the H1-in-body/// convention instead of passing the `title` argument. The `title`/// argument is a known source of `JSON parsing` errors when the LLMdiff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex cefd27a4..4a1266a4 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -242,8 +242,8 @@ invariants below.| `memory_status` | read-only | Counts, paths, version. || `memory_briefing` | read-only | Structured counts/activity/rules/slots/recent snapshot. || `memory_explore` | read-only | LLM prose digest over the briefing snapshot, degrading to JSON without a provider. |-| `memory_handoff_begin` | destructive | Open a handoff for the next agent. |-| `memory_handoff_accept` | destructive | Fetch + ack the latest open handoff (auto-cwd-matched). |+| `memory_handoff_begin` | destructive | Open a handoff for the next agent. Optional `workspace` + `project` targets a named sibling workspace/project. |+| `memory_handoff_accept` | destructive | Fetch + ack the latest open handoff (auto-cwd-matched by default). Optional `workspace` + `project` targets a named sibling workspace/project. || `memory_handoff_cancel` | destructive | Mark an exact open handoff id expired when it was created by mistake. || `memory_consolidate` | destructive | LLM-driven page rewrite. `multi_page=true` for atomic fan-out. || `memory_write_page` | destructive | Write durable wiki knowledge when the user explicitly asks to remember/annotate something permanent. |