From 573354f5e44bf952260691cf6a0ad91ef1b3deb1 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 22 Jan 2026 07:41:47 +0000 Subject: [PATCH] chore(dev): default restart-mac to attach-only --- scripts/restart-mac.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/scripts/restart-mac.sh b/scripts/restart-mac.sh index 8187a9148..8cda970d8 100755 --- a/scripts/restart-mac.sh +++ b/scripts/restart-mac.sh @@ -20,6 +20,7 @@ SIGN=0 AUTO_DETECT_SIGNING=1 GATEWAY_WAIT_SECONDS="${CLAWDBOT_GATEWAY_WAIT_SECONDS:-0}" LAUNCHAGENT_DISABLE_MARKER="${HOME}/.clawdbot/disable-launchagent" +ATTACH_ONLY=1 log() { printf '%s\n' "$*"; } fail() { printf 'ERROR: %s\n' "$*" >&2; exit 1; } @@ -81,11 +82,15 @@ for arg in "$@"; do --wait|-w) WAIT_FOR_LOCK=1 ;; --no-sign) NO_SIGN=1; AUTO_DETECT_SIGNING=0 ;; --sign) SIGN=1; AUTO_DETECT_SIGNING=0 ;; + --attach-only) ATTACH_ONLY=1 ;; + --no-attach-only) ATTACH_ONLY=0 ;; --help|-h) - log "Usage: $(basename "$0") [--wait] [--no-sign] [--sign]" + log "Usage: $(basename "$0") [--wait] [--no-sign] [--sign] [--attach-only|--no-attach-only]" log " --wait Wait for other restart to complete instead of exiting" log " --no-sign Force no code signing (fastest for development)" log " --sign Force code signing (will fail if no signing key available)" + log " --attach-only Launch app with --attach-only (skip launchd install)" + log " --no-attach-only Launch app without attach-only override" log "" log "Env:" log " CLAWDBOT_GATEWAY_WAIT_SECONDS=0 Wait time before gateway port check (unsigned only)" @@ -115,6 +120,9 @@ log "==> Log: ${LOG_PATH}" if [[ "$NO_SIGN" -eq 1 ]]; then log "==> Using --no-sign (unsigned flow enabled)" fi +if [[ "$ATTACH_ONLY" -eq 1 ]]; then + log "==> Using --attach-only (skip launchd install)" +fi acquire_lock @@ -202,13 +210,13 @@ choose_app_bundle() { choose_app_bundle # When signed, clear any previous launchagent override marker. -if [[ "$NO_SIGN" -ne 1 && -f "${LAUNCHAGENT_DISABLE_MARKER}" ]]; then +if [[ "$NO_SIGN" -ne 1 && "$ATTACH_ONLY" -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 +if [ "$NO_SIGN" -eq 1 ] && [ "$ATTACH_ONLY" -ne 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 @@ -231,6 +239,11 @@ if [ "$NO_SIGN" -eq 1 ]; then run_step "verify gateway port ${GATEWAY_PORT} (unsigned)" bash -lc "lsof -iTCP:${GATEWAY_PORT} -sTCP:LISTEN | head -n 5 || true" fi +ATTACH_ONLY_ARGS=() +if [[ "$ATTACH_ONLY" -eq 1 ]]; then + ATTACH_ONLY_ARGS+=(--args --attach-only) +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. @@ -241,7 +254,7 @@ run_step "launch app" env -i \ TMPDIR="${TMPDIR:-/tmp}" \ PATH="/usr/bin:/bin:/usr/sbin:/sbin" \ LANG="${LANG:-en_US.UTF-8}" \ - /usr/bin/open "${APP_BUNDLE}" + /usr/bin/open "${APP_BUNDLE}" ${ATTACH_ONLY_ARGS[@]:+"${ATTACH_ONLY_ARGS[@]}"} # 5) Verify the app is alive. sleep 1.5 @@ -251,6 +264,6 @@ else fail "App exited immediately. Check ${LOG_PATH} or Console.app (User Reports)." fi -if [ "$NO_SIGN" -eq 1 ]; then +if [ "$NO_SIGN" -eq 1 ] && [ "$ATTACH_ONLY" -ne 1 ]; then 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