fix(missions): replace destructive token cleaner with actual token accountant
This commit is contained in:
@@ -170,6 +170,41 @@ REDIRECT
|
||||
# print_info "Patched $filename -> $shim_path"
|
||||
fi
|
||||
done
|
||||
|
||||
# 6b. Patch Token Check (Replace destructive cleaner with real counter)
|
||||
TOKEN_CHECK="$REPO_ROLES_DIR/../token_check.sh"
|
||||
if [ -f "$TOKEN_CHECK" ]; then
|
||||
cat << 'TOKEN' > "$TOKEN_CHECK"
|
||||
#!/bin/bash
|
||||
# Crumbforest Token Budget Checker
|
||||
# Sums up tokens from all log files
|
||||
|
||||
echo "📊 Crumbforest Token Budget"
|
||||
TRAFFIC=0
|
||||
|
||||
# Find logs (avoiding .bak and .cleaned)
|
||||
LOGS=$(find "$HOME" -name "token_log.json" -type f 2>/dev/null)
|
||||
|
||||
for f in $LOGS; do
|
||||
# Check if valid JSON content exists
|
||||
if [ -s "$f" ]; then
|
||||
# Try to sum total_tokens. Handle potential empty lines or []
|
||||
# We use inputs to handle stream of objects
|
||||
SUM=$(jq -n '[inputs | .usage.total_tokens // 0] | add' "$f" 2>/dev/null)
|
||||
if [ "$SUM" != "null" ] && [ "$SUM" != "" ] && [ "$SUM" != "0" ]; then
|
||||
echo " 📄 $(basename $(dirname "$f"))/$(basename "$f"): $SUM Krümel"
|
||||
TRAFFIC=$((TRAFFIC + SUM))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo "💰 Gesamtverbrauch: $TRAFFIC Krümel"
|
||||
TOKEN
|
||||
chmod +x "$TOKEN_CHECK"
|
||||
print_info "Patched token_check.sh with real accounting logic (non-destructive)."
|
||||
fi
|
||||
|
||||
print_info "Mission repo patched for server environment."
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user