-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaude-pet
More file actions
executable file
·54 lines (50 loc) · 2.78 KB
/
Copy pathclaude-pet
File metadata and controls
executable file
·54 lines (50 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
# Entry point for claude-pet. Safe to call by absolute path from Claude hooks.
set -euo pipefail
HERE="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
export PYTHONPATH="${HERE}${PYTHONPATH:+:${PYTHONPATH}}"
# `python3 -m` puts the working directory first on sys.path, so running this
# launcher from inside *another* claude-pet checkout would import that copy
# instead of this one. Ignored before Python 3.11, which is harmless.
export PYTHONSAFEPATH=1
# GTK must pick its backend before Python starts. Only X11/XWayland honours
# _NET_WM_STATE_ABOVE under mutter, which is what keeps the pet on top.
export GDK_BACKEND="${CLAUDE_PET_GDK_BACKEND:-x11}"
# PyGObject is installed by the system package manager, into the *system*
# Python's dist-packages and nowhere else. So `python3` being first on PATH is
# not enough: for anyone whose shell resolves it to pyenv, conda, asdf or an
# active virtualenv, apt has installed a PyGObject that interpreter cannot see,
# and the pet dies on `import gi` having looked correctly installed all along.
#
# Only commands that need the GUI libraries pay for the probe. `hook` runs
# inside every turn of every agent and has no use for them.
#
# `doctor` and `setup` are in the list because they import Pillow and GTK to
# check them, and a diagnostic that dies of the very fault it exists to report
# is worse than no diagnostic at all.
case "${1:-}" in
run|start|restart|demo|snapshot|preview|doctor|setup)
for candidate in "${CLAUDE_PET_PYTHON:-}" python3 /usr/bin/python3; do
[ -n "$candidate" ] || continue
command -v "$candidate" >/dev/null 2>&1 || continue
if "$candidate" -c 'import gi' >/dev/null 2>&1; then
exec "$candidate" -m claude_pet "$@"
fi
done
# Nothing on this machine can import it, which is a missing package
# rather than a broken install -- so say which one, instead of letting
# a bare ModuleNotFoundError stand in for the explanation.
echo "claude-pet: PyGObject (the 'gi' module) is not available to any python3 here." >&2
echo " Debian/Ubuntu: sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0" >&2
echo " Fedora: sudo dnf install python3-gobject gtk3" >&2
echo " Arch: sudo pacman -S python-gobject gtk3" >&2
echo " openSUSE: sudo zypper install python3-gobject gtk3" >&2
echo >&2
echo " Already installed? Your python3 is probably a virtualenv, pyenv or" >&2
echo " conda one, which cannot see packages installed system-wide. Point" >&2
echo " claude-pet at the system interpreter:" >&2
echo " CLAUDE_PET_PYTHON=/usr/bin/python3 claude-pet $1" >&2
exit 1
;;
esac
exec python3 -m claude_pet "$@"