chess/.claude/helpers/standard-checkpoint-hooks.sh
Christoph Wagner 5ad0700b41 refactor: Consolidate repository structure - flatten from workspace pattern
Restructured project from nested workspace pattern to flat single-repo layout.
This eliminates redundant nesting and consolidates all project files under version control.

## Migration Summary

**Before:**
```
alex/ (workspace, not versioned)
├── chess-game/ (git repo)
│   ├── js/, css/, tests/
│   └── index.html
└── docs/ (planning, not versioned)
```

**After:**
```
alex/ (git repo, everything versioned)
├── js/, css/, tests/
├── index.html
├── docs/ (project documentation)
├── planning/ (historical planning docs)
├── .gitea/ (CI/CD)
└── CLAUDE.md (configuration)
```

## Changes Made

### Structure Consolidation
- Moved all chess-game/ contents to root level
- Removed redundant chess-game/ subdirectory
- Flattened directory structure (eliminated one nesting level)

### Documentation Organization
- Moved chess-game/docs/ → docs/ (project documentation)
- Moved alex/docs/ → planning/ (historical planning documents)
- Added CLAUDE.md (workspace configuration)
- Added IMPLEMENTATION_PROMPT.md (original project prompt)

### Version Control Improvements
- All project files now under version control
- Planning documents preserved in planning/ folder
- Merged .gitignore files (workspace + project)
- Added .claude/ agent configurations

### File Updates
- Updated .gitignore to include both workspace and project excludes
- Moved README.md to root level
- All import paths remain functional (relative paths unchanged)

## Benefits

 **Simpler Structure** - One level of nesting removed
 **Complete Versioning** - All documentation now in git
 **Standard Layout** - Matches open-source project conventions
 **Easier Navigation** - Direct access to all project files
 **CI/CD Compatible** - All workflows still functional

## Technical Validation

-  Node.js environment verified
-  Dependencies installed successfully
-  Dev server starts and responds
-  All core files present and accessible
-  Git repository functional

## Files Preserved

**Implementation Files:**
- js/ (3,517 lines of code)
- css/ (4 stylesheets)
- tests/ (87 test cases)
- index.html
- package.json

**CI/CD Pipeline:**
- .gitea/workflows/ci.yml
- .gitea/workflows/release.yml

**Documentation:**
- docs/ (12+ documentation files)
- planning/ (historical planning materials)
- README.md

**Configuration:**
- jest.config.js, babel.config.cjs, playwright.config.js
- .gitignore (merged)
- CLAUDE.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 10:05:26 +01:00

