rd13_copilot_setup/git-templates/hooks/post-commit
Conrad Schulz bc23bd7f92 feat: post-commit hängt git-block an session-datei an
- Hook erkennt *_session.md Dateien (vom Agent via /history erstellt)
- Modus A: Git-Block an bestehende Konversations-Datei anhängen
- Modus B: Nur Git-Stub wenn kein Agent-Log vorhanden (Hinweis ausgeben)
- history.prompt.md: Dateinamen-Konvention _session.md dokumentiert
2026-06-02 09:26:32 +00:00

87 lines
2.5 KiB
Bash
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.

#!/usr/bin/env sh
# post-commit Automatischer History-Log
#
# Läuft nach jedem erfolgreichen Commit.
# Zwei Modi:
#
# A) Session-Datei gefunden (Agent hat /history ausgeführt):
# → Git-Block wird an die bestehende Konversations-Datei ANGEHÄNGT.
# Session-Dateien werden vom Agent mit dem Suffix "_session.md" erstellt.
#
# B) Keine Session-Datei für heute:
# → Neuer Git-Stub (nur Metadaten, kein KI-Inhalt).
#
# Die Datei wird NICHT automatisch committed (kein Rekursionsrisiko).
# Sie wird beim nächsten regulären Commit mit erfasst (history/ ist tracked).
HASH=$(git rev-parse --short HEAD 2>/dev/null)
FULL_HASH=$(git rev-parse HEAD 2>/dev/null)
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
DATE=$(date '+%Y-%m-%d')
DATETIME=$(date '+%Y-%m-%d %H:%M:%S')
MSG=$(git log -1 --format='%s' 2>/dev/null)
AUTHOR=$(git log -1 --format='%an <%ae>' 2>/dev/null)
# Nur ausführen wenn history/prompts/ existiert
if [ ! -d "history/prompts" ]; then
exit 0
fi
# Geänderte Dateien dieses Commits
CHANGED_FILES=$(git diff-tree --no-commit-id -r --name-status "$FULL_HASH" 2>/dev/null \
| awk '{printf "| %-1s | %s |\n", $1, $2}')
GIT_BLOCK=$(cat << EOF
---
## Git Commit
| Feld | Wert |
|---|---|
| Datum | $DATETIME |
| Branch | \`$BRANCH\` |
| Commit | \`$FULL_HASH\` |
| Autor | $AUTHOR |
### Commit Message
\`\`\`
$MSG
\`\`\`
### Geänderte Dateien
| Status | Datei |
|---|---|
$CHANGED_FILES
---
*Git-Block automatisch generiert durch post-commit hook.*
EOF
)
# Modus A: Session-Datei vom Agent für heute suchen (Suffix: _session.md)
SESSION_FILE=$(ls "history/prompts/${DATE}_"*"_session.md" 2>/dev/null | tail -1)
if [ -n "$SESSION_FILE" ]; then
printf '%s\n' "$GIT_BLOCK" >> "$SESSION_FILE"
echo ""
echo " ✓ history: Git-Block angehängt an $(basename "$SESSION_FILE")"
echo " → Konversation + Commit in einer Datei"
else
# Modus B: Kein Agent-Log reinen Git-Stub anlegen
BRANCH_CLEAN=$(printf '%s' "$BRANCH" | tr '/' '-' | tr ' ' '-')
OUTFILE="history/prompts/${DATE}_${BRANCH_CLEAN}_${HASH}.md"
cat > "$OUTFILE" << STUB
# Auto-Log: $MSG
$GIT_BLOCK
*Kein Agent-Log vorhanden. Für vollständige Konversation: Copilot Chat → \`/history\` vor dem Commit ausführen.*
STUB
echo ""
echo " ✓ history: $(basename "$OUTFILE") geschrieben (nur Git-Metadaten)"
echo " → Tipp: '/history' vor dem Commit für vollständige Konversation"
fi
echo " → wird beim nächsten Commit automatisch erfasst"