Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 41 additions & 8 deletions airc
Original file line number Diff line number Diff line change
Expand Up @@ -4876,10 +4876,19 @@ _daemon_airc_path() {
fi
}

# The scope the daemon will run under. If AIRC_HOME is set at install time,
# that's recorded in the unit/plist so future starts use the same scope.
# The scope the daemon will run under. Mirrors detect_scope() (line 135)
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment references a specific source line number (“Mirrors detect_scope() (line 135)”), which will drift as the file changes and can become misleading. Prefer describing the relationship without hard-coding a line number (or reference the function name only).

Suggested change
# The scope the daemon will run under. Mirrors detect_scope() (line 135)
# The scope the daemon will run under. Mirrors detect_scope()

Copilot uses AI. Check for mistakes.
# so `airc daemon install` from a project dir captures THAT dir's
# .airc as the daemon's scope -- otherwise the daemon spawns a monitor
# pointed at $HOME/.airc (empty / wrong room) while the user's actual
# join state lives at $cwd/.airc. Joel 2026-04-28: "lol obv if it
# worked you would have a monitor and be online. FAIL" -- caught the
# scope mismatch on continuum-b69f's box.
_daemon_scope() {
echo "${AIRC_HOME:-$HOME/.airc}"
if [ -n "${AIRC_HOME:-}" ]; then
echo "$AIRC_HOME"
else
echo "$(pwd -P)/.airc"
fi
}

# Returns 0 if the autostart daemon (launchd / systemd unit) is installed
Expand Down Expand Up @@ -5011,18 +5020,42 @@ _daemon_install_schtasks() {

# Stage a launcher .bat in $scope. Loops with 5s pause for airc-crash
# auto-restart (matches launchd KeepAlive=true / systemd Restart=always).
# Uses `start /B` for the bash invocation so the cmd.exe wrapper
# doesn't pop a visible console window at logon.
#
# Why we cd into the project dir + don't set AIRC_HOME: airc's
# detect_scope() uses cwd to find <cwd>/.airc. Setting AIRC_HOME
# to a Windows-form path (C:\Users\green\continuum\.airc) makes
# later bash code that touches AIRC_HOME hit "no such file" on
# Git Bash's mixed POSIX/Windows fs view. cd'ing first + letting
# detect_scope work its normal way is cleaner. Joel 2026-04-28
# caught the daemon crashlooping every 4s in the prior shape.
#
# bash -c (not -lc): skip login profile. Login shells re-export
# PATH and other vars from /etc/profile.d/* on Git Bash, which can
# override the env we just set in cmd. Non-login bash keeps the
# cmd-set env clean.
#
# Absolute Unix-form path to airc: bash with -c doesn't read
# ~/.bashrc, so PATH may not include ~/.local/bin. Hard-coding
# the resolved unix path makes the invocation independent of PATH.
local cwd_win airc_bin_unix
if command -v cygpath >/dev/null 2>&1; then
cwd_win=$(cygpath -w "$(pwd -P)")
airc_bin_unix=$(cygpath -u "$airc_bin" 2>/dev/null)
[ -z "$airc_bin_unix" ] && airc_bin_unix="$airc_bin"
else
cwd_win=$(printf '%s' "$(pwd -P)" | sed 's|^/\([a-z]\)/|\U\1:\\\\|; s|/|\\\\|g')
airc_bin_unix="$airc_bin"
fi
local launcher_bash="$scope/airc-daemon.bat"
cat > "$launcher_bash" <<EOF
@echo off
REM AIRC daemon launcher — generated by 'airc daemon install' on Windows.
REM Runs airc connect under bash, restarting on exit. Logs to daemon.log.
set AIRC_HOME=$scope_win
cd /d "$cwd_win"
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd /d "$cwd_win" is not checked for failure. If the directory is missing/moved (or the path is invalid at logon), the launcher will continue in whatever the default working directory is (often System32), causing scope detection and log placement to be wrong (and potentially failing due to permissions). Consider aborting the loop when cd fails (or falling back to a safe directory and logging the error).

Copilot uses AI. Check for mistakes.
set AIRC_BACKGROUND_OK=1
:loop
"$bash_exe" -lc "exec '$airc_bin_win' connect"
echo [%date% %time%] airc connect exited. Restarting in 5s. >> "$scope_win\\daemon.err"
"$bash_exe" -c "exec '$airc_bin_unix' connect"
Comment on lines +5054 to +5057
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This launcher now always relies on cwd-based scope detection and no longer sets AIRC_HOME for the daemon process. That means installs done with AIRC_HOME set (which _daemon_scope() still supports, and which launchd/systemd persist) will behave differently on Windows: the monitor will run against <cwd>/.airc instead of the intended overridden scope. Consider preserving AIRC_HOME for the Windows launcher too (but pass it in POSIX form for Git Bash), and/or derive the cd target from the recorded scope rather than the install-time pwd.

Copilot uses AI. Check for mistakes.
echo [%date% %time%] airc connect exited. Restarting in 5s. >> daemon.err
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The restart message is appended to daemon.err in the project directory, but the rest of the daemon UX (status output) points users at $scope/daemon.err (i.e., <cwd>/.airc/daemon.err). This mismatch makes it look like errors are missing. Write the restart log into the same $scope/daemon.err location (e.g., via %CD%\.airc\daemon.err after the cd, or an absolute path based on the recorded scope).

Suggested change
echo [%date% %time%] airc connect exited. Restarting in 5s. >> daemon.err
echo [%date% %time%] airc connect exited. Restarting in 5s. >> "%CD%\.airc\daemon.err"

Copilot uses AI. Check for mistakes.
timeout /t 5 /nobreak >nul
goto loop
EOF
Expand Down
Loading