-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession-end
More file actions
executable file
·181 lines (152 loc) · 4.54 KB
/
session-end
File metadata and controls
executable file
·181 lines (152 loc) · 4.54 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash
# Universal Session End Script v3.0
# Usage: ./session-end [optional-feature-name]
set -e
# Configuration
PROJECT_NAME=$(basename "$PWD")
FEATURE_NAME="${1:-Session Update}"
DATE=$(date +"%B %d, %Y")
DATE_SHORT=$(date +"%Y-%m-%d")
TIMESTAMP=$(date +"%Y-%m-%d_%H%M%S")
# Paths
CLAUDE_DIR=".claude"
LOGS_DIR="$CLAUDE_DIR/logs/sessions"
SESSION_FILE="$LOGS_DIR/${TIMESTAMP}.md"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
NC='\033[0m'
# Helper functions
print_header() { echo -e "\n${BLUE}${BOLD}=== $1 ===${NC}"; }
print_success() { echo -e "${GREEN}✓${NC} $1"; }
print_warning() { echo -e "${YELLOW}⚠${NC} $1"; }
print_info() { echo -e "${CYAN}ℹ${NC} $1"; }
# Start
print_header "Session End"
echo -e "Project: ${BOLD}$PROJECT_NAME${NC}"
echo -e "Feature: ${BOLD}$FEATURE_NAME${NC}"
# Verify git
if [ ! -d ".git" ]; then
print_warning "Not a git repository"
fi
# Create directories
mkdir -p "$LOGS_DIR"
mkdir -p "docs/archive"
# Git state (if available)
if [ -d ".git" ]; then
BRANCH=$(git branch --show-current 2>/dev/null || echo "main")
COMMITS=$(git log --oneline -10 2>/dev/null || echo "No commits")
STATUS=$(git status --short 2>/dev/null || echo "Clean")
DIFF_STAT=$(git diff --stat 2>/dev/null || echo "No changes")
FILES_CHANGED=$(git diff --name-only 2>/dev/null | wc -l | tr -d ' ')
else
BRANCH="N/A"
COMMITS="Not a git repository"
STATUS="N/A"
DIFF_STAT="N/A"
FILES_CHANGED="0"
fi
print_success "State captured"
# Run tests based on project type
print_header "Running Tests"
TEST_RESULTS=""
TEST_STATUS="⏭️ Skipped"
if [ -f "package.json" ] && grep -q '"test"' package.json 2>/dev/null; then
print_info "Running npm tests..."
if npm test 2>&1 | tee /tmp/test-output.txt | tail -5; then
TEST_STATUS="✅ Passed"
else
TEST_STATUS="❌ Failed"
fi
TEST_RESULTS=$(cat /tmp/test-output.txt | tail -20)
elif [ -f "requirements.txt" ] || [ -f "pyproject.toml" ]; then
if command -v pytest &> /dev/null; then
print_info "Running pytest..."
if pytest 2>&1 | tee /tmp/test-output.txt | tail -5; then
TEST_STATUS="✅ Passed"
else
TEST_STATUS="❌ Failed"
fi
TEST_RESULTS=$(cat /tmp/test-output.txt | tail -20)
fi
elif [ -f "Cargo.toml" ]; then
print_info "Running cargo tests..."
if cargo test 2>&1 | tee /tmp/test-output.txt | tail -5; then
TEST_STATUS="✅ Passed"
else
TEST_STATUS="❌ Failed"
fi
TEST_RESULTS=$(cat /tmp/test-output.txt | tail -20)
else
TEST_RESULTS="No automated tests found"
fi
# Generate summary
print_header "Generating Summary"
cat > "$SESSION_FILE" << EOF
# Session Summary: $FEATURE_NAME
**Date**: $DATE
**Project**: $PROJECT_NAME
**Branch**: $BRANCH
**Status**: $TEST_STATUS
## Work Completed
$FEATURE_NAME
## Git State
\`\`\`
$STATUS
\`\`\`
## Recent Commits
\`\`\`
$COMMITS
\`\`\`
## Test Results
\`\`\`
$TEST_RESULTS
\`\`\`
## Next Session
\`\`\`bash
cd $(pwd)
./session-start
\`\`\`
---
*Ended: $TIMESTAMP*
EOF
print_success "Summary saved: $SESSION_FILE"
# Update memory
if [ -f "$CLAUDE_DIR/memory.md" ]; then
echo -e "\n### $DATE - $FEATURE_NAME" >> "$CLAUDE_DIR/memory.md"
echo "- Branch: $BRANCH" >> "$CLAUDE_DIR/memory.md"
echo "- Status: $TEST_STATUS" >> "$CLAUDE_DIR/memory.md"
sed -i.bak "s/Last Updated:.*/Last Updated: $DATE/" "$CLAUDE_DIR/memory.md" 2>/dev/null || true
rm "$CLAUDE_DIR/memory.md.bak" 2>/dev/null || true
fi
# Export to Superpowers if available
if [ -f ".claude/superpowers-bridge.sh" ]; then
print_info "Exporting to Superpowers..."
.claude/superpowers-bridge.sh export "$SESSION_FILE" 2>/dev/null || true
fi
# Cleanup temp files (runs automatically via hook)
find . -type f \( -name "*.tmp" -o -name "*.log" -o -name ".DS_Store" \) \
-not -path "./node_modules/*" -not -path "./.git/*" \
-not -path "./$LOGS_DIR/*" -delete 2>/dev/null || true
# Optional git commit
if [ -d ".git" ]; then
echo ""
read -p "Commit session docs? [y/N] " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
git add "$CLAUDE_DIR/" docs/STATUS.md 2>/dev/null || true
git commit -m "docs: session end - $FEATURE_NAME
Summary: $SESSION_FILE
Status: $TEST_STATUS
Co-authored-by: Claude <claude-code@anthropic.com>" || true
print_success "Committed"
fi
fi
echo ""
echo -e "${GREEN}${BOLD}✨ Session ended successfully!${NC}"
echo -e "Summary: ${CYAN}$SESSION_FILE${NC}"
echo -e "Start next: ${CYAN}./session-start${NC}"