SessionStart failed with 'pyenv: mem0-agent: command not found' in any repo whose
.python-version selects a Python the console script was not installed into. A
pip entry point is the wrong dependency for a plugin.
- bin/mem0-agent: POSIX launcher that picks the first CPython >= 3.10 it can find
and runs the package from source (there are no third-party dependencies)
- hooks now invoke ${CLAUDE_PLUGIN_ROOT}/bin/mem0-agent, matching how the v1
plugin calls its own scripts; the generator enforces this
- app_id override renamed to MEM0_AGENT_APP_ID: v1 exports MEM0_PROJECT_ID, which
was silently overriding this plugin's project scope while both are installed
Verified: all six hooks exit 0 from a pyenv-3.11 repo, and app_id resolves per
repository again.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
61 lines
1.7 KiB
Bash
Executable File
61 lines
1.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Self-contained launcher. Hooks invoke this via ${CLAUDE_PLUGIN_ROOT}/bin/mem0-agent so
|
|
# the plugin never depends on a globally-installed console script.
|
|
#
|
|
# A pip-installed entry point is not dependable here: under pyenv the shim resolves against
|
|
# whichever Python version the current directory selects, so a repo with a .python-version
|
|
# pinning a different version fails with "pyenv: mem0-agent: command not found".
|
|
#
|
|
# The package has no third-party dependencies, so any CPython >= 3.10 can run it straight
|
|
# from source.
|
|
|
|
set -eu
|
|
|
|
PLUGIN_ROOT="$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)"
|
|
SRC="$PLUGIN_ROOT/src"
|
|
|
|
if [ ! -d "$SRC/mem0_agent" ]; then
|
|
echo "mem0-agent: package not found at $SRC" >&2
|
|
exit 0 # never break a hook
|
|
fi
|
|
|
|
# Does this interpreter exist and satisfy the minimum version?
|
|
usable() {
|
|
[ -n "${1:-}" ] || return 1
|
|
command -v "$1" >/dev/null 2>&1 || return 1
|
|
"$1" -c 'import sys; sys.exit(0 if sys.version_info >= (3, 10) else 1)' >/dev/null 2>&1
|
|
}
|
|
|
|
PY=""
|
|
for candidate in \
|
|
"${MEM0_AGENT_PYTHON:-}" \
|
|
python3 \
|
|
/opt/homebrew/bin/python3 \
|
|
/usr/local/bin/python3 \
|
|
/usr/bin/python3
|
|
do
|
|
if usable "$candidate"; then
|
|
PY="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$PY" ]; then
|
|
# Last resort: any pyenv version that is new enough.
|
|
for candidate in "$HOME"/.pyenv/versions/3.1[0-9]*/bin/python3; do
|
|
if usable "$candidate"; then
|
|
PY="$candidate"
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ -z "$PY" ]; then
|
|
echo "mem0-agent: no Python >= 3.10 found; set MEM0_AGENT_PYTHON" >&2
|
|
exit 0 # never break a hook
|
|
fi
|
|
|
|
PYTHONPATH="$SRC${PYTHONPATH:+:$PYTHONPATH}"
|
|
export PYTHONPATH
|
|
exec "$PY" -m mem0_agent.cli "$@"
|