refactor(lib.sh): extract hardcoded tmux shim paths to constants (FW-07) + cache _delegate_py_bin result (FW-08)
FW-07: _resolve_real_tmux_path and _init_tmux_isolation now use _TMUX_SHIM_DIR_PATTERN and _TMUX_SKILLS_BIN_PATTERN env-overridable constants instead of hardcoded path strings. All 4 reference sites updated (lines 32, 37, 57, 76). Default values preserve original slash semantics (/multi-agent-tmux-shim/, /skills/.bin). FW-08: _delegate_py_bin caches result in AGENT_PYTHON_BIN shell variable (not exported — avoids cross-workspace pollution). Fallback uses command -v python3 for absolute path caching. Reviewed by agy-existing (FAIL->fixed) and claude-existing (FAIL->fixed). Both reviewers identified: slash omission, incomplete extraction at :57/:76, export side effects. All issues resolved.
This commit is contained in:
+16
-6
@@ -26,15 +26,19 @@ LOCAL_BIN="${LOCAL_BIN:-$HOME/.local/bin}"
|
|||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Tmux Server Isolation support
|
# Tmux Server Isolation support
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
# Paths to exclude when resolving the real tmux binary (shim/wrapper dirs).
|
||||||
|
_TMUX_SHIM_DIR_PATTERN="${_TMUX_SHIM_DIR_PATTERN:-/multi-agent-tmux-shim/}"
|
||||||
|
_TMUX_SKILLS_BIN_PATTERN="${_TMUX_SKILLS_BIN_PATTERN:-/skills/.bin}"
|
||||||
|
|
||||||
TMUX_SERVER_NAME="${TMUX_SERVER_NAME:-default}"
|
TMUX_SERVER_NAME="${TMUX_SERVER_NAME:-default}"
|
||||||
|
|
||||||
_resolve_real_tmux_path() {
|
_resolve_real_tmux_path() {
|
||||||
if [ -z "${_REAL_TMUX_PATH:-}" ] || [[ "$_REAL_TMUX_PATH" == *"/multi-agent-tmux-shim/"* ]] || [[ "$_REAL_TMUX_PATH" == *"/skills/.bin"* ]]; then
|
if [ -z "${_REAL_TMUX_PATH:-}" ] || [[ "$_REAL_TMUX_PATH" == *"${_TMUX_SHIM_DIR_PATTERN}"* ]] || [[ "$_REAL_TMUX_PATH" == *"${_TMUX_SKILLS_BIN_PATTERN}"* ]]; then
|
||||||
local dir save_ifs="$IFS"
|
local dir save_ifs="$IFS"
|
||||||
_REAL_TMUX_PATH=""
|
_REAL_TMUX_PATH=""
|
||||||
IFS=:
|
IFS=:
|
||||||
for dir in $PATH; do
|
for dir in $PATH; do
|
||||||
if [[ "$dir" != *"/multi-agent-tmux-shim/"* ]] && [[ "$dir" != *"/skills/.bin"* ]] && [ -x "$dir/tmux" ]; then
|
if [[ "$dir" != *"${_TMUX_SHIM_DIR_PATTERN}"* ]] && [[ "$dir" != *"${_TMUX_SKILLS_BIN_PATTERN}"* ]] && [ -x "$dir/tmux" ]; then
|
||||||
_REAL_TMUX_PATH="$dir/tmux"
|
_REAL_TMUX_PATH="$dir/tmux"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
@@ -50,7 +54,7 @@ _resolve_real_tmux_path() {
|
|||||||
_init_tmux_isolation() {
|
_init_tmux_isolation() {
|
||||||
_resolve_real_tmux_path
|
_resolve_real_tmux_path
|
||||||
if [ -n "${TMUX_SERVER_NAME:-}" ] && [ "$TMUX_SERVER_NAME" != "default" ]; then
|
if [ -n "${TMUX_SERVER_NAME:-}" ] && [ "$TMUX_SERVER_NAME" != "default" ]; then
|
||||||
local wrapper_dir="${TMPDIR:-/tmp}/multi-agent-tmux-shim/${TMUX_SERVER_NAME}"
|
local wrapper_dir="${TMPDIR:-/tmp}${_TMUX_SHIM_DIR_PATTERN}${TMUX_SERVER_NAME}"
|
||||||
if [[ ":$PATH:" != *":$wrapper_dir:"* ]]; then
|
if [[ ":$PATH:" != *":$wrapper_dir:"* ]]; then
|
||||||
mkdir -p "$wrapper_dir"
|
mkdir -p "$wrapper_dir"
|
||||||
cat <<EOF > "$wrapper_dir/tmux"
|
cat <<EOF > "$wrapper_dir/tmux"
|
||||||
@@ -69,7 +73,7 @@ EOF
|
|||||||
local new_path="" dir save_ifs="$IFS"
|
local new_path="" dir save_ifs="$IFS"
|
||||||
IFS=:
|
IFS=:
|
||||||
for dir in $PATH; do
|
for dir in $PATH; do
|
||||||
if [[ "$dir" != *"/multi-agent-tmux-shim/"* ]] && [[ "$dir" != *"/skills/.bin"* ]]; then
|
if [[ "$dir" != *"${_TMUX_SHIM_DIR_PATTERN}"* ]] && [[ "$dir" != *"${_TMUX_SKILLS_BIN_PATTERN}"* ]]; then
|
||||||
if [ -z "$new_path" ]; then
|
if [ -z "$new_path" ]; then
|
||||||
new_path="$dir"
|
new_path="$dir"
|
||||||
else
|
else
|
||||||
@@ -419,15 +423,21 @@ PYEOF
|
|||||||
|
|
||||||
# _delegate_py_bin — echo the virtualenv python (walk up from skills/), else python3.
|
# _delegate_py_bin — echo the virtualenv python (walk up from skills/), else python3.
|
||||||
_delegate_py_bin() {
|
_delegate_py_bin() {
|
||||||
|
# Return cached result if available (shell variable, not exported — avoids cross-workspace pollution)
|
||||||
|
if [ -n "${AGENT_PYTHON_BIN:-}" ] && [ -x "$AGENT_PYTHON_BIN" ]; then
|
||||||
|
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
|
||||||
|
fi
|
||||||
local d
|
local d
|
||||||
d="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
d="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
while [ "$d" != "/" ] && [ -n "$d" ]; do
|
while [ "$d" != "/" ] && [ -n "$d" ]; do
|
||||||
if [ -x "$d/.venv/bin/python" ]; then
|
if [ -x "$d/.venv/bin/python" ]; then
|
||||||
printf '%s\n' "$d/.venv/bin/python"; return 0
|
AGENT_PYTHON_BIN="$d/.venv/bin/python"
|
||||||
|
printf '%s\n' "$AGENT_PYTHON_BIN"; return 0
|
||||||
fi
|
fi
|
||||||
d="$(dirname "$d")"
|
d="$(dirname "$d")"
|
||||||
done
|
done
|
||||||
printf '%s\n' "python3"
|
AGENT_PYTHON_BIN="$(command -v python3 || echo python3)"
|
||||||
|
printf '%s\n' "$AGENT_PYTHON_BIN"
|
||||||
}
|
}
|
||||||
|
|
||||||
# _delegate_script <name> — echo the path to a tmux-agent-orchestrate-delegate-job script, resolved
|
# _delegate_script <name> — echo the path to a tmux-agent-orchestrate-delegate-job script, resolved
|
||||||
|
|||||||
Reference in New Issue
Block a user