Files
meshcore-bot/scripts/post_tool_counter.sh
agessaman 0e1372e3d4 Enhance package data validation and error handling in scripts
- Added a trap command in `check-package-data.sh` to ensure cleanup of temporary files on exit.
- Improved error handling in `context_checkpoint.sh` for flushing pending bugs to `BUGS.md`, providing warnings if write operations fail.
- Implemented file locking in `post_tool_counter.sh` to ensure atomic increment of the tool counter, preventing race conditions.

These changes improve the reliability and robustness of package data checks and related scripts.
2026-04-02 10:57:58 -07:00

25 lines
710 B
Bash
Executable File

#!/usr/bin/env bash
# Post-tool counter: increments tool call count and runs checkpoint every 100 calls
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
COUNTER_FILE="/tmp/mc_tool_count"
# Increment counter (flock makes read-modify-write atomic)
LOCK_FILE="${COUNTER_FILE}.lock"
COUNT=$(
(
flock -x 9
C=$(cat "$COUNTER_FILE" 2>/dev/null || echo "0")
C=$((C + 1))
echo "$C" > "$COUNTER_FILE"
echo "$C"
) 9>"$LOCK_FILE"
)
# Every 100 tool calls, run checkpoint
if [ $((COUNT % 100)) -eq 0 ]; then
echo "post_tool_counter: $COUNT tool calls — running context checkpoint"
bash "$REPO_ROOT/scripts/context_checkpoint.sh"
fi