#!/usr/bin/env bash # post_update.sh — multi-agent-mux-update phase 2 (Issue #72, decision 5). # post_update.sh --monitor <0|1> # # Run by install_phase.sh from the NEWLY installed tree, in its own process: # converts the registry with the new code's entry point (lib_py.registry_format, # #71) and starts the monitor again if it ran before the update. Exit 0, or # nonzero when the conversion or the monitor restart failed (the install is # kept either way: the registry converts again on its next write). set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" WS="$(cd -P "$SCRIPT_DIR/../../../.." && pwd -P)" export WORKSPACE_ROOT="$WS" export AGENT_SESSIONS_YAML="$WS/.mam/agent-sessions.yaml" # shellcheck source=../../lib.sh source "$WS/.agents/skills/lib.sh" MON=0 while [ $# -gt 0 ]; do case "$1" in --monitor) MON="$2"; shift 2 ;; *) echo "ERROR: unknown arg: $1" >&2; exit 2 ;; esac done rc=0 if [ ! -f "$AGENT_SESSIONS_YAML" ] && [ ! -f "$WS/.mam/agent-sessions.db" ]; then echo "registry: nothing to convert (no registry)" else "$(_delegate_py_bin)" -m lib_py.registry_format --yaml "$AGENT_SESSIONS_YAML" || rc=$? if [ "$rc" -ne 0 ]; then echo "ERROR: the registry was not converted (rc $rc); the install is kept and the next registry write converts it" >&2 fi fi if [ "$MON" = "1" ]; then if [ "${MAM_NO_SUBSCRIBER_DAEMON:-0}" = "1" ]; then echo "monitor: not restarted (MAM_NO_SUBSCRIBER_DAEMON=1)" elif pid="$(start_watchdog update "$WS")"; then echo "monitor: restarted (PID $pid)" else echo "ERROR: could not restart the monitor daemon" >&2 rc=1 fi fi exit "$rc"