Files
mem0/mem0-plugin/scripts/on_git_commit_capture.sh
T
kartik-mem0 b49626ab11 fix(mem0-plugin): wire pre-commit capture hook, add Setup hook, fix access counters
- Add PreToolUse(Bash) hook: detects `git commit` commands, fires
  on_pre_commit.py in background to capture staged changes as memory
- Add Setup(init|maintenance) hook: installs mem0ai SDK on first plugin
  install via ensure_deps.sh (120s timeout for slow networks)
- Add on_git_commit_capture.sh wrapper: reads tool input JSON, matches
  git commit/merge/rebase, runs capture script fire-and-forget
- Fix #24: add metadata.last_accessed ISO timestamp to access counter
  instructions in mem0-mcp/SKILL.md alongside existing access_count
2026-05-21 23:02:32 +05:30

42 lines
894 B
Bash
Executable File

#!/usr/bin/env bash
# Hook: PreToolUse (matcher: Bash)
#
# Detects `git commit` commands and fires on_pre_commit.py in the background
# to capture staged changes as a mem0 memory. Never blocks the commit.
#
# Input: JSON on stdin with tool_name, tool_input
# Output: none (always exit 0)
set -euo pipefail
INPUT=$(cat)
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // ""' 2>/dev/null || echo "")
if [ -z "$COMMAND" ]; then
exit 0
fi
case "$COMMAND" in
*"git commit"*|*"git merge"*|*"git rebase"*)
;;
*)
exit 0
;;
esac
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
if [ ! -x "$SCRIPT_DIR/on_pre_commit.py" ] && [ ! -f "$SCRIPT_DIR/on_pre_commit.py" ]; then
exit 0
fi
API_KEY="${MEM0_API_KEY:-${CLAUDE_PLUGIN_OPTION_MEM0_API_KEY:-}}"
if [ -z "$API_KEY" ]; then
exit 0
fi
git diff --cached --stat 2>/dev/null | python3 "$SCRIPT_DIR/on_pre_commit.py" &
exit 0