diff --git a/scripts/restart-mac.sh b/scripts/restart-mac.sh index d75aac24d..8187a9148 100755 --- a/scripts/restart-mac.sh +++ b/scripts/restart-mac.sh @@ -206,6 +206,31 @@ if [[ "$NO_SIGN" -ne 1 && -f "${LAUNCHAGENT_DISABLE_MARKER}" ]]; then run_step "clear launchagent disable marker" /bin/rm -f "${LAUNCHAGENT_DISABLE_MARKER}" fi +# When unsigned, ensure the gateway LaunchAgent targets the repo CLI (before the app launches). +# This reduces noisy "could not connect" errors during app startup. +if [ "$NO_SIGN" -eq 1 ]; then + run_step "install gateway launch agent (unsigned)" bash -lc "cd '${ROOT_DIR}' && node dist/entry.js daemon install --force --runtime node" + run_step "restart gateway daemon (unsigned)" bash -lc "cd '${ROOT_DIR}' && node dist/entry.js daemon restart" + if [[ "${GATEWAY_WAIT_SECONDS}" -gt 0 ]]; then + run_step "wait for gateway (unsigned)" sleep "${GATEWAY_WAIT_SECONDS}" + fi + GATEWAY_PORT="$( + node -e ' + const fs = require("node:fs"); + const path = require("node:path"); + try { + const raw = fs.readFileSync(path.join(process.env.HOME, ".clawdbot", "clawdbot.json"), "utf8"); + const cfg = JSON.parse(raw); + const port = cfg && cfg.gateway && typeof cfg.gateway.port === "number" ? cfg.gateway.port : 18789; + process.stdout.write(String(port)); + } catch { + process.stdout.write("18789"); + } + ' + )" + run_step "verify gateway port ${GATEWAY_PORT} (unsigned)" bash -lc "lsof -iTCP:${GATEWAY_PORT} -sTCP:LISTEN | head -n 5 || true" +fi + # 4) Launch the installed app in the foreground so the menu bar extra appears. # LaunchServices can inherit a huge environment from this shell (secrets, prompt vars, etc.). # That can cause launchd spawn failures and is undesirable for a GUI app anyway. @@ -226,13 +251,6 @@ else fail "App exited immediately. Check ${LOG_PATH} or Console.app (User Reports)." fi -# When unsigned, ensure the gateway LaunchAgent targets the repo CLI (after the app launches). if [ "$NO_SIGN" -eq 1 ]; then - run_step "install gateway launch agent (unsigned)" bash -lc "cd '${ROOT_DIR}' && node dist/entry.js daemon install --force --runtime node" - run_step "restart gateway daemon (unsigned)" bash -lc "cd '${ROOT_DIR}' && node dist/entry.js daemon restart" - if [[ "${GATEWAY_WAIT_SECONDS}" -gt 0 ]]; then - run_step "wait for gateway (unsigned)" sleep "${GATEWAY_WAIT_SECONDS}" - fi - run_step "verify gateway port 18789 (unsigned)" bash -lc "lsof -iTCP:18789 -sTCP:LISTEN | head -n 5 || true" run_step "show gateway launch agent args (unsigned)" bash -lc "/usr/bin/plutil -p '${HOME}/Library/LaunchAgents/com.clawdbot.gateway.plist' | head -n 40 || true" fi