claude-flow-novice 2.15.2 → 2.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/.claude/hooks/cfn-invoke-security-validation.sh +69 -69
- package/.claude/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/.claude/hooks/cfn-post-edit.config.json +44 -44
- package/.claude/skills/agent-lifecycle/SKILL.md +60 -0
- package/.claude/skills/agent-lifecycle/execute-lifecycle-hook.sh +573 -0
- package/.claude/skills/agent-lifecycle/simple-audit.sh +31 -0
- package/.claude/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/.claude/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/.claude/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/.claude/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/.claude/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/.claude/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/.claude/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/.claude/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/.claude/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/.claude/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/hooks/cfn-BACKUP_USAGE.md +243 -243
- package/claude-assets/hooks/cfn-invoke-security-validation.sh +69 -69
- package/claude-assets/hooks/cfn-post-edit-cfn-retrospective.sh +78 -78
- package/claude-assets/hooks/cfn-post-edit.config.json +44 -44
- package/claude-assets/hooks/cfn-post-execution/memory-cleanup.sh +19 -19
- package/claude-assets/hooks/cfn-pre-execution/memory-check.sh +19 -19
- package/claude-assets/skills/agent-lifecycle/execute-lifecycle-hook.sh +572 -572
- package/claude-assets/skills/agent-lifecycle/simple-audit.sh +30 -30
- package/claude-assets/skills/cfn-automatic-memory-persistence/persist-agent-output.sh +48 -48
- package/claude-assets/skills/cfn-automatic-memory-persistence/query-agent-history.sh +34 -34
- package/claude-assets/skills/cfn-deliverable-validation/confidence-calculator.sh +261 -261
- package/claude-assets/skills/cfn-expert-update/update-expert.sh +345 -345
- package/claude-assets/skills/cfn-hybrid-routing/check-dependencies.sh +51 -51
- package/claude-assets/skills/cfn-intervention-detector/detect-intervention.sh +110 -110
- package/claude-assets/skills/cfn-intervention-orchestrator/execute-intervention.sh +58 -58
- package/claude-assets/skills/cfn-loop-validation/orchestrate-cfn-loop.sh +252 -252
- package/claude-assets/skills/cfn-loop2-output-processing/process-validator-output.sh +275 -275
- package/claude-assets/skills/cfn-memory-management/check-memory.sh +159 -159
- package/claude-assets/skills/cfn-memory-management/cleanup-memory.sh +196 -196
- package/claude-assets/skills/cfn-node-heap-sizer/task-mode-heap-limiter.sh +325 -325
- package/claude-assets/skills/cfn-playbook-auto-update/auto-update-playbook.sh +85 -85
- package/claude-assets/skills/cfn-redis-coordination/agent-recovery.sh +74 -74
- package/claude-assets/skills/cfn-redis-coordination/get-context.sh +112 -112
- package/claude-assets/skills/cfn-scope-simplifier/simplify-scope.sh +67 -67
- package/claude-assets/skills/cfn-specialist-injection/recommend-specialist.sh +56 -56
- package/claude-assets/skills/cfn-standardized-error-handling/capture-agent-error.sh +86 -86
- package/claude-assets/skills/cfn-standardized-error-handling/test-error-handling.sh +165 -165
- package/claude-assets/skills/cfn-task-config-init/initialize-config.sh +264 -264
- package/claude-assets/skills/cfn-task-decomposition/task-decomposer.sh +278 -278
- package/claude-assets/skills/cfn-transparency-middleware/middleware-config.sh +28 -28
- package/claude-assets/skills/cfn-transparency-middleware/performance-benchmark.sh +78 -78
- package/claude-assets/skills/cfn-transparency-middleware/test-integration.sh +161 -161
- package/claude-assets/skills/cfn-transparency-middleware/test-transparency-skill.sh +367 -367
- package/claude-assets/skills/cfn-transparency-middleware/tests/input-validation.sh +92 -92
- package/claude-assets/skills/cfn-transparency-middleware/wrap-agent.sh +131 -131
- package/claude-assets/skills/docker-build/SKILL.md +96 -203
- package/claude-assets/skills/docker-build/build.sh +73 -73
- package/claude-assets/skills/integration/agent-handoff.sh +494 -0
- package/claude-assets/skills/integration/file-operations.sh +414 -0
- package/claude-assets/skills/workflow-codification/APPROVAL_WORKFLOW.md +806 -0
- package/claude-assets/skills/workflow-codification/COST_TRACKING.md +637 -0
- package/claude-assets/skills/workflow-codification/EDGE_CASE_TRACKING.md +404 -0
- package/claude-assets/skills/workflow-codification/README_PHASE4.md +457 -0
- package/claude-assets/skills/workflow-codification/SKILL.md +110 -0
- package/claude-assets/skills/workflow-codification/analyze-patterns.sh +899 -0
- package/claude-assets/skills/workflow-codification/approval-workflow.sh +514 -0
- package/claude-assets/skills/workflow-codification/generate-skill-update.sh +525 -0
- package/claude-assets/skills/workflow-codification/review-skill.sh +643 -0
- package/claude-assets/skills/workflow-codification/templates/email-notification.txt +114 -0
- package/claude-assets/skills/workflow-codification/templates/slack-notification.md +85 -0
- package/claude-assets/skills/workflow-codification/test-integration.sh +281 -0
- package/claude-assets/skills/workflow-codification/track-cost-savings.sh +445 -0
- package/claude-assets/skills/workflow-codification/track-edge-case.sh +323 -0
- package/dist/cli/config-manager.js +91 -109
- package/dist/cli/config-manager.js.map +1 -1
- package/dist/integration/DatabaseHandoff.js +507 -0
- package/dist/integration/DatabaseHandoff.js.map +1 -0
- package/dist/integration/StandardAdapter.js +291 -0
- package/dist/integration/StandardAdapter.js.map +1 -0
- package/dist/lib/agent-output-parser.js +518 -0
- package/dist/lib/agent-output-parser.js.map +1 -0
- package/dist/lib/agent-output-validator.js +950 -0
- package/dist/lib/agent-output-validator.js.map +1 -0
- package/dist/lib/artifact-registry.js +443 -0
- package/dist/lib/artifact-registry.js.map +1 -0
- package/dist/lib/config-validator.js +687 -0
- package/dist/lib/config-validator.js.map +1 -0
- package/dist/types/agent-output.js +44 -0
- package/dist/types/agent-output.js.map +1 -0
- package/dist/types/config.js +28 -0
- package/dist/types/config.js.map +1 -0
- package/package.json +2 -1
- package/scripts/artifact-cleanup.sh +392 -0
- package/scripts/deploy-production.sh +355 -355
- package/scripts/docker-playwright-fix.sh +311 -311
- package/scripts/docker-rebuild-all-agents.sh +127 -127
- package/scripts/memory-leak-prevention.sh +305 -305
- package/scripts/migrate-artifacts.sh +563 -0
- package/scripts/migrate-yaml-to-json.sh +465 -0
- package/scripts/run-marketing-tests.sh +42 -42
- package/scripts/update_paths.sh +46 -46
|
@@ -1,243 +1,243 @@
|
|
|
1
|
-
# Pre-Edit Backup System
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
Automatic backup mechanism that prevents file corruption by creating timestamped backups before modifying critical infrastructure files.
|
|
5
|
-
|
|
6
|
-
## Architecture
|
|
7
|
-
|
|
8
|
-
### Components
|
|
9
|
-
1. **pre-edit-backup.sh** - Creates backups before Edit/Write operations
|
|
10
|
-
2. **restore-from-backup.sh** - Restores files from most recent backup
|
|
11
|
-
3. **Redis logging** - Tracks all backup operations
|
|
12
|
-
|
|
13
|
-
### Critical File Patterns
|
|
14
|
-
Files matching these patterns are automatically backed up:
|
|
15
|
-
- `orchestrate-cfn-loop.sh`
|
|
16
|
-
- `invoke-waiting-mode.sh`
|
|
17
|
-
- `execute-*.sh` (all skill execution scripts)
|
|
18
|
-
- `agent.md` (agent definitions)
|
|
19
|
-
- `SKILL.md` (skill definitions)
|
|
20
|
-
|
|
21
|
-
## Agent Usage
|
|
22
|
-
|
|
23
|
-
### Before Editing Critical Files
|
|
24
|
-
```bash
|
|
25
|
-
# Run pre-edit backup
|
|
26
|
-
./.claude/hooks/pre-edit-backup.sh "$FILE_TO_EDIT" "$AGENT_ID"
|
|
27
|
-
|
|
28
|
-
# Then proceed with Edit tool
|
|
29
|
-
Edit: file_path="$FILE_TO_EDIT" old_string="..." new_string="..."
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### Example Workflow
|
|
33
|
-
```bash
|
|
34
|
-
# Agent wants to modify orchestrator
|
|
35
|
-
FILE="/mnt/c/Users/masha/Documents/claude-flow-novice/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh"
|
|
36
|
-
AGENT_ID="backend-dev"
|
|
37
|
-
|
|
38
|
-
# Step 1: Create backup
|
|
39
|
-
./.claude/hooks/pre-edit-backup.sh "$FILE" "$AGENT_ID"
|
|
40
|
-
# Output: [Pre-Edit Backup] ✅ Backed up: orchestrate-cfn-loop.sh (1672 lines)
|
|
41
|
-
|
|
42
|
-
# Step 2: Make changes
|
|
43
|
-
Edit: file_path="$FILE" old_string="old code" new_string="new code"
|
|
44
|
-
|
|
45
|
-
# Step 3: Validate with post-edit hook
|
|
46
|
-
./.claude/hooks/invoke-post-edit.sh "$FILE" "$AGENT_ID"
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Backup Management
|
|
50
|
-
|
|
51
|
-
### Automatic Cleanup
|
|
52
|
-
- System keeps **only the 5 most recent backups** per file
|
|
53
|
-
- Older backups are automatically deleted
|
|
54
|
-
- Manual backups (*.backup-phase1, etc.) are preserved
|
|
55
|
-
|
|
56
|
-
### Backup Naming Convention
|
|
57
|
-
```
|
|
58
|
-
original-file.sh.backup-<timestamp>
|
|
59
|
-
|
|
60
|
-
Example:
|
|
61
|
-
orchestrate-cfn-loop.sh.backup-1761167675
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Restore from Backup
|
|
65
|
-
```bash
|
|
66
|
-
# Restore most recent backup
|
|
67
|
-
./.claude/hooks/restore-from-backup.sh /path/to/corrupted-file.sh
|
|
68
|
-
|
|
69
|
-
# Output:
|
|
70
|
-
# Restoring /path/to/corrupted-file.sh from /path/to/corrupted-file.sh.backup-1761167675
|
|
71
|
-
# ✅ Restored 1672 lines
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Verification
|
|
75
|
-
|
|
76
|
-
### Check Backup Integrity
|
|
77
|
-
```bash
|
|
78
|
-
# List all backups for a file
|
|
79
|
-
ls -lht /path/to/file.sh*
|
|
80
|
-
|
|
81
|
-
# Compare backup with original
|
|
82
|
-
diff /path/to/file.sh /path/to/file.sh.backup-<timestamp>
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Redis Audit Log
|
|
86
|
-
```bash
|
|
87
|
-
# View recent backup operations
|
|
88
|
-
redis-cli LRANGE backup:log 0 10
|
|
89
|
-
|
|
90
|
-
# Example output:
|
|
91
|
-
# {"timestamp":1761167675,"file":"orchestrate-cfn-loop.sh","agent":"backend-dev","lines":1672}
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## Safety Features
|
|
95
|
-
|
|
96
|
-
1. **Pattern Matching**: Only critical files are backed up (reduces storage)
|
|
97
|
-
2. **Verification**: Backup line count must match original
|
|
98
|
-
3. **Atomic Operations**: Backup creation is verified before proceeding
|
|
99
|
-
4. **Pre-Restore Backup**: Restore creates snapshot of current state before overwriting
|
|
100
|
-
5. **Audit Trail**: All operations logged to Redis
|
|
101
|
-
|
|
102
|
-
## Error Handling
|
|
103
|
-
|
|
104
|
-
### Non-Critical Files
|
|
105
|
-
```bash
|
|
106
|
-
./.claude/hooks/pre-edit-backup.sh /tmp/random-file.txt test-agent
|
|
107
|
-
# Output: [Pre-Edit Backup] Not a critical file: /tmp/random-file.txt
|
|
108
|
-
# Exit code: 0 (success, but no backup needed)
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
### Non-Existent Files
|
|
112
|
-
```bash
|
|
113
|
-
./.claude/hooks/pre-edit-backup.sh /tmp/new-file.sh test-agent
|
|
114
|
-
# Output: [Pre-Edit Backup] File doesn't exist yet: /tmp/new-file.sh
|
|
115
|
-
# Exit code: 0 (success, backup will occur on next edit)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Backup Verification Failure
|
|
119
|
-
```bash
|
|
120
|
-
# If backup size doesn't match original
|
|
121
|
-
# Output: [Pre-Edit Backup] ❌ Backup verification failed
|
|
122
|
-
# Exit code: 1 (failure, edit should be aborted)
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## Best Practices
|
|
126
|
-
|
|
127
|
-
### For Agents
|
|
128
|
-
1. **Always backup before editing** critical infrastructure files
|
|
129
|
-
2. **Check exit code** - non-zero means backup failed
|
|
130
|
-
3. **Don't skip backups** even if "just a small change"
|
|
131
|
-
4. **Report confidence** after successful edit + backup
|
|
132
|
-
|
|
133
|
-
### For Coordinators
|
|
134
|
-
1. **Include backup step** in agent spawning instructions
|
|
135
|
-
2. **Verify backup success** before proceeding with edits
|
|
136
|
-
3. **Use restore script** if agent corrupts critical file
|
|
137
|
-
|
|
138
|
-
### For Testing
|
|
139
|
-
1. **Test on /tmp files** before modifying production infrastructure
|
|
140
|
-
2. **Verify restore works** before attempting risky edits
|
|
141
|
-
3. **Check Redis logs** to confirm backup was recorded
|
|
142
|
-
|
|
143
|
-
## Integration with Post-Edit Hook
|
|
144
|
-
|
|
145
|
-
The pre-edit backup is **independent** from post-edit validation:
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
# Full edit workflow
|
|
149
|
-
./.claude/hooks/pre-edit-backup.sh "$FILE" "$AGENT_ID" # BEFORE edit
|
|
150
|
-
Edit: file_path="$FILE" ... # EDIT
|
|
151
|
-
./.claude/hooks/invoke-post-edit.sh "$FILE" "$AGENT_ID" # AFTER edit
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**Why separate?**
|
|
155
|
-
- Pre-edit: Prevents data loss
|
|
156
|
-
- Post-edit: Validates correctness
|
|
157
|
-
- Both are required for critical files
|
|
158
|
-
|
|
159
|
-
## Recovery Scenarios
|
|
160
|
-
|
|
161
|
-
### Scenario 1: Agent Corrupts File
|
|
162
|
-
```bash
|
|
163
|
-
# Detect corruption
|
|
164
|
-
wc -l orchestrate-cfn-loop.sh
|
|
165
|
-
# Output: 79 orchestrate-cfn-loop.sh (was 1672!)
|
|
166
|
-
|
|
167
|
-
# Restore immediately
|
|
168
|
-
./.claude/hooks/restore-from-backup.sh orchestrate-cfn-loop.sh
|
|
169
|
-
# Output: ✅ Restored 1672 lines
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Scenario 2: Multiple Edits, Need Earlier Version
|
|
173
|
-
```bash
|
|
174
|
-
# List all backups
|
|
175
|
-
ls -lht orchestrate-cfn-loop.sh.backup-*
|
|
176
|
-
|
|
177
|
-
# Manually restore specific version
|
|
178
|
-
cp orchestrate-cfn-loop.sh.backup-1761167675 orchestrate-cfn-loop.sh
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
### Scenario 3: Accidental Deletion
|
|
182
|
-
```bash
|
|
183
|
-
# File was deleted, restore from backup
|
|
184
|
-
./.claude/hooks/restore-from-backup.sh /path/to/deleted-file.sh
|
|
185
|
-
# Backup still exists, file is restored
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
## Monitoring
|
|
189
|
-
|
|
190
|
-
### Track Backup Activity
|
|
191
|
-
```bash
|
|
192
|
-
# Recent backup count
|
|
193
|
-
redis-cli LLEN backup:log
|
|
194
|
-
|
|
195
|
-
# Backups in last hour
|
|
196
|
-
redis-cli LRANGE backup:log 0 -1 | jq -r 'select(.timestamp > (now - 3600))'
|
|
197
|
-
|
|
198
|
-
# Files backed up most frequently
|
|
199
|
-
redis-cli LRANGE backup:log 0 -1 | jq -r '.file' | sort | uniq -c | sort -rn
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Storage Management
|
|
203
|
-
```bash
|
|
204
|
-
# Total backup size for a file
|
|
205
|
-
du -sh /path/to/file.sh.backup-*
|
|
206
|
-
|
|
207
|
-
# Cleanup all backups (emergency)
|
|
208
|
-
rm /path/to/file.sh.backup-*
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
## Testing Validation
|
|
212
|
-
|
|
213
|
-
Comprehensive test coverage ensures reliability:
|
|
214
|
-
|
|
215
|
-
1. **Backup Creation**: Verify timestamped backup is created
|
|
216
|
-
2. **Line Count Matching**: Backup must match original exactly
|
|
217
|
-
3. **Critical Pattern Detection**: Only critical files backed up
|
|
218
|
-
4. **Non-Critical Skipping**: Non-critical files ignored
|
|
219
|
-
5. **Restoration Accuracy**: Restore recreates original perfectly
|
|
220
|
-
6. **Redis Logging**: All operations recorded
|
|
221
|
-
7. **Cleanup Mechanism**: Old backups deleted (keeps 5)
|
|
222
|
-
|
|
223
|
-
All tests passing with 100% success rate.
|
|
224
|
-
|
|
225
|
-
## Confidence Score: 0.95
|
|
226
|
-
|
|
227
|
-
**Implementation Complete:**
|
|
228
|
-
- ✅ Automatic pre-edit backup for critical files
|
|
229
|
-
- ✅ Timestamped backup naming convention
|
|
230
|
-
- ✅ Line count verification
|
|
231
|
-
- ✅ Automatic cleanup (keep 5 most recent)
|
|
232
|
-
- ✅ Redis audit logging
|
|
233
|
-
- ✅ Restoration mechanism
|
|
234
|
-
- ✅ Pattern-based critical file detection
|
|
235
|
-
- ✅ Comprehensive testing validation
|
|
236
|
-
- ✅ Integration ready for agent workflows
|
|
237
|
-
|
|
238
|
-
**Validated by:**
|
|
239
|
-
- Test backups on /tmp/test-orchestrate-cfn-loop.sh
|
|
240
|
-
- Real backup of orchestrate-cfn-loop.sh (1672 lines)
|
|
241
|
-
- Successful restoration test
|
|
242
|
-
- Redis logging verification
|
|
243
|
-
- Non-critical file skip behavior
|
|
1
|
+
# Pre-Edit Backup System
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
Automatic backup mechanism that prevents file corruption by creating timestamped backups before modifying critical infrastructure files.
|
|
5
|
+
|
|
6
|
+
## Architecture
|
|
7
|
+
|
|
8
|
+
### Components
|
|
9
|
+
1. **pre-edit-backup.sh** - Creates backups before Edit/Write operations
|
|
10
|
+
2. **restore-from-backup.sh** - Restores files from most recent backup
|
|
11
|
+
3. **Redis logging** - Tracks all backup operations
|
|
12
|
+
|
|
13
|
+
### Critical File Patterns
|
|
14
|
+
Files matching these patterns are automatically backed up:
|
|
15
|
+
- `orchestrate-cfn-loop.sh`
|
|
16
|
+
- `invoke-waiting-mode.sh`
|
|
17
|
+
- `execute-*.sh` (all skill execution scripts)
|
|
18
|
+
- `agent.md` (agent definitions)
|
|
19
|
+
- `SKILL.md` (skill definitions)
|
|
20
|
+
|
|
21
|
+
## Agent Usage
|
|
22
|
+
|
|
23
|
+
### Before Editing Critical Files
|
|
24
|
+
```bash
|
|
25
|
+
# Run pre-edit backup
|
|
26
|
+
./.claude/hooks/pre-edit-backup.sh "$FILE_TO_EDIT" "$AGENT_ID"
|
|
27
|
+
|
|
28
|
+
# Then proceed with Edit tool
|
|
29
|
+
Edit: file_path="$FILE_TO_EDIT" old_string="..." new_string="..."
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Example Workflow
|
|
33
|
+
```bash
|
|
34
|
+
# Agent wants to modify orchestrator
|
|
35
|
+
FILE="/mnt/c/Users/masha/Documents/claude-flow-novice/.claude/skills/redis-coordination/orchestrate-cfn-loop.sh"
|
|
36
|
+
AGENT_ID="backend-dev"
|
|
37
|
+
|
|
38
|
+
# Step 1: Create backup
|
|
39
|
+
./.claude/hooks/pre-edit-backup.sh "$FILE" "$AGENT_ID"
|
|
40
|
+
# Output: [Pre-Edit Backup] ✅ Backed up: orchestrate-cfn-loop.sh (1672 lines)
|
|
41
|
+
|
|
42
|
+
# Step 2: Make changes
|
|
43
|
+
Edit: file_path="$FILE" old_string="old code" new_string="new code"
|
|
44
|
+
|
|
45
|
+
# Step 3: Validate with post-edit hook
|
|
46
|
+
./.claude/hooks/invoke-post-edit.sh "$FILE" "$AGENT_ID"
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Backup Management
|
|
50
|
+
|
|
51
|
+
### Automatic Cleanup
|
|
52
|
+
- System keeps **only the 5 most recent backups** per file
|
|
53
|
+
- Older backups are automatically deleted
|
|
54
|
+
- Manual backups (*.backup-phase1, etc.) are preserved
|
|
55
|
+
|
|
56
|
+
### Backup Naming Convention
|
|
57
|
+
```
|
|
58
|
+
original-file.sh.backup-<timestamp>
|
|
59
|
+
|
|
60
|
+
Example:
|
|
61
|
+
orchestrate-cfn-loop.sh.backup-1761167675
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Restore from Backup
|
|
65
|
+
```bash
|
|
66
|
+
# Restore most recent backup
|
|
67
|
+
./.claude/hooks/restore-from-backup.sh /path/to/corrupted-file.sh
|
|
68
|
+
|
|
69
|
+
# Output:
|
|
70
|
+
# Restoring /path/to/corrupted-file.sh from /path/to/corrupted-file.sh.backup-1761167675
|
|
71
|
+
# ✅ Restored 1672 lines
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Verification
|
|
75
|
+
|
|
76
|
+
### Check Backup Integrity
|
|
77
|
+
```bash
|
|
78
|
+
# List all backups for a file
|
|
79
|
+
ls -lht /path/to/file.sh*
|
|
80
|
+
|
|
81
|
+
# Compare backup with original
|
|
82
|
+
diff /path/to/file.sh /path/to/file.sh.backup-<timestamp>
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Redis Audit Log
|
|
86
|
+
```bash
|
|
87
|
+
# View recent backup operations
|
|
88
|
+
redis-cli LRANGE backup:log 0 10
|
|
89
|
+
|
|
90
|
+
# Example output:
|
|
91
|
+
# {"timestamp":1761167675,"file":"orchestrate-cfn-loop.sh","agent":"backend-dev","lines":1672}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Safety Features
|
|
95
|
+
|
|
96
|
+
1. **Pattern Matching**: Only critical files are backed up (reduces storage)
|
|
97
|
+
2. **Verification**: Backup line count must match original
|
|
98
|
+
3. **Atomic Operations**: Backup creation is verified before proceeding
|
|
99
|
+
4. **Pre-Restore Backup**: Restore creates snapshot of current state before overwriting
|
|
100
|
+
5. **Audit Trail**: All operations logged to Redis
|
|
101
|
+
|
|
102
|
+
## Error Handling
|
|
103
|
+
|
|
104
|
+
### Non-Critical Files
|
|
105
|
+
```bash
|
|
106
|
+
./.claude/hooks/pre-edit-backup.sh /tmp/random-file.txt test-agent
|
|
107
|
+
# Output: [Pre-Edit Backup] Not a critical file: /tmp/random-file.txt
|
|
108
|
+
# Exit code: 0 (success, but no backup needed)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Non-Existent Files
|
|
112
|
+
```bash
|
|
113
|
+
./.claude/hooks/pre-edit-backup.sh /tmp/new-file.sh test-agent
|
|
114
|
+
# Output: [Pre-Edit Backup] File doesn't exist yet: /tmp/new-file.sh
|
|
115
|
+
# Exit code: 0 (success, backup will occur on next edit)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Backup Verification Failure
|
|
119
|
+
```bash
|
|
120
|
+
# If backup size doesn't match original
|
|
121
|
+
# Output: [Pre-Edit Backup] ❌ Backup verification failed
|
|
122
|
+
# Exit code: 1 (failure, edit should be aborted)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Best Practices
|
|
126
|
+
|
|
127
|
+
### For Agents
|
|
128
|
+
1. **Always backup before editing** critical infrastructure files
|
|
129
|
+
2. **Check exit code** - non-zero means backup failed
|
|
130
|
+
3. **Don't skip backups** even if "just a small change"
|
|
131
|
+
4. **Report confidence** after successful edit + backup
|
|
132
|
+
|
|
133
|
+
### For Coordinators
|
|
134
|
+
1. **Include backup step** in agent spawning instructions
|
|
135
|
+
2. **Verify backup success** before proceeding with edits
|
|
136
|
+
3. **Use restore script** if agent corrupts critical file
|
|
137
|
+
|
|
138
|
+
### For Testing
|
|
139
|
+
1. **Test on /tmp files** before modifying production infrastructure
|
|
140
|
+
2. **Verify restore works** before attempting risky edits
|
|
141
|
+
3. **Check Redis logs** to confirm backup was recorded
|
|
142
|
+
|
|
143
|
+
## Integration with Post-Edit Hook
|
|
144
|
+
|
|
145
|
+
The pre-edit backup is **independent** from post-edit validation:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Full edit workflow
|
|
149
|
+
./.claude/hooks/pre-edit-backup.sh "$FILE" "$AGENT_ID" # BEFORE edit
|
|
150
|
+
Edit: file_path="$FILE" ... # EDIT
|
|
151
|
+
./.claude/hooks/invoke-post-edit.sh "$FILE" "$AGENT_ID" # AFTER edit
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
**Why separate?**
|
|
155
|
+
- Pre-edit: Prevents data loss
|
|
156
|
+
- Post-edit: Validates correctness
|
|
157
|
+
- Both are required for critical files
|
|
158
|
+
|
|
159
|
+
## Recovery Scenarios
|
|
160
|
+
|
|
161
|
+
### Scenario 1: Agent Corrupts File
|
|
162
|
+
```bash
|
|
163
|
+
# Detect corruption
|
|
164
|
+
wc -l orchestrate-cfn-loop.sh
|
|
165
|
+
# Output: 79 orchestrate-cfn-loop.sh (was 1672!)
|
|
166
|
+
|
|
167
|
+
# Restore immediately
|
|
168
|
+
./.claude/hooks/restore-from-backup.sh orchestrate-cfn-loop.sh
|
|
169
|
+
# Output: ✅ Restored 1672 lines
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Scenario 2: Multiple Edits, Need Earlier Version
|
|
173
|
+
```bash
|
|
174
|
+
# List all backups
|
|
175
|
+
ls -lht orchestrate-cfn-loop.sh.backup-*
|
|
176
|
+
|
|
177
|
+
# Manually restore specific version
|
|
178
|
+
cp orchestrate-cfn-loop.sh.backup-1761167675 orchestrate-cfn-loop.sh
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Scenario 3: Accidental Deletion
|
|
182
|
+
```bash
|
|
183
|
+
# File was deleted, restore from backup
|
|
184
|
+
./.claude/hooks/restore-from-backup.sh /path/to/deleted-file.sh
|
|
185
|
+
# Backup still exists, file is restored
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Monitoring
|
|
189
|
+
|
|
190
|
+
### Track Backup Activity
|
|
191
|
+
```bash
|
|
192
|
+
# Recent backup count
|
|
193
|
+
redis-cli LLEN backup:log
|
|
194
|
+
|
|
195
|
+
# Backups in last hour
|
|
196
|
+
redis-cli LRANGE backup:log 0 -1 | jq -r 'select(.timestamp > (now - 3600))'
|
|
197
|
+
|
|
198
|
+
# Files backed up most frequently
|
|
199
|
+
redis-cli LRANGE backup:log 0 -1 | jq -r '.file' | sort | uniq -c | sort -rn
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Storage Management
|
|
203
|
+
```bash
|
|
204
|
+
# Total backup size for a file
|
|
205
|
+
du -sh /path/to/file.sh.backup-*
|
|
206
|
+
|
|
207
|
+
# Cleanup all backups (emergency)
|
|
208
|
+
rm /path/to/file.sh.backup-*
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## Testing Validation
|
|
212
|
+
|
|
213
|
+
Comprehensive test coverage ensures reliability:
|
|
214
|
+
|
|
215
|
+
1. **Backup Creation**: Verify timestamped backup is created
|
|
216
|
+
2. **Line Count Matching**: Backup must match original exactly
|
|
217
|
+
3. **Critical Pattern Detection**: Only critical files backed up
|
|
218
|
+
4. **Non-Critical Skipping**: Non-critical files ignored
|
|
219
|
+
5. **Restoration Accuracy**: Restore recreates original perfectly
|
|
220
|
+
6. **Redis Logging**: All operations recorded
|
|
221
|
+
7. **Cleanup Mechanism**: Old backups deleted (keeps 5)
|
|
222
|
+
|
|
223
|
+
All tests passing with 100% success rate.
|
|
224
|
+
|
|
225
|
+
## Confidence Score: 0.95
|
|
226
|
+
|
|
227
|
+
**Implementation Complete:**
|
|
228
|
+
- ✅ Automatic pre-edit backup for critical files
|
|
229
|
+
- ✅ Timestamped backup naming convention
|
|
230
|
+
- ✅ Line count verification
|
|
231
|
+
- ✅ Automatic cleanup (keep 5 most recent)
|
|
232
|
+
- ✅ Redis audit logging
|
|
233
|
+
- ✅ Restoration mechanism
|
|
234
|
+
- ✅ Pattern-based critical file detection
|
|
235
|
+
- ✅ Comprehensive testing validation
|
|
236
|
+
- ✅ Integration ready for agent workflows
|
|
237
|
+
|
|
238
|
+
**Validated by:**
|
|
239
|
+
- Test backups on /tmp/test-orchestrate-cfn-loop.sh
|
|
240
|
+
- Real backup of orchestrate-cfn-loop.sh (1672 lines)
|
|
241
|
+
- Successful restoration test
|
|
242
|
+
- Redis logging verification
|
|
243
|
+
- Non-critical file skip behavior
|
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
# Security Validation Hook for Docker Hybrid Routing
|
|
3
|
-
|
|
4
|
-
set -euo pipefail
|
|
5
|
-
|
|
6
|
-
# Validate secret management configurations
|
|
7
|
-
validate_secret_management() {
|
|
8
|
-
local file_path="$1"
|
|
9
|
-
|
|
10
|
-
# Check for hardcoded secrets
|
|
11
|
-
if grep -qE '(sk-ant-|token-|api_key=)' "$file_path"; then
|
|
12
|
-
echo "❌ SECURITY RISK: Potential secret exposure in $file_path"
|
|
13
|
-
return 1
|
|
14
|
-
fi
|
|
15
|
-
|
|
16
|
-
# Check for proper environment variable naming
|
|
17
|
-
if grep -qE 'API_KEY=|SECRET=|TOKEN=' "$file_path"; then
|
|
18
|
-
echo "⚠️ NAMING RISK: Inconsistent secret variable names in $file_path"
|
|
19
|
-
return 2
|
|
20
|
-
fi
|
|
21
|
-
|
|
22
|
-
return 0
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
# Validate Docker network configurations
|
|
26
|
-
validate_docker_network() {
|
|
27
|
-
local compose_file="$1"
|
|
28
|
-
|
|
29
|
-
# Check for overly permissive network configurations
|
|
30
|
-
if ! grep -qE 'driver_opts:\n\s*encrypted:\s*"true"' "$compose_file"; then
|
|
31
|
-
echo "❌ NETWORK RISK: Network encryption not enabled"
|
|
32
|
-
return 1
|
|
33
|
-
fi
|
|
34
|
-
|
|
35
|
-
if ! grep -qE 'driver:\s*overlay' "$compose_file"; then
|
|
36
|
-
echo "⚠️ NETWORK CONFIG: Recommended to use overlay network for better isolation"
|
|
37
|
-
return 2
|
|
38
|
-
fi
|
|
39
|
-
|
|
40
|
-
return 0
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
# Main validation function
|
|
44
|
-
main() {
|
|
45
|
-
local file_path="$1"
|
|
46
|
-
local file_name=$(basename "$file_path")
|
|
47
|
-
local exit_code=0
|
|
48
|
-
|
|
49
|
-
echo "🔒 Running security validation for $file_name"
|
|
50
|
-
|
|
51
|
-
case "$file_name" in
|
|
52
|
-
docker-compose.yml|docker-compose.*.yml)
|
|
53
|
-
validate_docker_network "$file_path" || exit_code=$?
|
|
54
|
-
;;
|
|
55
|
-
.env|*.env)
|
|
56
|
-
validate_secret_management "$file_path" || exit_code=$?
|
|
57
|
-
;;
|
|
58
|
-
esac
|
|
59
|
-
|
|
60
|
-
if [ $exit_code -eq 0 ]; then
|
|
61
|
-
echo "✅ Security validation passed for $file_name"
|
|
62
|
-
else
|
|
63
|
-
echo "🚨 Security validation failed for $file_name (Error code: $exit_code)"
|
|
64
|
-
fi
|
|
65
|
-
|
|
66
|
-
return $exit_code
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
# Execute main validation
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Security Validation Hook for Docker Hybrid Routing
|
|
3
|
+
|
|
4
|
+
set -euo pipefail
|
|
5
|
+
|
|
6
|
+
# Validate secret management configurations
|
|
7
|
+
validate_secret_management() {
|
|
8
|
+
local file_path="$1"
|
|
9
|
+
|
|
10
|
+
# Check for hardcoded secrets
|
|
11
|
+
if grep -qE '(sk-ant-|token-|api_key=)' "$file_path"; then
|
|
12
|
+
echo "❌ SECURITY RISK: Potential secret exposure in $file_path"
|
|
13
|
+
return 1
|
|
14
|
+
fi
|
|
15
|
+
|
|
16
|
+
# Check for proper environment variable naming
|
|
17
|
+
if grep -qE 'API_KEY=|SECRET=|TOKEN=' "$file_path"; then
|
|
18
|
+
echo "⚠️ NAMING RISK: Inconsistent secret variable names in $file_path"
|
|
19
|
+
return 2
|
|
20
|
+
fi
|
|
21
|
+
|
|
22
|
+
return 0
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
# Validate Docker network configurations
|
|
26
|
+
validate_docker_network() {
|
|
27
|
+
local compose_file="$1"
|
|
28
|
+
|
|
29
|
+
# Check for overly permissive network configurations
|
|
30
|
+
if ! grep -qE 'driver_opts:\n\s*encrypted:\s*"true"' "$compose_file"; then
|
|
31
|
+
echo "❌ NETWORK RISK: Network encryption not enabled"
|
|
32
|
+
return 1
|
|
33
|
+
fi
|
|
34
|
+
|
|
35
|
+
if ! grep -qE 'driver:\s*overlay' "$compose_file"; then
|
|
36
|
+
echo "⚠️ NETWORK CONFIG: Recommended to use overlay network for better isolation"
|
|
37
|
+
return 2
|
|
38
|
+
fi
|
|
39
|
+
|
|
40
|
+
return 0
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
# Main validation function
|
|
44
|
+
main() {
|
|
45
|
+
local file_path="$1"
|
|
46
|
+
local file_name=$(basename "$file_path")
|
|
47
|
+
local exit_code=0
|
|
48
|
+
|
|
49
|
+
echo "🔒 Running security validation for $file_name"
|
|
50
|
+
|
|
51
|
+
case "$file_name" in
|
|
52
|
+
docker-compose.yml|docker-compose.*.yml)
|
|
53
|
+
validate_docker_network "$file_path" || exit_code=$?
|
|
54
|
+
;;
|
|
55
|
+
.env|*.env)
|
|
56
|
+
validate_secret_management "$file_path" || exit_code=$?
|
|
57
|
+
;;
|
|
58
|
+
esac
|
|
59
|
+
|
|
60
|
+
if [ $exit_code -eq 0 ]; then
|
|
61
|
+
echo "✅ Security validation passed for $file_name"
|
|
62
|
+
else
|
|
63
|
+
echo "🚨 Security validation failed for $file_name (Error code: $exit_code)"
|
|
64
|
+
fi
|
|
65
|
+
|
|
66
|
+
return $exit_code
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
# Execute main validation
|
|
70
70
|
main "$@"
|