fix(mem0-plugin): review fixes — loop guard, v3 response format, robustness

- on_stop_cursor.sh: add loop_count guard to prevent infinite re-entry
- on_stop.sh: drop set -e so stats failure doesn't kill the reminder
- _identity.py: fix fallback stub signatures to match production (accept cwd arg)
- on_pre_compact.py: add missing infer=False on session_state writes
- on_session_start.sh: handle v3 search response format (dict with results key)
- Align all plugin versions to 0.2.1 (Claude Code, Codex, Cursor)
This commit is contained in:
kartik-mem0
2026-05-21 18:27:47 +05:30
parent 470cef6ba6
commit 4b94902446
7 changed files with 24 additions and 11 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "mem0",
"version": "0.2.0",
"version": "0.2.1",
"description": "Mem0 memory layer for AI applications. Add persistent memory, personalization, and semantic search to Codex workflows using the Mem0 Platform MCP server.",
"author": {
"name": "Mem0",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "mem0",
"version": "0.2.0",
"version": "0.2.1",
"description": "Mem0 memory layer for AI applications. Add persistent memory, personalization, and semantic search using the Mem0 Platform MCP server.",
"author": {
"name": "Mem0",
+3 -3
View File
@@ -31,10 +31,10 @@ def resolve_user_id() -> str:
try:
from _project import resolve_branch, resolve_project_id, save_project_mapping
except ImportError:
def resolve_project_id() -> str:
return os.path.basename(os.getcwd())
def resolve_project_id(cwd: str | None = None) -> str:
return os.path.basename(cwd or os.getcwd())
def resolve_branch() -> str:
def resolve_branch(cwd: str | None = None) -> str:
return "unknown"
def save_project_mapping(cwd: str, project_id: str) -> None:
+1
View File
@@ -186,6 +186,7 @@ def store_memory(api_key: str, content: str, user_id: str, source: str, session_
"app_id": project_id,
"metadata": metadata,
"expiration_date": expires,
"infer": False,
}
data = json.dumps(body).encode("utf-8")
+8 -5
View File
@@ -53,12 +53,15 @@ req = urllib.request.Request(
)
try:
with urllib.request.urlopen(req, timeout=5) as r:
results = json.loads(r.read())
if isinstance(results, list):
n = len(results)
print(f'{n}+' if n >= 100 else str(n))
data = json.loads(r.read())
if isinstance(data, list):
results = data
elif isinstance(data, dict) and 'results' in data:
results = data['results']
else:
print('?')
print('?'); raise SystemExit
n = len(results)
print(f'{n}+' if n >= 100 else str(n))
except Exception:
print('?')
" 2>/dev/null || echo "?")
+2 -1
View File
@@ -10,7 +10,8 @@
#
# IMPORTANT: Check stop_hook_active to avoid infinite loops.
set -euo pipefail
# Intentionally omit -e so the reminder always emits even if session_stats fails.
set -uo pipefail
if [ -n "${MEM0_DEBUG:-}" ]; then
mkdir -p "$HOME/.mem0" && exec 2>>"$HOME/.mem0/hooks.log"
+8
View File
@@ -19,6 +19,14 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
INPUT=$(cat)
# Guard against infinite loops: if this is a re-entry after a prior followup,
# let the turn end. Cursor exposes loop_count in the input JSON.
LOOP_COUNT=$(echo "$INPUT" | jq -r '.loop_count // 0' 2>/dev/null || echo "0")
if [ "$LOOP_COUNT" -gt 1 ]; then
echo '{}'
exit 0
fi
# Session-end report (best-effort)
REPORT=$(python3 "$SCRIPT_DIR/session_stats.py" report 2>/dev/null || echo "")
REPORT_BLOCK=""