From 4cea11438a9a2e05e941b4ac7aa0ddc7228964be Mon Sep 17 00:00:00 2001 From: Godopu Date: Sun, 21 Jun 2026 06:24:31 +0000 Subject: [PATCH] refactor(lib.sh): extract hardcoded tmux shim paths to constants (FW-07) + cache _delegate_py_bin result (FW-08) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- skills/lib.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/skills/lib.sh b/skills/lib.sh index 76772e9..b56b404 100644 --- a/skills/lib.sh +++ b/skills/lib.sh @@ -26,15 +26,19 @@ LOCAL_BIN="${LOCAL_BIN:-$HOME/.local/bin}" # --------------------------------------------------------------------------- # 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}" _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" _REAL_TMUX_PATH="" IFS=: 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" break fi @@ -50,7 +54,7 @@ _resolve_real_tmux_path() { _init_tmux_isolation() { _resolve_real_tmux_path 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 mkdir -p "$wrapper_dir" cat < "$wrapper_dir/tmux" @@ -69,7 +73,7 @@ EOF local new_path="" dir save_ifs="$IFS" IFS=: 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 new_path="$dir" else @@ -419,15 +423,21 @@ PYEOF # _delegate_py_bin — echo the virtualenv python (walk up from skills/), else python3. _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 d="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" while [ "$d" != "/" ] && [ -n "$d" ]; do 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 d="$(dirname "$d")" done - printf '%s\n' "python3" + AGENT_PYTHON_BIN="$(command -v python3 || echo python3)" + printf '%s\n' "$AGENT_PYTHON_BIN" } # _delegate_script — echo the path to a tmux-agent-orchestrate-delegate-job script, resolved