Spaces:
Configuration error
Configuration error
Implement memory_antigravity_sync_all master sync tool
Browse filesFiles changed (7)
- AGENTS.md+2-1
- README.md+4-3
- plugin/.claude-plugin/plugin.json+1-1
- plugin/CLAUDE.mdAdded+143
- plugin/plugin.json+1-1
- src/app.py+46
- src/mcp_stdio.py+49
92 unmodified lines9394959697989917 unmodified lines11711811912012112292 unmodified lines## MCP ToolsThe server exposes 30 MCP tools via `GET /agentmemory/mcp/tools` (schema) and `POST /agentmemory/mcp/tools` (execution).| Tool | Description | Status ||------|-------------|--------|17 unmodified lines| `agent_observe` | Log agent execution observation | Working || `agent_remember` | Save agent memory to long-term | Working || `memory_antigravity_sync` | Sync Antigravity transcripts | Working || `memory_slot_list` | List all pinned memory slots | Working || `memory_slot_get` | Retrieve a specific pinned slot | Working || `memory_slot_create` | Create/overwrite pinned slot | Working |92 unmodified lines9394959697989917 unmodified lines11711811912012112212392 unmodified lines## MCP ToolsThe server exposes 31 MCP tools via `GET /agentmemory/mcp/tools` (schema) and `POST /agentmemory/mcp/tools` (execution).| Tool | Description | Status ||------|-------------|--------|17 unmodified lines| `agent_observe` | Log agent execution observation | Working || `agent_remember` | Save agent memory to long-term | Working || `memory_antigravity_sync` | Sync Antigravity transcripts | Working || `memory_antigravity_sync_all` | Master sync: transcript + crystallize + reflect | Working || `memory_slot_list` | List all pinned memory slots | Working || `memory_slot_get` | Retrieve a specific pinned slot | Working || `memory_slot_create` | Create/overwrite pinned slot | Working |
105 unmodified lines10610710810911011111258 unmodified lines17117217317417517617717 unmodified lines195196197198199200266 unmodified lines467468469470471472473105 unmodified lines|---------|--------|-------|| REST API — sessions, memories, observations | ✅ | Full surface || WebSocket live stream | ✅ | `/stream/mem-live/viewer` || MCP tools endpoint | ✅ | 30 tools || Built-in HTML viewer | ✅ | Real-time dashboard at `/viewer` || BM25 keyword search | ✅ | Always on, no API key needed || Hybrid BM25 + vector search | ✅ | Requires `GEMINI_API_KEY` |58 unmodified linesOpen the viewer at: http://localhost:3111/viewer```### Available MCP Tools (30)| Tool | Description ||------|-------------|17 unmodified lines| `agent_observe` | Log agent execution observation || `agent_remember` | Save agent memory to long-term storage || `memory_antigravity_sync` | Sync Antigravity transcripts to memory || `memory_slot_list` | List all pinned memory slots || `memory_slot_get` | Retrieve a specific pinned memory slot || `memory_slot_create` | Create/overwrite a pinned memory slot |266 unmodified lines| Storage | Dolt SQL (git-versioned MySQL) | SQLite WAL (single file) || Engine dependency | iii-engine (separate binary) | None — just Flask || Embeddings | 6 providers + local `@xenova/transformers` | Gemini 768-dim || MCP tools | 53 | 30 || REST endpoints | 128 | ~50 || Deploy | npm, Docker, fly.io, Railway, Render | Docker, HuggingFace Spaces || Cold boot | ~7s (iii engine warm-up) | <2s |105 unmodified lines10610710810911011111258 unmodified lines17117217317417517617717 unmodified lines195196197198199200201266 unmodified lines468469470471472473474105 unmodified lines|---------|--------|-------|| REST API — sessions, memories, observations | ✅ | Full surface || WebSocket live stream | ✅ | `/stream/mem-live/viewer` || MCP tools endpoint | ✅ | 31 tools || Built-in HTML viewer | ✅ | Real-time dashboard at `/viewer` || BM25 keyword search | ✅ | Always on, no API key needed || Hybrid BM25 + vector search | ✅ | Requires `GEMINI_API_KEY` |58 unmodified linesOpen the viewer at: http://localhost:3111/viewer```### Available MCP Tools (31)| Tool | Description ||------|-------------|17 unmodified lines| `agent_observe` | Log agent execution observation || `agent_remember` | Save agent memory to long-term storage || `memory_antigravity_sync` | Sync Antigravity transcripts to memory || `memory_antigravity_sync_all` | Master sync: transcript + crystallize + reflect || `memory_slot_list` | List all pinned memory slots || `memory_slot_get` | Retrieve a specific pinned memory slot || `memory_slot_create` | Create/overwrite a pinned memory slot |266 unmodified lines| Storage | Dolt SQL (git-versioned MySQL) | SQLite WAL (single file) || Engine dependency | iii-engine (separate binary) | None — just Flask || Embeddings | 6 providers + local `@xenova/transformers` | Gemini 768-dim || MCP tools | 53 | 31 || REST endpoints | 128 | ~50 || Deploy | npm, Docker, fly.io, Railway, Render | Docker, HuggingFace Spaces || Cold boot | ~7s (iii engine warm-up) | <2s |
1234567{"name": "agentmemory","version": "0.9.27","description": "Persistent memory for AI coding agents -- captures tool usage, compresses via LLM, injects context into future sessions. 12 hooks, 30 MCP tools, 16 skills, real-time viewer.","author": {"name": "Rohit Ghumare","url": "https://github.com/rohitg00"1234567{"name": "agentmemory","version": "0.9.27","description": "Persistent memory for AI coding agents -- captures tool usage, compresses via LLM, injects context into future sessions. 12 hooks, 31 MCP tools, 16 skills, real-time viewer.","author": {"name": "Rohit Ghumare","url": "https://github.com/rohitg00"
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143# Plugin Directory — CLAUDE.md
## What This Is
The `plugin/` directory contains all agent-facing integration artifacts for agentmemory-python: hook scripts, MCP configs, skills, and automation utilities.
## Directory Layout
```plugin/├── plugin.json Plugin manifest (name, version, hooks, skills, MCP)├── antigravity.md Antigravity-specific integration notes├── CLAUDE.md This file├── .claude-plugin/│ └── plugin.json Claude Code plugin config├── .codex-plugin/│ └── plugin.json Codex plugin config├── .mcp.json MCP server config (local)├── .mcp.copilot.json MCP server config (Copilot)├── hooks/│ ├── hooks.json Claude Code hooks config│ ├── hooks.codex.json Codex hooks config│ └── hooks.copilot.json Copilot hooks config├── scripts/ Python hook scripts (see below)└── skills/ Agent skill definitions```
## Hook Scripts (`plugin/scripts/`)
| Script | Hook Event | Purpose ||--------|-----------|---------|| `session_start.py` | `session_start` | Register new session, optionally inject context || `session_end.py` | `session_end` | Mark session complete, trigger consolidation || `prompt_submit.py` | `prompt_submit` | Log user prompt as observation || `pre_tool_use.py` | `PreToolUse` | Enrich file context before file tools (read/edit/write) || `post_tool_use.py` | `PostToolUse` | Log tool execution as observation || `post_tool_failure.py` | `PostToolUse` (failure) | Log failed tool calls || `pre_compact.py` | `PreCompact` | Sync memory before context compaction || `subagent_start.py` | `session_start` (SDK child) | Subagent session start || `subagent_stop.py` | `session_end` (SDK child) | Subagent session end || `stop.py` | `Stop` | Final cleanup on Claude exit || `task_completed.py` | `PostToolUse` (task done) | Log task completion || `notification.py` | Various | Desktop/push notifications on events |
### Automation Scripts (non-hook)
| Script | Purpose ||--------|---------|| `auto_session_start.py` | **Upsert session**: checks if session exists in agentmemory, updates if found, creates if not. Use as drop-in replacement for `session_start.py` when hooks don't fire. || `auto_log.py` | Log a single observation via MCP tools directly || `auto_log_prompt.py` | Log a user prompt via MCP tools directly || `mcp_stdio.py` | MCP stdio bridge — reads `AGENTMEMORY_URL` and `AGENTMEMORY_SECRET` from env || `simple_test_hook.py` | Debug utility — logs invocation to `~/.agentmemory/hook_test_log.txt` |
### Key shared utility: `hook_utils.py`
Provides:- `load_env()` — loads `~/.agentmemory/.env` at import time- `resolve_project(cwd)` — git root basename or cwd basename- `is_sdk_child(payload)` — detects SDK subagent invocations- `api_call(path, body, timeout)` — sync REST call to agentmemory- `api_call_bg(path, body)` — background thread REST call
## Environment Variables
All scripts read from environment (or `~/.agentmemory/.env`):
| Variable | Purpose ||----------|---------|| `AGENTMEMORY_URL` | Base URL of agentmemory server (default: `http://localhost:3111`) || `AGENTMEMORY_SECRET` | Bearer token for auth || `AGENTMEMORY_PROJECT` | Override project name (default: git root basename) || `AGENTMEMORY_SESSION_ID` | Override session ID || `AGENTMEMORY_CWD` | Override working directory || `AGENTMEMORY_INJECT_CONTEXT` | `true` to inject context into stdout on session start || `AGENTMEMORY_AGENT_ID` | Agent identifier (default: `claude-code`) || `CONSOLIDATION_ENABLED` | `true` to run consolidation on session end |
## Skills (`plugin/skills/`)
| Skill | Purpose ||-------|---------|| `agentmemory-agents` | How agents should interact with agentmemory || `agentmemory-architecture` | Architecture overview for agents || `agentmemory-config` | Configuration reference || `agentmemory-hooks` | Hooks system reference || `agentmemory-mcp-tools` | MCP tools reference (20 tools) || `agentmemory-rest-api` | REST API reference || `commit-context` | Save git commit context to memory || `commit-history` | Recall commit history from memory || `forget` | Delete observations/sessions/memories || `handoff` | Summarize session for handoff || `recall` | Search past observations || `recap` | Summarize current session || `remember` | Save insight to long-term memory || `session-history` | View session observation history || `write-agentmemory-skill` | Meta-skill: create new agentmemory skills |
## How Hooks Were Wired (History)
Originally hooks were registered in `~/.claude.json` under `"hooks"` key:
```json{ "hooks": { "session_start": { "command": "python", "args": ["...session_start.py"], "env": {...} }, "session_end": { "command": "python", "args": ["...session_end.py"], "env": {...} }, "prompt_submit": { "command": "python", "args": ["...prompt_submit.py"], "env": {...} } }}```
**Issue discovered (2026-06-10):** Claude Code hooks were not being invoked automatically. `prompt_submit` hook never fired — `~/.agentmemory/hook_log.txt` was never created. Hooks removed from config.
**Working alternative:** Use `auto_session_start.py` directly with env vars set. This uses the REST API + MCP tools to create/update sessions without relying on hooks.
## Auto-Session Upsert Logic (`auto_session_start.py`)
1. Calls `memory_sessions_list` MCP tool to get all sessions2. Searches for session matching `AGENTMEMORY_SESSION_ID`3. If found → logs "Session reactivated" observation via `agent_observe`4. If not found → calls `POST /session/start` REST endpoint to create new session5. Returns session info + context
## MCP Configuration
The `agentmemory-python` MCP is configured in `~/.claude.json`:
```json{ "agentmemory-python": { "type": "stdio", "command": "python", "args": ["D:\\Downloads\\Projects\\Other Projects\\agentmemory-python\\plugin\\scripts\\mcp_stdio.py"], "env": { "AGENTMEMORY_URL": "https://yash030-agentmemory-python.hf.space", "AGENTMEMORY_SECRET": "test" } }}```
`mcp_stdio.py` bridges Claude Code's MCP stdio protocol to the Flask HTTP API.1234567{"name": "agentmemory","version": "0.9.27","description": "Persistent memory for AI coding agents -- captures tool usage, compresses via LLM, injects context into future sessions. 12 hooks, 30 MCP tools, 16 skills, real-time viewer.","author": {"name": "Rohit Ghumare","url": "https://github.com/rohitg00"1234567{"name": "agentmemory","version": "0.9.27","description": "Persistent memory for AI coding agents -- captures tool usage, compresses via LLM, injects context into future sessions. 12 hooks, 31 MCP tools, 16 skills, real-time viewer.","author": {"name": "Rohit Ghumare","url": "https://github.com/rohitg00"
1998 unmodified lines199920002001200220032004304 unmodified lines2309231023112312231323141998 unmodified lines"required": ["mode"]}},{"name": "memory_slot_list","description": "List all pinned memory slots.",304 unmodified linesres = perform_antigravity_sync(mode, current_convo, current_folder)text_out = json.dumps(res)elif name == "memory_slot_list":res = functions.slot_list(kv)text_out = json.dumps(res, indent=2)1998 unmodified lines1999200020012002200320042005200620072008200920102011201220132014201520162017304 unmodified lines2322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923601998 unmodified lines"required": ["mode"]}},{"name": "memory_antigravity_sync_all","description": "Sync the current Antigravity session, automatically crystallize (summarize) it, and reflect to populate pinned memory slots in a single action.","inputSchema": {"type": "object","properties": {"mode": {"type": "string", "description": "Sync mode: current_session (default), current_folder, or all"},"currentConversationId": {"type": "string", "description": "Optional conversation ID of the current active session"},"currentFolder": {"type": "string", "description": "Optional current folder path to filter by"}},"required": ["mode"]}},{"name": "memory_slot_list","description": "List all pinned memory slots.",304 unmodified linesres = perform_antigravity_sync(mode, current_convo, current_folder)text_out = json.dumps(res)elif name == "memory_antigravity_sync_all":mode = args.get("mode") or "current_session"current_convo = args.get("currentConversationId")current_folder = args.get("currentFolder")sync_res = perform_antigravity_sync(mode, current_convo, current_folder)synced_sessions = sync_res.get("syncedSessions") or []crystallizations = {}reflections = {}for cid in synced_sessions:session_id = f"antigravity_{cid[:18].replace('-', '_')}"try:cres = functions.summarize(kv, {"sessionId": session_id})crystallizations[session_id] = cresexcept Exception as ex:crystallizations[session_id] = {"success": False, "error": str(ex)}try:rres = functions.slot_reflect(kv, session_id, 50)reflections[session_id] = rresexcept Exception as ex:reflections[session_id] = {"success": False, "error": str(ex)}text_out = json.dumps({"success": sync_res.get("success", True),"syncedSessions": synced_sessions,"observationsAdded": sync_res.get("observationsAdded", 0),"crystallizations": crystallizations,"reflections": reflections}, indent=2)elif name == "memory_slot_list":res = functions.slot_list(kv)text_out = json.dumps(res, indent=2)
264 unmodified lines26526626726826927030 unmodified lines301302303304305306264 unmodified lines})}]}def handle(req):method = req.get("method", "")req_id = req.get("id")30 unmodified linestry:if name == "memory_antigravity_sync":result = perform_antigravity_sync_local(args)else:r = requests.post(f"{BASE}/mcp/tools",headers=headers(),264 unmodified lines26526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631730 unmodified lines348349350351352353354355264 unmodified lines})}]}def perform_antigravity_sync_all_local(args):sync_res_outer = perform_antigravity_sync_local(args)try:sync_res = json.loads(sync_res_outer["content"][0]["text"])except Exception as ex:return sync_res_outerif not sync_res.get("success"):return sync_res_outersynced_sessions = sync_res.get("syncedSessions") or []crystallizations = {}reflections = {}headers_dict = headers()for cid in synced_sessions:session_id = f"antigravity_{cid[:18].replace('-', '_')}"try:r_sum = requests.post(f"{BASE}/summarize", headers=headers_dict, json={"sessionId": session_id}, timeout=30)if r_sum.status_code == 200:crystallizations[session_id] = r_sum.json()else:crystallizations[session_id] = {"success": False, "status_code": r_sum.status_code, "error": r_sum.text}except Exception as e:crystallizations[session_id] = {"success": False, "error": str(e)}try:r_ref = requests.post(f"{BASE}/slot/reflect", headers=headers_dict, json={"sessionId": session_id, "maxObservations": 50}, timeout=30)if r_ref.status_code == 200:reflections[session_id] = r_ref.json()else:reflections[session_id] = {"success": False, "status_code": r_ref.status_code, "error": r_ref.text}except Exception as e:reflections[session_id] = {"success": False, "error": str(e)}return {"content": [{"type": "text", "text": json.dumps({"success": True,"syncedSessions": synced_sessions,"observationsAdded": sync_res.get("observationsAdded", 0),"crystallizations": crystallizations,"reflections": reflections}, indent=2)}]}def handle(req):method = req.get("method", "")req_id = req.get("id")30 unmodified linestry:if name == "memory_antigravity_sync":result = perform_antigravity_sync_local(args)elif name == "memory_antigravity_sync_all":result = perform_antigravity_sync_all_local(args)else:r = requests.post(f"{BASE}/mcp/tools",headers=headers(),
AGENTS.md+2-1
README.md+4-3
plugin/.claude-plugin/plugin.json+1-1
plugin/CLAUDE.mdAdded+143
plugin/plugin.json+1-1
src/app.py+46
src/mcp_stdio.py+49