- Reset master to upstream/main (16,697 commits) - Overlay 2,271 local-only files (skills, tools, workspace, configs, apps) - Restore IDENTITY.md and USER.md templates - Build verified, gateway running, Discord working Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
68 lines
1.6 KiB
Bash
68 lines
1.6 KiB
Bash
#!/bin/bash
|
|
# JARVIS Smart Alert System
|
|
# Only alert if: (1) new issue OR (2) >1 hour since last alert
|
|
|
|
ALERT_STATE_DIR="/home/alex/clawd/.jarvis-state"
|
|
CRITICAL_LOG="/home/alex/clawd/logs/jarvis-critical.log"
|
|
PENDING_LOG="/home/alex/clawd/logs/jarvis-pending-tomorrow.log"
|
|
|
|
mkdir -p "$ALERT_STATE_DIR"
|
|
|
|
# Function to check if we've alerted about this in the last hour
|
|
should_alert() {
|
|
local issue_key="$1"
|
|
local state_file="$ALERT_STATE_DIR/${issue_key}.last-alert"
|
|
|
|
if [[ ! -f "$state_file" ]]; then
|
|
# Never alerted before
|
|
return 0
|
|
fi
|
|
|
|
local last_alert=$(cat "$state_file")
|
|
local now=$(date +%s)
|
|
local diff=$((now - last_alert))
|
|
|
|
# Alert if >1 hour (3600 seconds)
|
|
if [[ $diff -gt 3600 ]]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Function to record alert
|
|
record_alert() {
|
|
local issue_key="$1"
|
|
local state_file="$ALERT_STATE_DIR/${issue_key}.last-alert"
|
|
date +%s > "$state_file"
|
|
}
|
|
|
|
# Function to defer to tomorrow
|
|
defer_to_tomorrow() {
|
|
local issue="$1"
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] DEFERRED: $issue" >> "$PENDING_LOG"
|
|
}
|
|
|
|
# Main alert logic
|
|
alert_critical() {
|
|
local issue_key="$1"
|
|
local message="$2"
|
|
|
|
if should_alert "$issue_key"; then
|
|
# Alert now
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] CRITICAL: $message" | tee -a "$CRITICAL_LOG"
|
|
record_alert "$issue_key"
|
|
return 0
|
|
else
|
|
# Defer to tomorrow's summary
|
|
defer_to_tomorrow "$message"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Export functions for use in other scripts
|
|
export -f should_alert
|
|
export -f record_alert
|
|
export -f defer_to_tomorrow
|
|
export -f alert_critical
|