fix(missions): write token accountant direct to /usr/local/bin with correct perms
This commit is contained in:
@@ -209,17 +209,43 @@ TOKEN
|
||||
fi
|
||||
|
||||
# 7. Global Dependencies (Token Check)
|
||||
# The "fat" roles rely on 'check_token_budget' being in the PATH.
|
||||
TOKEN_CHECK_SCRIPT="$ROLES_DIR/token_check.sh"
|
||||
# We generate the official "Accountant" script directly to /usr/local/bin
|
||||
TARGET_TOKEN_BIN="/usr/local/bin/check_token_budget"
|
||||
|
||||
if [ -f "$TOKEN_CHECK_SCRIPT" ]; then
|
||||
print_info "Installing global check_token_budget command..."
|
||||
# We copy it to /usr/local/bin/check_token_budget
|
||||
cp -f "$TOKEN_CHECK_SCRIPT" "$TARGET_TOKEN_BIN"
|
||||
chmod +x "$TARGET_TOKEN_BIN"
|
||||
print_info "Installed: $TARGET_TOKEN_BIN"
|
||||
fi
|
||||
print_info "Installing global check_token_budget command..."
|
||||
cat << 'TOKEN' > "$TARGET_TOKEN_BIN"
|
||||
#!/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)
|
||||
# We look in the current user's home
|
||||
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
|
||||
|
||||
# Ensure it is executable by EVERYONE (755)
|
||||
chmod 755 "$TARGET_TOKEN_BIN"
|
||||
chown root:root "$TARGET_TOKEN_BIN"
|
||||
print_info "Installed: $TARGET_TOKEN_BIN (Mode 755)"
|
||||
|
||||
# 8. Fix Mission Selector (Waldwaechter Patch)
|
||||
# The script lib/waldwaechter.sh has a bug with 'stat' on Debian, causing export errors.
|
||||
|
||||
Reference in New Issue
Block a user