claude-vault/scripts/detect-skill-proposals.sh
2026-02-04 22:35:40 +01:00

165 lines
4.6 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# Scannt Git-History und Memory-Logs nach wiederholten Aufgaben → Skill-Proposals
# Wird automatisch wöchentlich via Cron ausgeführt
set -e
VAULT="$HOME/Work/claude-vault"
PROPOSALS="$VAULT/skills/proposals"
THRESHOLD=3 # Mindestanzahl Wiederholungen für Proposal
echo "🔍 Scanne nach wiederholten Aufgaben..."
mkdir -p "$PROPOSALS"
# Temporäre Datei für Aufgaben-Tracking
TEMP_TASKS="/tmp/task-detection-$$.txt"
> "$TEMP_TASKS"
# 1. Analysiere Memory-Logs nach Beschreibungen
if [ -d "$VAULT/memory/log" ]; then
echo " 📝 Scanne Memory-Logs..."
find "$VAULT/memory/log" -name "*.md" -type f | while read log_file; do
# Extrahiere Beschreibungen aus Session-Logs
grep "^\*\*Beschreibung:\*\*" "$log_file" 2>/dev/null | \
sed 's/\*\*Beschreibung:\*\* //' | \
tr '[:upper:]' '[:lower:]' | \
sed 's/[[:punct:]]//g' >> "$TEMP_TASKS" || true
done
fi
# 2. Analysiere Git-Commit-Messages (falls Vault ein Git-Repo ist)
if [ -d "$VAULT/.git" ]; then
echo " 🔗 Scanne Git-Commits (letzte 30 Tage)..."
git -C "$VAULT" log --since="30 days ago" --pretty=format:"%s" 2>/dev/null | \
grep -iE '(add|create|implement|fix|update|improve)' | \
tr '[:upper:]' '[:lower:]' | \
sed 's/[[:punct:]]//g' >> "$TEMP_TASKS" || true
fi
# 3. Zähle Wiederholungen und erstelle Proposals
if [ -s "$TEMP_TASKS" ]; then
echo " 🎯 Analysiere Muster (Threshold: ${THRESHOLD}x)..."
# Finde Tasks die >= THRESHOLD mal vorkommen
sort "$TEMP_TASKS" | uniq -c | sort -rn | \
awk -v threshold="$THRESHOLD" '$1 >= threshold {$1=""; print $0}' | \
sed 's/^ *//' | \
while IFS= read -r task_pattern; do
# Skip wenn leer oder zu kurz
[ -z "$task_pattern" ] && continue
WORD_COUNT=$(echo "$task_pattern" | wc -w | xargs)
[ "$WORD_COUNT" -lt 2 ] && continue
# Generiere Skill-Namen aus Pattern
SKILL_NAME=$(echo "$task_pattern" | \
head -c 50 | \
tr ' ' '-' | \
tr -cd '[:alnum:]-' | \
sed 's/--*/-/g' | \
sed 's/^-//' | \
sed 's/-$//')
# Verhindere zu generische Namen
if echo "$SKILL_NAME" | grep -qE '^(add|create|fix|update|implement)$'; then
continue
fi
DATE=$(date +%Y-%m-%d)
PROPOSAL_FILE="$PROPOSALS/${DATE}_${SKILL_NAME}.md"
# Erstelle Proposal nur wenn noch nicht vorhanden
if [ ! -f "$PROPOSAL_FILE" ]; then
COUNT=$(grep -c "$task_pattern" "$TEMP_TASKS")
cat > "$PROPOSAL_FILE" <<EOF
---
status: proposed
created: $DATE
trigger: ${COUNT}x wiederholte Aufgabe
---
# Skill-Proposal: ${SKILL_NAME}
**Erstellt:** $DATE
**Trigger:** ${COUNT}x in letzten 30 Tagen erkannt
## Erkanntes Muster
**Wiederholte Aufgabe:**
> ${task_pattern}
**Häufigkeit:** ${COUNT}x
## Vorgeschlagener Skill
### Name
\`${SKILL_NAME}\`
### Beschreibung (TODO)
<!--
Beschreibe in max. 200 Zeichen was dieser Skill tut.
CRITICAL: Diese Beschreibung wird für Auto-Invocation genutzt.
-->
### Argument-Hint (TODO)
\`<required-arg> [optional-arg]\`
### Allowed-Tools (TODO)
\`Read, Write, Edit, Glob, Grep\`
## Implementation (TODO)
### Schritt 1: Template erstellen
<!-- Nutze skill-creator oder erstelle manuell -->
### Schritt 2: Prompt schreiben
<!-- Definiere was der Skill genau tut -->
### Schritt 3: Testen
<!-- Teste mit echtem Use-Case -->
### Schritt 4: Dokumentieren
<!-- Füge zu vault-index.md hinzu -->
## Entscheidung
- [ ] **Umsetzen** → Skill erstellen
- [ ] **Verwerfen** → Proposal löschen
- [ ] **Später** → In proposals/ belassen
## Notizen
<!-- Zusätzliche Gedanken/Kontext -->
EOF
echo " ✨ Neues Proposal erstellt: ${SKILL_NAME} (${COUNT}x erkannt)"
fi
done
# Zeige Zusammenfassung
TOTAL_PROPOSALS=$(find "$PROPOSALS" -name "*.md" -type f | wc -l | xargs)
NEW_PROPOSALS=$(find "$PROPOSALS" -name "${DATE}_*.md" -type f | wc -l | xargs)
echo ""
echo "✅ Skill-Detection abgeschlossen"
echo " - Neue Proposals: $NEW_PROPOSALS"
echo " - Gesamt offen: $TOTAL_PROPOSALS"
if [ "$NEW_PROPOSALS" -gt 0 ]; then
echo ""
echo "📋 Neue Proposals:"
find "$PROPOSALS" -name "${DATE}_*.md" -type f -exec basename {} .md \; | sed "s/^${DATE}_/ - /"
fi
else
echo " Keine wiederholten Aufgaben gefunden (keine Daten in Memory-Logs)"
fi
# Cleanup
rm -f "$TEMP_TASKS"
echo ""
echo "Tipp: Reviewe Proposals mit: vault-proposals"