refactor: use delegated python binary in script execution and update resolution logic to prioritize virtual environments

This commit is contained in:
2026-07-25 00:11:32 +09:00
parent c4839822ed
commit 520168ca55
+11 -3
View File
@@ -633,7 +633,9 @@ env_python() {
;;
esac
done
env "${envs[@]}" python3 - "$@"
local pybin
pybin="$(_delegate_py_bin)"
env "${envs[@]}" "$pybin" - "$@"
}
# ---------------------------------------------------------------------------
@@ -691,7 +693,9 @@ atomic_dump_yaml() {
esac
done
local mutation; mutation="$(cat)"
env "${envs[@]}" AGENT_SESSIONS_MUTATION="$mutation" python3 - <<'PYEOF'
local pybin
pybin="$(_delegate_py_bin)"
env "${envs[@]}" AGENT_SESSIONS_MUTATION="$mutation" "$pybin" - <<'PYEOF'
import os, sys, tempfile, shutil, glob, subprocess, json, sqlite3
from datetime import datetime, timezone
import yaml
@@ -1362,10 +1366,14 @@ PYEOF
# _delegate_py_bin — echo the virtualenv python (walk up from .agents/skills/), else python3.
_delegate_py_bin() {
# Return cached result if available (shell variable, not exported — avoids cross-workspace pollution)
# Return cached result if available
if [ -n "${AGENT_PYTHON_BIN:-}" ] && [ -x "$AGENT_PYTHON_BIN" ]; then
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
fi
if [ -n "${VIRTUAL_ENV:-}" ] && [ -x "$VIRTUAL_ENV/bin/python" ]; then
AGENT_PYTHON_BIN="$VIRTUAL_ENV/bin/python"
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
fi
local d
d="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
while [ "$d" != "/" ] && [ -n "$d" ]; do