Files
athena/chezmoi/dot_claude/scripts/health-check.sh
T
Зарубин Филипп d2f2c382c2 feat: Athena OS — launchd status=127 guard в health-check
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).
2026-06-15 20:33:28 +03:00

49 lines
2.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# Athena OS — health-check (launchd, daily). Целостность Мозга: бинари + канон-файлы.
# Лог: ~/.claude/health.log. Не чинит — только сигналит. Generic, без личных данных.
set -uo pipefail
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"
chk "chezmoi" "command -v chezmoi"
chk "CLAUDE.md канон" "test -f \"$HOME/.claude/CLAUDE.md\""
chk "settings.json" "test -f \"$HOME/.claude/settings.json\""
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