-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-stop.sh
More file actions
43 lines (37 loc) · 1.37 KB
/
Copy pathsession-stop.sh
File metadata and controls
43 lines (37 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# OpenCode Stop hook: Log session summary when Claude finishes
# Records what was worked on for audit trail and sprint tracking
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
SESSION_LOG_DIR="production/session-logs"
mkdir -p "$SESSION_LOG_DIR" 2>/dev/null
# Log recent git activity from this session (check up to 8 hours for long sessions)
RECENT_COMMITS=$(git log --oneline --since="8 hours ago" 2>/dev/null)
MODIFIED_FILES=$(git diff --name-only 2>/dev/null)
# --- Archive active session state on shutdown (do NOT delete) ---
# active.md persists across clean exits so multi-session recovery works.
# It is only valid to delete active.md manually or when explicitly superseded.
STATE_FILE="production/session-state/active.md"
if [ -f "$STATE_FILE" ]; then
{
echo "## Archived Session State: $TIMESTAMP"
cat "$STATE_FILE"
echo "---"
echo ""
} >> "$SESSION_LOG_DIR/session-log.md" 2>/dev/null
fi
if [ -n "$RECENT_COMMITS" ] || [ -n "$MODIFIED_FILES" ]; then
{
echo "## Session End: $TIMESTAMP"
if [ -n "$RECENT_COMMITS" ]; then
echo "### Commits"
echo "$RECENT_COMMITS"
fi
if [ -n "$MODIFIED_FILES" ]; then
echo "### Uncommitted Changes"
echo "$MODIFIED_FILES"
fi
echo "---"
echo ""
} >> "$SESSION_LOG_DIR/session-log.md" 2>/dev/null
fi
exit 0