Files
CrmClinicas/.claude/helpers/standard-checkpoint-hooks.sh
Consultoria AS 79b5d86325 feat: CRM Clinicas SaaS - MVP completo
- Auth: Login/Register con creacion de clinica
- Dashboard: KPIs reales, graficas recharts
- Pacientes: CRUD completo con busqueda
- Agenda: FullCalendar, drag-and-drop, vista recepcion
- Expediente: Notas SOAP, signos vitales, CIE-10
- Facturacion: Facturas con IVA, campos CFDI SAT
- Inventario: Productos, stock, movimientos, alertas
- Configuracion: Clinica, equipo, catalogo servicios
- Supabase self-hosted: 18 tablas con RLS multi-tenant
- Docker + Nginx para produccion

Co-Authored-By: claude-flow <ruv@ruv.net>
2026-03-03 07:04:14 +00:00

190 lines
5.5 KiB
Bash
Executable File
Raw Permalink 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"
# Handle both JSON input and plain file path
if echo "$tool_input" | jq -e . >/dev/null 2>&1; then
local file=$(echo "$tool_input" | jq -r '.file_path // empty')
else
local file="$tool_input"
fi
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"
# Handle both JSON input and plain file path
if echo "$tool_input" | jq -e . >/dev/null 2>&1; then
local file=$(echo "$tool_input" | jq -r '.file_path // empty')
else
local file="$tool_input"
fi
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