#!/usr/bin/env bash # multi-agent-mux-delegate-job β€” user-facing orchestrator for the multi-agent-mux-delegate-job skill. # # Subcommands: # submit register a job, start the subscriber FIRST, then run the agent, # then (optionally) run a validation script. # status show one job record. # list list all jobs. # verify run a user-supplied --validate script against a job's artifacts. # wait block until all running/pending jobs reach a terminal state. # # This is a reference wrapper: it shells out to the python scripts that live # next to it. Copy it into your project and customise as needed. It never hard # fails if `claude`/`codex`/`herdr` are missing β€” it prints what it would run. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Load local env file (.mam.env preferred, .env fallback) from workspace root or explicit MAM_ENV_FILE REPO_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" TARGET_ENV="${MAM_ENV_FILE:-}" if [[ -z "$TARGET_ENV" ]]; then if [[ -f "$REPO_ROOT/.mam.env" ]]; then TARGET_ENV="$REPO_ROOT/.mam.env" elif [[ -f "$REPO_ROOT/.env" ]]; then TARGET_ENV="$REPO_ROOT/.env" echo "WARNING: Loading deprecated config file '$TARGET_ENV'. Please migrate to '.mam.env'." >&2 elif [[ -f .mam.env ]]; then TARGET_ENV=".mam.env" echo "WARNING: Loading config from cwd relative path '$TARGET_ENV'." >&2 elif [[ -f .env ]]; then TARGET_ENV=".env" echo "WARNING: Loading deprecated config from cwd relative path '$TARGET_ENV'. Please migrate to '.mam.env'." >&2 fi fi if [[ -n "$TARGET_ENV" && -f "$TARGET_ENV" ]]; then set -a; source "$TARGET_ENV"; set +a fi # Source EARLY (before any herdr usage in run_agent) β€” this is what turns # plain `herdr` into the tmux-compat shim (herdr() function) and provides # resolve_herdr_workspace/send_keys_safe. Sourcing it late meant the # has-session pre-flight check below used to hit the real herdr binary with # a nonexistent subcommand and always fail. source "$SCRIPT_DIR/../lib.sh" # Pick an interpreter: prefer a project .venv, else python3. pick_python() { local py_bin if [[ -n "${DELEGATE_JOB_PYTHON:-}" ]]; then py_bin="$DELEGATE_JOB_PYTHON" elif [[ -n "${AGENT_PYTHON_BIN:-}" ]] && [[ -x "$AGENT_PYTHON_BIN" ]]; then py_bin="$AGENT_PYTHON_BIN" elif [[ -x "${WORKDIR:-.}/.venv/bin/python" ]]; then py_bin="${WORKDIR}/.venv/bin/python" elif [[ -x ".venv/bin/python" ]]; then py_bin="$(pwd)/.venv/bin/python" else py_bin="python3" fi if ! "$py_bin" -c "import paho.mqtt" 2>/dev/null; then echo "ERROR: paho-mqtt package is missing for $py_bin." >&2 echo " Please create a virtual environment and install it:" >&2 echo " python3 -m venv .venv && .venv/bin/pip install -r \"$SCRIPT_DIR/requirements.txt\"" >&2 exit 1 fi echo "$py_bin" } REGISTRY_DIR_DEFAULT=".mam/jobs" usage() { cat <<'EOF' multi-agent-mux-delegate-job [options] submit --agent --prompt [--workdir ] [--agent-session