Repository navigation
Expand file tree
/
Copy pathverify-protocol.sh
More file actions
executable file
·151 lines (128 loc) · 4.41 KB
/
Copy pathverify-protocol.sh
File metadata and controls
executable file
·151 lines (128 loc) · 4.41 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
#!/bin/bash
# Protocol Verification Script
# Run this before committing to verify protocol compliance
set -e
echo "🔍 Verifying protocol compliance..."
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
ERRORS=0
WARNINGS=0
# Function to print error
error() {
echo -e "${RED}❌ ERROR: $1${NC}"
((ERRORS++))
}
# Function to print warning
warning() {
echo -e "${YELLOW}⚠️ WARNING: $1${NC}"
((WARNINGS++))
}
# Function to print success
success() {
echo -e "${GREEN}✅ $1${NC}"
}
echo "Checking protocol compliance..."
echo ""
# Check 1: HISTORY.md exists
if [ ! -f "HISTORY.md" ]; then
error "HISTORY.md file not found"
else
success "HISTORY.md exists"
fi
# Check 2: HISTORY.md was updated recently (within last 24 hours)
if [ -f "HISTORY.md" ]; then
HISTORY_MOD=$(date -r HISTORY.md +%s 2>/dev/null || stat -f%m HISTORY.md 2>/dev/null || stat -c%Y HISTORY.md 2>/dev/null)
NOW=$(date +%s)
DIFF=$((NOW - HISTORY_MOD))
HOURS=$((DIFF / 3600))
if [ $HOURS -gt 24 ]; then
warning "HISTORY.md was last updated $HOURS hours ago (should be updated every session)"
else
success "HISTORY.md was updated recently ($HOURS hours ago)"
fi
fi
# Check 3: Current branch name has Jira key format
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null)
if [ -z "$CURRENT_BRANCH" ]; then
warning "Could not determine current branch"
elif [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "dev" ] || [ "$CURRENT_BRANCH" = "staging" ]; then
success "On protected branch: $CURRENT_BRANCH"
elif echo "$CURRENT_BRANCH" | grep -qE '[A-Z]+-[0-9]+'; then
success "Branch name contains Jira key: $CURRENT_BRANCH"
else
error "Branch name does not contain Jira key format (e.g., PROJ-123): $CURRENT_BRANCH"
fi
# Check 4: Recent commits have Jira keys
echo ""
echo "Checking recent commits for Jira keys..."
COMMIT_COUNT=0
MISSING_JIRA=0
while IFS= read -r commit_msg; do
((COMMIT_COUNT++))
if ! echo "$commit_msg" | grep -qE '[A-Z]+-[0-9]+'; then
((MISSING_JIRA++))
warning "Commit missing Jira key: $commit_msg"
fi
done < <(git log --format=%s -n 5 2>/dev/null || echo "")
if [ $COMMIT_COUNT -gt 0 ]; then
if [ $MISSING_JIRA -eq 0 ]; then
success "All recent commits ($COMMIT_COUNT) contain Jira keys"
else
warning "$MISSING_JIRA out of $COMMIT_COUNT recent commits missing Jira keys"
fi
fi
# Check 5: No uncommitted changes (except HISTORY.md and this script's output)
if [ -n "$(git status --porcelain | grep -v 'HISTORY.md' | grep -v 'verify-protocol.sh')" ]; then
warning "You have uncommitted changes (remember to commit and push)"
git status --short | grep -v 'HISTORY.md' | grep -v 'verify-protocol.sh'
else
success "No uncommitted changes (or only HISTORY.md)"
fi
# Check 6: Verify required files exist
echo ""
echo "Checking required protocol files..."
for file in "PROTOCOL.md" "AGENTS.md" "PROJECT.md" "WORKFLOWS.md" "README.md"; do
if [ -f "$file" ]; then
success "$file exists"
else
error "$file is missing"
fi
done
# Check 7: Verify .claude/prompts/session-start.md exists
if [ -f ".claude/prompts/session-start.md" ]; then
success "Session start prompt configured"
else
warning ".claude/prompts/session-start.md not found (session start reminder won't auto-load)"
fi
# Check 8: Verify git remote is configured
if git remote -v | grep -q 'origin'; then
success "Git remote 'origin' is configured"
else
error "Git remote 'origin' is not configured"
fi
# Check 9: Verify we're not on main branch for development work
if [ "$CURRENT_BRANCH" = "main" ] && git status --porcelain | grep -q '^[AM]'; then
error "You have staged changes on the 'main' branch (should work on 'dev' or feature branch)"
fi
# Summary
echo ""
echo "=========================================="
echo "Protocol Verification Summary"
echo "=========================================="
if [ $ERRORS -eq 0 ] && [ $WARNINGS -eq 0 ]; then
echo -e "${GREEN}✅ All checks passed! Protocol compliance verified.${NC}"
exit 0
elif [ $ERRORS -eq 0 ]; then
echo -e "${YELLOW}⚠️ $WARNINGS warning(s) found. Review above and fix if needed.${NC}"
exit 0
else
echo -e "${RED}❌ $ERRORS error(s) and $WARNINGS warning(s) found.${NC}"
echo ""
echo "Please fix the errors above before committing."
echo "See PROTOCOL.md for guidance."
exit 1
fi