Skip to content
Open
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
29 changes: 29 additions & 0 deletions scripts/aea-monitor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ info() {
echo -e "${BLUE}[AEA Monitor]${NC} $1"
}

send_notification() {
local title="$1"
local message="$2"

# Optional: Send desktop notification if available
if command -v notify-send &> /dev/null; then
notify-send "$title" "$message" -i dialog-information -t 10000 2>/dev/null || true
fi
}

#===============================================================================
# PID Management
#===============================================================================
Expand Down Expand Up @@ -347,10 +357,29 @@ check_project_messages() {
echo "[$timestamp] Monitor found $unprocessed_count unprocessed messages" >> ".aea/agent.log"
fi

# Send desktop notification only if message count has increased
# Track notification state to avoid spam
local notif_state_file="$CONFIG_DIR/.notification_state_$(echo "$project_path" | md5sum | cut -d' ' -f1)"
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

The state file path construction is duplicated in two places (lines 362 and 381). Extract this to a local variable at the beginning of the function to avoid repetition and ensure consistency.

Suggested change
local notif_state_file="$CONFIG_DIR/.notification_state_$(echo "$project_path" | md5sum | cut -d' ' -f1)"
local notif_state_file
notif_state_file="$CONFIG_DIR/.notification_state_$(echo "$project_path" | md5sum | cut -d' ' -f1)"

Copilot uses AI. Check for mistakes.
local last_notified_count=0

if [ -f "$notif_state_file" ]; then
last_notified_count=$(cat "$notif_state_file" 2>/dev/null || echo 0)
Copy link

Copilot AI Oct 26, 2025

Choose a reason for hiding this comment

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

The fallback || echo 0 executes when cat fails (file doesn't exist), but also when the file exists and is empty or contains invalid data. This could lead to notifications being sent repeatedly if the state file is corrupted. Consider explicit validation of the file content or initialization with a default value.

Suggested change
last_notified_count=$(cat "$notif_state_file" 2>/dev/null || echo 0)
notif_content=$(cat "$notif_state_file" 2>/dev/null)
if [[ "$notif_content" =~ ^[0-9]+$ ]]; then
last_notified_count="$notif_content"
else
last_notified_count=0
fi

Copilot uses AI. Check for mistakes.
fi

# Only notify if message count increased (new messages arrived)
if [ "$unprocessed_count" -gt "$last_notified_count" ]; then
send_notification "AEA Monitor" "New messages in $project_name"
echo "$unprocessed_count" > "$notif_state_file"
fi

# TODO: In future, this would trigger Claude via API
# For now, just log that messages are waiting
warn "⏳ Messages waiting for Claude processing in $project_name"
warn " Run: cd $project_path && /aea"
else
# Clear notification state when all messages are processed
local notif_state_file="$CONFIG_DIR/.notification_state_$(echo "$project_path" | md5sum | cut -d' ' -f1)"
rm -f "$notif_state_file" 2>/dev/null
fi
}

Expand Down