From d2f2c382c2103e351b6ed644b6bcc36843eb0192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=97=D0=B0=D1=80=D1=83=D0=B1=D0=B8=D0=BD=20=D0=A4=D0=B8?= =?UTF-8?q?=D0=BB=D0=B8=D0=BF=D0=BF?= <289370046+zarubinphil@users.noreply.github.com> Date: Mon, 15 Jun 2026 20:33:28 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20Athena=20OS=20=E2=80=94=20launchd=20sta?= =?UTF-8?q?tus=3D127=20guard=20=D0=B2=20health-check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chk_launchd: для каждого user LaunchAgent проверяет, что бинари, вызванные голой командой (claude/chezmoi/node/yt-dlp/ffmpeg/whisper/python3), резолвятся под эффективным PATH агента (EnvironmentVariables.PATH ∪ login-shell -lc ∪ inline `export PATH=`). Ловит рекуррентный баг «бинарь не на PATH launchd» ДО того как агент молча сдохнет с exit 127 (3-й такой урок в lessons-log). Детектор: PlistBuddy (невэкранированный вывод вместо plutil-json, иначе \" ломает извлечение inline-PATH); тул = голая команда (граница пробел/;/&/|), абсолютные пути и подстроки в путях (.claude/, claude-telegram-bot) не флагуются. Живой аудит машины: 8/8 user-агентов ok (0 ложных, mnemosyne-health подтверждён после Ф3-фикса PATH). --- chezmoi/dot_claude/scripts/health-check.sh | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/chezmoi/dot_claude/scripts/health-check.sh b/chezmoi/dot_claude/scripts/health-check.sh index 81e160a..7e62918 100755 --- a/chezmoi/dot_claude/scripts/health-check.sh +++ b/chezmoi/dot_claude/scripts/health-check.sh @@ -6,6 +6,33 @@ LOG="$HOME/.claude/health.log" ts="$(date '+%Y-%m-%d %H:%M:%S')" issues=0 chk() { if eval "$2" >/dev/null 2>&1; then echo " ok $1"; else echo " !! $1"; issues=$((issues + 1)); fi; } +# Guard каждого user LaunchAgent против status=127 (бинарь не на PATH launchd). +# Эфф. PATH = EnvironmentVariables.PATH ∪ login-shell(-lc) ∪ inline `export PATH=` в команде. +chk_launchd() { + local dir="$HOME/Library/LaunchAgents" plist label args effpath inlinepath tool miss + [ -d "$dir" ] || { echo " ·· launchd: нет агентов (skip)"; return; } + for plist in "$dir"/*.plist; do + [ -e "$plist" ] || continue + label="$(basename "$plist" .plist)" + args="$(/usr/libexec/PlistBuddy -c 'Print :ProgramArguments' "$plist" 2>/dev/null)" || continue + [ -n "$args" ] || continue + effpath="$(plutil -extract EnvironmentVariables.PATH raw -o - "$plist" 2>/dev/null)" + if [ -z "$effpath" ] && printf '%s' "$args" | grep -q -- '-lc'; then + effpath="$(env -i HOME="$HOME" /bin/zsh -lc 'printf %s "$PATH"' 2>/dev/null)" + fi + inlinepath="$(printf '%s' "$args" | grep -oE 'export PATH="[^"]*"' | head -1 | sed -E 's/^export PATH="//; s/"$//')" + [ -n "$inlinepath" ] && effpath="$inlinepath:$effpath" + effpath="${effpath//\$HOME/$HOME}" + [ -n "$effpath" ] || effpath="/usr/bin:/bin" + miss="" + for tool in claude chezmoi node yt-dlp ffmpeg whisper python3; do + printf '%s' "$args" | grep -qE '(^|[[:space:];&|(])'"$tool"'([[:space:]]|$)' || continue + PATH="$effpath" command -v "$tool" >/dev/null 2>&1 || miss="$miss $tool" + done + if [ -n "$miss" ]; then echo " !! launchd $label:$miss не на PATH (status=127)"; issues=$((issues + 1)) + else echo " ok launchd $label"; fi + done +} { echo "── health $ts ──" chk "claude CLI" "command -v claude" @@ -15,6 +42,7 @@ chk() { if eval "$2" >/dev/null 2>&1; then echo " ok $1"; else echo " !! $1" chk "security-guard" "test -f \"$HOME/.claude/hooks/security-guard.sh\"" chk "rules/structure" "test -f \"$HOME/.claude/rules/structure.md\"" chk "registry" "test -d \"$HOME/.agents/registry\"" + chk_launchd echo " итог: $issues проблем(ы)" } >"$LOG" 2>&1 exit 0