feat(loop): port run_loop.sh to Python lib_py.loop with thin wrapper and strict parser (Phase 3)

This commit is contained in:
Godopu committed 2026-09-07 09:04:49 +09:00
1 parent e1203166d9
commit 8cd256cc7a
8 files changed
+1275 -7

No files matched your search

@@ -104,6 +104,13 @@ if [ -n "${PLANNER_SESSION_OVERRIDE:-}" ] && [ "$PLAN_MODE" = false ]; then
exit 1
fi
# Anchor Python interpreter before freeze so freeze child processes find the project venv (O-4)
if [ -z "${AGENT_PYTHON_BIN:-}" ]; then
if [ -x "$REPO_ROOT/.venv/bin/python" ]; then
export AGENT_PYTHON_BIN="$REPO_ROOT/.venv/bin/python"
fi
fi
# --- B-13 Stage 2: freeze the runtime before the loop can be edited under us ---
# bash keeps reading a running script from disk by byte offset, so a worker that
# edits .agents/skills/ mid-loop can break this very file (measured: even a valid
@@ -199,6 +206,23 @@ if [ "$PLAN_TALK_TURNS" -gt 0 ] && [ "$PLAN_MODE" = false ]; then
log_warn "--plan-talk was specified but --plan mode is not enabled. Discussion turns will be ignored."
fi
# ===========================================================================
# Phase 3: Python lib_py.loop Thin Wrapper Delegation (MAM_LOOP_PY=1 default)
# Set MAM_LOOP_PY=0 to restore legacy shell loop execution.
# ===========================================================================
if [ "${MAM_LOOP_PY:-1}" = "1" ]; then
_py="${DELEGATE_JOB_PYTHON:-${AGENT_PYTHON_BIN:-$(_delegate_py_bin)}}"
export PYTHONPATH="$MAM_REAL_ROOT/.agents/skills:$REPO_ROOT/.agents/skills:${PYTHONPATH:-}"
export MAM_REAL_ROOT
export WORKSPACE_ROOT
export MAM_LOOP_MARKER
export MAM_LOOP_FREEZE_DIR
export MAM_LOOP_FREEZE_OWNED
export PYTHONDONTWRITEBYTECODE=1
[ -f "$MAM_REAL_ROOT/.mam.env" ] && export MAM_ENV_FILE="$MAM_REAL_ROOT/.mam.env"
exec "$_py" -m lib_py.loop ${MAM_LOOP_ARGV[@]+"${MAM_LOOP_ARGV[@]}"}
fi
# Verdict must occupy the report's last non-blank line — a standalone token
# quoted mid-report (e.g. as a formatting example) never matches (P0-2).
has_verdict() {