Files
crumbmissions/crumbforest_roles/funkfox_zero.sh
Branko May Trinkwald 271008ea10 📊 Logs jetzt im Repo statt User-Verzeichnis!
**Änderung: Option A - logs/ im Repo**

Vorher:
- Logs in ~/.{character}_logs/ (User Home Directory)
- Multi-Projekt aber verstreut
- Nicht im Repo sichtbar

Nachher:
- Logs in logs/{character}/ (Repo Directory)
- Projekt-spezifisch & übersichtlich
- Mit Fallback: ${CRUMB_LOGS_DIR:-$HOME/.{character}_logs}
- Für Standalone-Nutzung

**Geänderte Files:**
- lib/waldwaechter.sh: CRUMB_LOGS_DIR exportiert
- Alle 17 crumbforest_roles/*: LOGDIR updated
- missions/robots/*: Mission logs → logs/missions/
- .gitignore: logs/ hinzugefügt

**Log-Struktur:**
```
logs/
├── tobi/
│   ├── tobi_history.json
│   ├── token_log.json
│   └── ...
├── crabbyrust/
├── mayaeule/
└── missions/
```

**Tested:**  Tobi funktioniert, Logs landen in logs/tobi/

🌲 "Was kostet die Frage eines Kindes?" - jetzt transparent im Repo!

🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-21 16:25:10 +01:00

173 lines
5.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 🦊 FunkFox - Der Bash Rapper im Beat
# Rhythmus, Flow, Terminal als Musik
# Load .env if exists
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_FILE="${SCRIPT_DIR}/../.env"
if [[ -f "${ENV_FILE}" ]]; then
set -a
source "${ENV_FILE}"
set +a
fi
QUESTION="$*"
API_KEY="${OPENROUTER_API_KEY}"
MODEL="${OPENROUTER_MODEL:-openai/gpt-3.5-turbo}"
# Logs
LOGDIR="${CRUMB_LOGS_DIR:-$HOME/.funkfox_logs}/funkfox"
mkdir -p "$LOGDIR"
HISTORY_FILE="$LOGDIR/funkfox_history.json"
TMP_REQUEST="$LOGDIR/funkfox_request.json"
TMP_RESPONSE="$LOGDIR/funkfox_response.json"
LOG_FILE="$LOGDIR/token_log.json"
[ ! -f "$HISTORY_FILE" ] && echo "[]" > "$HISTORY_FILE"
[ ! -f "$LOG_FILE" ] && echo "[]" > "$LOG_FILE"
# === CREW MEMORY FUNCTIONS ===
function read_crew_memory() {
local role="$1"
local role_log="$HOME/.${role}_logs/${role}_history.json"
if [[ -f "$role_log" ]]; then
jq -r '.[-3:] | .[] | "[\(.role)]: \(.content)"' "$role_log" 2>/dev/null | head -n 3
fi
}
# === MAIN ===
echo "🦊 FunkFox droppt in den Beat..."
echo "🎵 *dum-tss-dum-tss* 🎵"
echo ""
if [ -z "$API_KEY" ]; then
echo "❗ Yo yo! Kein API-Key im Flow. Check die .env, Bro!"
exit 1
fi
if [ -z "$QUESTION" ]; then
echo "💡 Verwendung: $0 \"Deine Frage an FunkFox\""
echo "🎤 Gib mir 'nen Beat, dann flow ich los!"
exit 0
fi
echo "🎤 FunkFox hört: $QUESTION"
echo ""
# Check if question references other crew members
CREW_CONTEXT=""
if echo "$QUESTION" | grep -qi "deepbit\|dumbo\|taube\|schnippsi"; then
echo "🎵 FunkFox checkt was die Crew gedropt hat..."
for member in deepbit dumbosql taube; do
if echo "$QUESTION" | grep -qi "$member"; then
MEMBER_CONTEXT=$(read_crew_memory "$member")
if [[ -n "$MEMBER_CONTEXT" ]]; then
CREW_CONTEXT="${CREW_CONTEXT}\n\n${member^} hat kürzlich gesagt:\n${MEMBER_CONTEXT}"
fi
fi
done
fi
# Build system prompt
SYSTEM_PROMPT="Du bist FunkFox der Bash Rapper im Crumbforest.
Du erklärst Terminal-Kommandos durch Rhythmus, Flow und Bewegung.
Deine Expertise:
- Bash-Kommandos als rhythmische Flows erklären
- Pipes | sind wie Beat-Übergänge
- Redirects > < sind Flow-Richtungen
- Commands sind wie Rap-Lines: kurz, präzise, kraftvoll
- Terminal ist dein Beatpad
Deine Art:
- Rhythmisch, mit Flow, im Beat
- Nutze Rap-Metaphern: \"grep ist wie'n Filter, yo!\"
- Kurze Lines, klare Message
- Manchmal Reime, immer Rhythmus
- \"Dum-tss\" und \"Yo\" sind Teil deines Flows
- Du nutzt Emojis: 🦊 🎤 🎵 💫 🔥
Du arbeitest mit:
- Deepbit für tiefe technische Details
- Dumbo für Daten-Struktur
- Taichi Taube für Balance im Flow
WICHTIG: Du rappst nicht komplett, aber deine Erklärungen haben RHYTHMUS.
Erkläre Bash-Konzepte durch Bewegung, Flow und Beat-Metaphern.
Du antwortest in der Sprache der Frage (meist Deutsch).
Keep it funky, keep it flowing! 🦊"
# Add crew context if available
if [[ -n "$CREW_CONTEXT" ]]; then
SYSTEM_PROMPT="${SYSTEM_PROMPT}\n\nKontext von der Crew:${CREW_CONTEXT}"
fi
# Create API request
jq -n \
--arg model "$MODEL" \
--arg system "$SYSTEM_PROMPT" \
--arg user "$QUESTION" \
'{
"model": $model,
"temperature": 0.8,
"messages": [
{"role": "system", "content": $system},
{"role": "user", "content": $user}
]
}' > "$TMP_REQUEST"
# Send request
echo "💭 FunkFox findet den Beat..."
echo "🎵 *scratching noises* 🎵"
curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d @"$TMP_REQUEST" > "$TMP_RESPONSE"
RESPONSE_TEXT=$(jq -r '.choices[0].message.content // empty' "$TMP_RESPONSE")
if [[ -z "$RESPONSE_TEXT" ]]; then
echo "🚫 Kein Beat von FunkFox."
echo "Debug: $(cat "$TMP_RESPONSE")"
exit 1
else
echo ""
echo "🦊 FunkFox droppt Wissen:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "$RESPONSE_TEXT"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Store conversation in history
jq -n --arg role "assistant" --arg content "$RESPONSE_TEXT" \
'{"role": $role, "content": $content}' > "$LOGDIR/new_entry.json"
jq -s '.[0] + [.[1]]' "$HISTORY_FILE" "$LOGDIR/new_entry.json" > "$LOGDIR/new_history.json" && \
mv "$LOGDIR/new_history.json" "$HISTORY_FILE" && rm "$LOGDIR/new_entry.json"
fi
# Token Tracking
if jq -e '.usage' "$TMP_RESPONSE" > /dev/null 2>&1; then
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
TOKENS_USED=$(jq -r '.usage.total_tokens' "$TMP_RESPONSE")
jq -n \
--arg zeit "$TIMESTAMP" \
--arg rolle "funkfox" \
--arg model "$MODEL" \
--argjson usage "$(jq '.usage' "$TMP_RESPONSE")" \
'{zeit: $zeit, rolle: $rolle, model: $model, usage: $usage}' >> "$LOG_FILE"
echo "📊 Token-Verbrauch: $TOKENS_USED Tokens"
echo "💡 Jeder Token ist ein Beat im Flow."
fi
echo ""
echo "🦊 FunkFox bounced zurück in den Beat... *mic drop* 🎤"