From 82ab253f2c6b3cc31150e6a495ede32e939dbb0f Mon Sep 17 00:00:00 2001 From: kartik-mem0 Date: Thu, 21 May 2026 17:43:40 +0530 Subject: [PATCH] fix(mem0-plugin): sanitize marker path, add pre-compact REST backup, fix cross-tool gaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Sanitize project_id in onboard marker path (tr '/:' '--') to handle slashes from env var overrides - Fire on_pre_compact.py REST backup from PreCompact hook (was only called from Stop hooks — crash before Stop = data loss) - Source _identity.sh in on_stop_codex.sh and on_stop_cursor.sh so MEM0_PROJECT_ID + API key fallback are available - Note dream --schedule is Claude Code-only (Codex/Cursor lack schedule) --- mem0-plugin/scripts/on_pre_compact.sh | 7 +++++++ mem0-plugin/scripts/on_session_start.sh | 3 ++- mem0-plugin/scripts/on_stop_codex.sh | 2 ++ mem0-plugin/scripts/on_stop_cursor.sh | 2 ++ mem0-plugin/skills/mem0-onboard/SKILL.md | 3 ++- 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/mem0-plugin/scripts/on_pre_compact.sh b/mem0-plugin/scripts/on_pre_compact.sh index 3448cf5f4..28a1d86af 100755 --- a/mem0-plugin/scripts/on_pre_compact.sh +++ b/mem0-plugin/scripts/on_pre_compact.sh @@ -15,6 +15,13 @@ if [ -n "${MEM0_DEBUG:-}" ]; then mkdir -p "$HOME/.mem0" && exec 2>>"$HOME/.mem0/hooks.log" fi +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +INPUT=$(cat) + +# Fire REST API transcript backup in background (safety net if agent +# can't complete the add_memory call before compaction finishes) +echo "$INPUT" | python3 "$SCRIPT_DIR/on_pre_compact.py" --source=pre-compaction 2>/dev/null & + cat <<'EOF' ## CRITICAL: Pre-Compaction Session Summary diff --git a/mem0-plugin/scripts/on_session_start.sh b/mem0-plugin/scripts/on_session_start.sh index 74a5953d2..d9351c752 100755 --- a/mem0-plugin/scripts/on_session_start.sh +++ b/mem0-plugin/scripts/on_session_start.sh @@ -79,7 +79,8 @@ echo "" if [ "$SOURCE" = "startup" ]; then # First-run detection: auto-trigger onboarding for new projects - _ONBOARD_MARKER="$HOME/.mem0/.onboarded_${MEM0_PROJECT_ID}" + _SAFE_PID=$(printf '%s' "$MEM0_PROJECT_ID" | tr '/:' '--') + _ONBOARD_MARKER="$HOME/.mem0/.onboarded_${_SAFE_PID}" if [ ! -f "$_ONBOARD_MARKER" ]; then cat <<'EOF' ## Mem0 First Run — Automatic Onboarding diff --git a/mem0-plugin/scripts/on_stop_codex.sh b/mem0-plugin/scripts/on_stop_codex.sh index 983bac8de..16c5a023f 100755 --- a/mem0-plugin/scripts/on_stop_codex.sh +++ b/mem0-plugin/scripts/on_stop_codex.sh @@ -22,6 +22,8 @@ if [ -n "${MEM0_DEBUG:-}" ]; then fi SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +# shellcheck source=_identity.sh +. "$SCRIPT_DIR/_identity.sh" INPUT=$(cat) STOP_HOOK_ACTIVE=$(echo "$INPUT" | jq -r '.stop_hook_active // false' 2>/dev/null || echo "false") diff --git a/mem0-plugin/scripts/on_stop_cursor.sh b/mem0-plugin/scripts/on_stop_cursor.sh index 3e441c557..179d924ed 100755 --- a/mem0-plugin/scripts/on_stop_cursor.sh +++ b/mem0-plugin/scripts/on_stop_cursor.sh @@ -14,6 +14,8 @@ if [ -n "${MEM0_DEBUG:-}" ]; then fi SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +# shellcheck source=_identity.sh +. "$SCRIPT_DIR/_identity.sh" INPUT=$(cat) diff --git a/mem0-plugin/skills/mem0-onboard/SKILL.md b/mem0-plugin/skills/mem0-onboard/SKILL.md index e00b51f38..f5566630f 100644 --- a/mem0-plugin/skills/mem0-onboard/SKILL.md +++ b/mem0-plugin/skills/mem0-onboard/SKILL.md @@ -77,7 +77,8 @@ If the script reports an error, show the error message and suggest checking the Create a marker file so SessionStart won't re-trigger onboarding next session: ```bash -mkdir -p ~/.mem0 && touch ~/.mem0/.onboarded_ +_SAFE_PID=$(printf '%s' "" | tr '/:' '--') +mkdir -p ~/.mem0 && touch ~/.mem0/.onboarded_${_SAFE_PID} ``` This is silent — no user-facing output needed.