**Ä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>
56 lines
1.9 KiB
Bash
Executable File
56 lines
1.9 KiB
Bash
Executable File
#!/bin/bash
|
||
QUESTION="$*"
|
||
MODEL="openai/gpt-3.5-turbo"
|
||
API_KEY="${OPENROUTER_API_KEY}"
|
||
|
||
LOGDIR="${CRUMB_LOGS_DIR:-$HOME/.bugsy_logs}/bugsy"
|
||
mkdir -p "$LOGDIR"
|
||
|
||
HISTORY_FILE="$LOGDIR/bugsy_history.json"
|
||
TMP_REQUEST="$LOGDIR/bugsy_request.json"
|
||
TMP_RESPONSE="$LOGDIR/bugsy_response.json"
|
||
LOG_FILE="$LOGDIR/token_log.json"
|
||
|
||
[ ! -f "$HISTORY_FILE" ] && echo "[]" > "$HISTORY_FILE"
|
||
[ ! -f "$LOG_FILE" ] && echo "[]" > "$LOG_FILE"
|
||
|
||
echo "🌍 Bugsy responds based on language of input: $QUESTION"
|
||
|
||
if [ -z "$API_KEY" ]; then
|
||
echo "❗ No API key set. Use: export OPENROUTER_API_KEY=..."
|
||
exit 1
|
||
fi
|
||
|
||
jq -n \
|
||
--arg model "$MODEL" \
|
||
--arg system_prompt "You are Bugsy – a friendly bug who helps children understand error messages in a simple, kind and encouraging way. You always respond in the language of the question." \
|
||
--arg user "$QUESTION" \
|
||
'{"model": $model, "temperature": 0.5, "messages": [{"role": "system", "content": $system_prompt}, {"role": "user", "content": $user}]}' > "$TMP_REQUEST"
|
||
|
||
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 "🚫 No response from model."
|
||
exit 1
|
||
else
|
||
echo -e "$RESPONSE_TEXT"
|
||
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" && \
|
||
cp "$LOGDIR/new_history.json" "$HISTORY_FILE" && rm "$LOGDIR/new_history.json"
|
||
fi
|
||
|
||
if jq -e '.usage' "$TMP_RESPONSE" > /dev/null; then
|
||
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
|
||
jq -n \
|
||
--arg zeit "$TIMESTAMP" \
|
||
--arg rolle "bugsy" \
|
||
--arg usage "$(jq -c '.usage' "$TMP_RESPONSE")" \
|
||
'{zeit: $zeit, rolle: $rolle, usage: $usage}' >> "$LOG_FILE"
|
||
fi
|