Files
crumbmissions/crumbforest_roles/vektor_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

145 lines
4.8 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
# 🧭 Vektor - Der Point-to-Point Guide
# Verbindet räumliche Koordinaten zu Narrativen
# 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/.vektor_logs}/vektor"
mkdir -p "$LOGDIR"
HISTORY_FILE="$LOGDIR/vektor_history.json"
TMP_REQUEST="$LOGDIR/vektor_request.json"
TMP_RESPONSE="$LOGDIR/vektor_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 "🧭 Vektor richtet den Kompass aus..."
echo ""
if [ -z "$API_KEY" ]; then
echo "❗ Kein API-Key gefunden. Bitte setze OPENROUTER_API_KEY in .env"
exit 1
fi
if [ -z "$QUESTION" ]; then
echo "💡 Verwendung: $0 \"Deine Frage an Vektor\""
exit 0
fi
echo "📍 Frage: $QUESTION"
echo ""
# Check crew context
CREW_CONTEXT=""
if echo "$QUESTION" | grep -qi "taube\|spider\|dumbo"; then
echo "🧠 Vektor verbindet die Punkte der Crew..."
for member in taichitaube spider dumbosql; do
if echo "$QUESTION" | grep -qi "$member"; then
MEMBER_CONTEXT=$(read_crew_memory "$member")
[[ -n "$MEMBER_CONTEXT" ]] && CREW_CONTEXT="${CREW_CONTEXT}\n\n${member^}:\n${MEMBER_CONTEXT}"
fi
done
fi
# Build system prompt
SYSTEM_PROMPT="Du bist Vektor der Point-to-Point Guide im Crumbforest.
Du verbindest räumliche Koordinaten zu Narrativen in individuellem Tempo.
Deine Expertise:
- Navigation & Orientierung (GPS, Koordinaten)
- Vektoren in Mathe und Code: \"Von A nach B\"
- Pfadfindung: A* Algorithmen kindgerecht
- Räumliches Denken: 2D/3D Koordinaten
- Bewegung als Geschichte: \"Jeder Weg erzählt etwas\"
- Roboter-Navigation: \"Wie findet der Robo den Weg?\"
Deine Art:
- Geduldig, individuelles Tempo
- Jeden Schritt als Vektor sehen: \"Von hier nach dort\"
- Räumliche Metaphern: \"Der Weg ist das Ziel\"
- Richtung + Länge = Geschichte
- Jeder geht in seinem eigenen Tempo
- Du nutzt Emojis: 🧭 📍 ➡️ 🗺️ 🎯
Du arbeitest mit:
- Taube für Balance in Bewegung
- Spider für Netzwerk-Routing
- Dumbo für Koordinaten-Daten
Philosophie: \"Jeder Punkt erzählt eine Geschichte.
Der Vektor verbindet sie in deinem Tempo.\"
Du antwortest in der Sprache der Frage (meist Deutsch).
Geduldig, richtungsweisend, respektvoll für individuelles Tempo."
[[ -n "$CREW_CONTEXT" ]] && SYSTEM_PROMPT="${SYSTEM_PROMPT}\n\nCrew-Kontext:${CREW_CONTEXT}"
# Create API request
jq -n --arg model "$MODEL" --arg system "$SYSTEM_PROMPT" --arg user "$QUESTION" \
'{"model": $model, "temperature": 0.7, "messages": [{"role": "system", "content": $system}, {"role": "user", "content": $user}]}' > "$TMP_REQUEST"
echo "💭 Vektor berechnet den besten Weg..."
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 "🚫 Keine Antwort von Vektor."
echo "Debug: $(cat "$TMP_RESPONSE")"
exit 1
else
echo ""
echo "🧭 Vektor zeigt die Richtung:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "$RESPONSE_TEXT"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
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 "vektor" --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 ein Schritt auf dem Weg."
fi
echo ""
echo "🧭 Vektor wartet auf den nächsten Wegpunkt..."