fix: Add safety checks and auto-recovery to update-memory commands

- Fix execution order in update-memory-related: detect changes before staging
- Add safety checks to prevent unintended source code modifications
- Implement automatic staging recovery if non-CLAUDE.md files are modified
- Ensure both update commands have consistent safety mechanisms

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
catlog22
2025-09-10 18:59:36 +08:00
parent 5983762810
commit 5fe1f40f36
2 changed files with 30 additions and 7 deletions

View File

@@ -83,7 +83,17 @@ FOR depth FROM max_depth DOWN TO 0:
Bash(~/.claude/scripts/update_module_claude.sh "$module" "full" &) Bash(~/.claude/scripts/update_module_claude.sh "$module" "full" &)
wait_all_jobs() wait_all_jobs()
# Step 6: Display changes → Final status # Step 6: Safety check and restore staging state
non_claude=$(Bash(git diff --cached --name-only | grep -v "CLAUDE.md" || true))
if [ -n "$non_claude" ]; then
Bash(git restore --staged .)
echo "⚠️ Warning: Non-CLAUDE.md files were modified, staging reverted"
echo "Modified files: $non_claude"
else
echo "✅ Only CLAUDE.md files modified, staging preserved"
fi
# Step 7: Display changes → Final status
Bash(git status --short) Bash(git status --short)
``` ```
@@ -111,7 +121,8 @@ subagent_type: "memory-gemini-bridge"
- **Separated Commands**: Each bash operation is a discrete, trackable step - **Separated Commands**: Each bash operation is a discrete, trackable step
- **Intelligent Complexity Detection**: Model analyzes project context for optimal strategy - **Intelligent Complexity Detection**: Model analyzes project context for optimal strategy
- **Depth-Parallel Execution**: Same depth modules run in parallel, depths run sequentially - **Depth-Parallel Execution**: Same depth modules run in parallel, depths run sequentially
- **Git Integration**: Auto-cache changes before, show status after - **Git Integration**: Auto-cache changes before, safety check and show status after
- **Safety Protection**: Automatic detection and revert of unintended source code modifications
- **Module Detection**: Uses get_modules_by_depth.sh for structure discovery - **Module Detection**: Uses get_modules_by_depth.sh for structure discovery
- **User Confirmation**: Clear plan presentation with approval step - **User Confirmation**: Clear plan presentation with approval step
- **CLAUDE.md Only**: Only updates documentation, never source code - **CLAUDE.md Only**: Only updates documentation, never source code

View File

@@ -17,17 +17,19 @@ Context-aware documentation update for modules affected by recent changes.
#!/bin/bash #!/bin/bash
# Context-aware CLAUDE.md documentation update # Context-aware CLAUDE.md documentation update
# Step 1: Cache git changes # Step 1: Detect changed modules (before staging)
changed=$(Bash(~/.claude/scripts/detect_changed_modules.sh list))
# Step 2: Cache git changes (protect current state)
Bash(git add -A 2>/dev/null || true) Bash(git add -A 2>/dev/null || true)
# Step 2: Detect changed modules # Step 3: Use detected changes or fallback
changed=$(Bash(~/.claude/scripts/detect_changed_modules.sh list))
if [ -z "$changed" ]; then if [ -z "$changed" ]; then
changed=$(Bash(~/.claude/scripts/get_modules_by_depth.sh list | head -10)) changed=$(Bash(~/.claude/scripts/get_modules_by_depth.sh list | head -10))
fi fi
count=$(echo "$changed" | wc -l) count=$(echo "$changed" | wc -l)
# Step 3: Analysis handover → Model takes control # Step 4: Analysis handover → Model takes control
# BASH_EXECUTION_STOPS → MODEL_ANALYSIS_BEGINS # BASH_EXECUTION_STOPS → MODEL_ANALYSIS_BEGINS
# Pseudocode flow: # Pseudocode flow:
@@ -88,7 +90,17 @@ FOR depth FROM max_depth DOWN TO 0:
Bash(~/.claude/scripts/update_module_claude.sh "$module" "related" &) Bash(~/.claude/scripts/update_module_claude.sh "$module" "related" &)
wait_all_jobs() wait_all_jobs()
# Step 6: Display changes → Final status # Step 6: Safety check and restore staging state
non_claude=$(Bash(git diff --cached --name-only | grep -v "CLAUDE.md" || true))
if [ -n "$non_claude" ]; then
Bash(git restore --staged .)
echo "⚠️ Warning: Non-CLAUDE.md files were modified, staging reverted"
echo "Modified files: $non_claude"
else
echo "✅ Only CLAUDE.md files modified, staging preserved"
fi
# Step 7: Display changes → Final status
Bash(git diff --stat) Bash(git diff --stat)
``` ```