feat(ralph): rate limit budget tracking + whatsapp text-keywords
Task #1 — Rate limit budget tracking MVP: - tools/ralph_usage.py: pure functions (extract_usage_entry, parse_usage_jsonl, aggregate_by_day/_project, filter_by_days, summarize) + CLI append/summarize subcommands. Atomic write via temp+rename. - tools/ralph/ralph.sh: după fiecare claude -p, append usage entry derivat din JSON envelope la <project>/scripts/ralph/usage.jsonl. Best-effort, niciodată blochează rularea (|| true). - dashboard/handlers/ralph.py: GET /api/ralph/usage[?days=N] aggregează cross- project și returnează {today_cost, today_runs, by_project, by_day, ...}. Task #2 — WhatsApp text-keyword commands: - src/router.py: helper _translate_whatsapp_text mapează "aprob"/"stop <slug>"/ "stare [<slug>]" → /a, /k, /l. Apelat DOAR pe adapter whatsapp în _try_ralph_dispatch (Discord/TG nu sunt afectate). NU acoperim propose intentionat — descrierea liberă e prea fragilă pentru parsing text-only. Tests: 49 noi (test_ralph_usage 28 + test_whatsapp_keywords 21) + 4 noi în test_dashboard_ralph_endpoint pentru /api/ralph/usage. Toate trec; regression suite (test_router, test_router_planning, test_dashboard_ralph_endpoint, test_whatsapp) — 90/90 pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,21 @@ else
|
||||
DAG_HELPER=""
|
||||
fi
|
||||
|
||||
# Usage helper auto-detect (rate limit budget tracking — best effort, niciodată
|
||||
# blochează rularea Ralph dacă lipsește)
|
||||
if [ -n "$RALPH_USAGE_HELPER" ] && [ -f "$RALPH_USAGE_HELPER" ]; then
|
||||
USAGE_HELPER="$RALPH_USAGE_HELPER"
|
||||
elif [ -f "/home/moltbot/echo-core/tools/ralph_usage.py" ]; then
|
||||
USAGE_HELPER="/home/moltbot/echo-core/tools/ralph_usage.py"
|
||||
elif [ -f "/home/moltbot/echo-core-instr/tools/ralph_usage.py" ]; then
|
||||
USAGE_HELPER="/home/moltbot/echo-core-instr/tools/ralph_usage.py"
|
||||
elif [ -f "$SCRIPT_DIR/ralph_usage.py" ]; then
|
||||
USAGE_HELPER="$SCRIPT_DIR/ralph_usage.py"
|
||||
else
|
||||
USAGE_HELPER=""
|
||||
fi
|
||||
USAGE_FILE="$SCRIPT_DIR/usage.jsonl"
|
||||
|
||||
# Verifică că jq este instalat
|
||||
if ! command -v jq &> /dev/null; then
|
||||
echo "Eroare: jq nu este instalat. Rulează: apt install jq"
|
||||
@@ -292,6 +307,15 @@ EOF
|
||||
set -e
|
||||
OUTPUT=$(cat "$LOG_FILE")
|
||||
|
||||
# Rate limit budget tracking (best-effort, never blocks Ralph)
|
||||
if [ -n "$USAGE_HELPER" ]; then
|
||||
"$RALPH_PYTHON" "$USAGE_HELPER" append \
|
||||
"$USAGE_FILE" "$LOG_FILE" \
|
||||
--slug "$PROJECT_NAME" \
|
||||
--story-id "$CURRENT_STORY" \
|
||||
--iter "$i" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# W3: rate limit detection (max 1 retry per rulare)
|
||||
if is_rate_limited "$OUTPUT" || [ "$CLAUDE_EXIT" = "29" ]; then
|
||||
if [ "$RATE_LIMIT_RETRY_USED" = "0" ]; then
|
||||
|
||||
Reference in New Issue
Block a user