180 lines
5.2 KiB
Bash
Executable File
Raw 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
# Standard checkpoint hook functions for Claude settings.json (without GitHub features)
# Function to handle pre-edit checkpoints
pre_edit_checkpoint() {
local tool_input="$1"
local file=$(echo "$tool_input" | jq -r '.file_path // empty')
if [ -n "$file" ]; then
local checkpoint_branch="checkpoint/pre-edit-$(date +%Y%m%d-%H%M%S)"
local current_branch=$(git branch --show-current)
# Create checkpoint
git add -A
git stash push -m "Pre-edit checkpoint for $file" >/dev/null 2>&1
git branch "$checkpoint_branch"
# Store metadata
mkdir -p .claude/checkpoints
cat > ".claude/checkpoints/$(date +%s).json" <<EOF
{
"branch": "$checkpoint_branch",
"file": "$file",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"type": "pre-edit",
"original_branch": "$current_branch"
}
EOF
# Restore working directory
git stash pop --quiet >/dev/null 2>&1 || true
echo "✅ Created checkpoint: $checkpoint_branch for $file"
fi
}
# Function to handle post-edit checkpoints
post_edit_checkpoint() {
local tool_input="$1"
local file=$(echo "$tool_input" | jq -r '.file_path // empty')
if [ -n "$file" ] && [ -f "$file" ]; then
# Check if file was modified - first check if file is tracked
if ! git ls-files --error-unmatch "$file" >/dev/null 2>&1; then
# File is not tracked, add it first
git add "$file"
fi
# Now check if there are changes
if git diff --cached --quiet "$file" 2>/dev/null && git diff --quiet "$file" 2>/dev/null; then
echo " No changes to checkpoint for $file"
else
local tag_name="checkpoint-$(date +%Y%m%d-%H%M%S)"
local current_branch=$(git branch --show-current)
# Create commit
git add "$file"
if git commit -m "🔖 Checkpoint: Edit $file
Automatic checkpoint created by Claude
- File: $file
- Branch: $current_branch
- Timestamp: $(date -u +%Y-%m-%dT%H:%M:%SZ)
[Auto-checkpoint]" --quiet; then
# Create tag only if commit succeeded
git tag -a "$tag_name" -m "Checkpoint after editing $file"
# Store metadata
mkdir -p .claude/checkpoints
local diff_stats=$(git diff HEAD~1 --stat | tr '\n' ' ' | sed 's/"/\"/g')
cat > ".claude/checkpoints/$(date +%s).json" <<EOF
{
"tag": "$tag_name",
"file": "$file",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"type": "post-edit",
"branch": "$current_branch",
"diff_summary": "$diff_stats"
}
EOF
echo "✅ Created checkpoint: $tag_name for $file"
else
echo " No commit created (no changes or commit failed)"
fi
fi
fi
}
# Function to handle task checkpoints
task_checkpoint() {
local user_prompt="$1"
local task=$(echo "$user_prompt" | head -c 100 | tr '\n' ' ')
if [ -n "$task" ]; then
local checkpoint_name="task-$(date +%Y%m%d-%H%M%S)"
# Commit current state
git add -A
git commit -m "🔖 Task checkpoint: $task..." --quiet || true
# Store metadata
mkdir -p .claude/checkpoints
cat > ".claude/checkpoints/task-$(date +%s).json" <<EOF
{
"checkpoint": "$checkpoint_name",
"task": "$task",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
"commit": "$(git rev-parse HEAD)"
}
EOF
echo "✅ Created task checkpoint: $checkpoint_name"
fi
}
# Function to handle session end
session_end_checkpoint() {
local session_id="session-$(date +%Y%m%d-%H%M%S)"
local summary_file=".claude/checkpoints/summary-$session_id.md"
mkdir -p .claude/checkpoints
# Create summary
cat > "$summary_file" <<EOF
# Session Summary - $(date +'%Y-%m-%d %H:%M:%S')
## Checkpoints Created
$(find .claude/checkpoints -name '*.json' -mtime -1 -exec basename {} \; | sort)
## Files Modified
$(git diff --name-only $(git log --format=%H -n 1 --before="1 hour ago" 2>/dev/null) 2>/dev/null || echo "No files tracked")
## Recent Commits
$(git log --oneline -10 --grep="Checkpoint" || echo "No checkpoint commits")
## Rollback Instructions
To rollback to a specific checkpoint:
\`\`\`bash
# List all checkpoints
git tag -l 'checkpoint-*' | sort -r
# Rollback to a checkpoint
git checkout checkpoint-YYYYMMDD-HHMMSS
# Or reset to a checkpoint (destructive)
git reset --hard checkpoint-YYYYMMDD-HHMMSS
\`\`\`
EOF
# Create final checkpoint
git add -A
git commit -m "🏁 Session end checkpoint: $session_id" --quiet || true
git tag -a "session-end-$session_id" -m "End of Claude session"
echo "✅ Session summary saved to: $summary_file"
echo "📌 Final checkpoint: session-end-$session_id"
}
# Main entry point
case "$1" in
pre-edit)
pre_edit_checkpoint "$2"
;;
post-edit)
post_edit_checkpoint "$2"
;;
task)
task_checkpoint "$2"
;;
session-end)
session_end_checkpoint
;;
*)
echo "Usage: $0 {pre-edit|post-edit|task|session-end} [input]"
exit 1
;;
esac