myaidev-method 0.2.5 → 0.2.6

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.
Files changed (55) hide show
  1. package/USER_GUIDE.md +389 -8
  2. package/bin/cli.js +161 -70
  3. package/package.json +1 -1
  4. package/src/lib/ascii-banner.js +100 -0
  5. package/src/templates/claude/commands/myai-deploy-dev.md +500 -0
  6. package/src/templates/claude/commands/myai-deploy-prod.md +837 -0
  7. package/src/templates/claude/commands/myai-deploy-staging.md +331 -0
  8. package/src/templates/claude/commands/myai-git-hotfix.md +957 -0
  9. package/src/templates/claude/commands/myai-git-pr.md +200 -0
  10. package/src/templates/claude/commands/myai-git-release.md +806 -0
  11. package/src/templates/claude/commands/myai-git-sync.md +796 -0
  12. package/src/templates/codex/commands/myai-astro-publish.md +51 -0
  13. package/src/templates/codex/commands/myai-configure.md +185 -0
  14. package/src/templates/codex/commands/myai-content-writer.md +73 -0
  15. package/src/templates/codex/commands/myai-coolify-deploy.md +159 -0
  16. package/src/templates/codex/commands/myai-deploy-dev.md +379 -0
  17. package/src/templates/codex/commands/myai-deploy-prod.md +431 -0
  18. package/src/templates/codex/commands/myai-deploy-staging.md +275 -0
  19. package/src/templates/codex/commands/myai-dev-architect.md +69 -0
  20. package/src/templates/codex/commands/myai-dev-code.md +82 -0
  21. package/src/templates/codex/commands/myai-dev-docs.md +83 -0
  22. package/src/templates/codex/commands/myai-dev-review.md +85 -0
  23. package/src/templates/codex/commands/myai-dev-test.md +84 -0
  24. package/src/templates/codex/commands/myai-docusaurus-publish.md +42 -0
  25. package/src/templates/codex/commands/myai-git-hotfix.md +512 -0
  26. package/src/templates/codex/commands/myai-git-pr.md +196 -0
  27. package/src/templates/codex/commands/myai-git-release.md +516 -0
  28. package/src/templates/codex/commands/myai-git-sync.md +517 -0
  29. package/src/templates/codex/commands/myai-mintlify-publish.md +42 -0
  30. package/src/templates/codex/commands/myai-payloadcms-publish.md +42 -0
  31. package/src/templates/codex/commands/myai-sparc-workflow.md +185 -0
  32. package/src/templates/codex/commands/myai-wordpress-admin.md +143 -0
  33. package/src/templates/codex/commands/myai-wordpress-publish.md +66 -0
  34. package/src/templates/gemini/commands/myai-astro-publish.toml +76 -0
  35. package/src/templates/gemini/commands/myai-configure.toml +188 -0
  36. package/src/templates/gemini/commands/myai-content-writer.toml +76 -0
  37. package/src/templates/gemini/commands/myai-coolify-deploy.toml +138 -0
  38. package/src/templates/gemini/commands/myai-deploy-dev.toml +379 -0
  39. package/src/templates/gemini/commands/myai-deploy-prod.toml +438 -0
  40. package/src/templates/gemini/commands/myai-deploy-staging.toml +275 -0
  41. package/src/templates/gemini/commands/myai-dev-architect.toml +64 -0
  42. package/src/templates/gemini/commands/myai-dev-code.toml +75 -0
  43. package/src/templates/gemini/commands/myai-dev-docs.toml +76 -0
  44. package/src/templates/gemini/commands/myai-dev-review.toml +78 -0
  45. package/src/templates/gemini/commands/myai-dev-test.toml +77 -0
  46. package/src/templates/gemini/commands/myai-docusaurus-publish.toml +63 -0
  47. package/src/templates/gemini/commands/myai-git-hotfix.toml +953 -0
  48. package/src/templates/gemini/commands/myai-git-pr.toml +196 -0
  49. package/src/templates/gemini/commands/myai-git-release.toml +802 -0
  50. package/src/templates/gemini/commands/myai-git-sync.toml +792 -0
  51. package/src/templates/gemini/commands/myai-mintlify-publish.toml +67 -0
  52. package/src/templates/gemini/commands/myai-payloadcms-publish.toml +59 -0
  53. package/src/templates/gemini/commands/myai-sparc-workflow.toml +47 -0
  54. package/src/templates/gemini/commands/myai-wordpress-admin.toml +143 -0
  55. package/src/templates/gemini/commands/myai-wordpress-publish.toml +77 -0
@@ -0,0 +1,957 @@
1
+ ---
2
+ name: myai-git-hotfix
3
+ description: Create and deploy emergency hotfixes with fast-track procedures
4
+ tools: [bash, read, write]
5
+ ---
6
+
7
+ You are a hotfix automation assistant specializing in emergency production fixes with rapid deployment.
8
+
9
+ Task: Create and deploy hotfix - $ARGUMENTS
10
+
11
+ ## Hotfix Workflow
12
+
13
+ ### 1. Emergency Assessment
14
+
15
+ ```bash
16
+ assess_hotfix_urgency() {
17
+ echo "🚨 HOTFIX EMERGENCY ASSESSMENT"
18
+ echo "═══════════════════════════════════════"
19
+
20
+ # Gather incident information
21
+ read -p "Issue description: " issue_desc
22
+ read -p "Severity (critical/high/medium): " severity
23
+ read -p "Affected systems: " affected_systems
24
+ read -p "User impact: " user_impact
25
+
26
+ # Create incident record
27
+ incident_id="HOTFIX-$(date +%Y%m%d-%H%M%S)"
28
+
29
+ cat > ".hotfix-$incident_id.json" << EOF
30
+ {
31
+ "incident_id": "$incident_id",
32
+ "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)",
33
+ "severity": "$severity",
34
+ "description": "$issue_desc",
35
+ "affected_systems": "$affected_systems",
36
+ "user_impact": "$user_impact",
37
+ "status": "initiated"
38
+ }
39
+ EOF
40
+
41
+ echo ""
42
+ echo "╔══════════════════════════════════════════════════════════╗"
43
+ echo "║ HOTFIX INCIDENT CREATED ║"
44
+ echo "╚══════════════════════════════════════════════════════════╝"
45
+ echo "Incident ID: $incident_id"
46
+ echo "Severity: $severity"
47
+ echo "Description: $issue_desc"
48
+ echo ""
49
+
50
+ # Alert team
51
+ send_hotfix_alert "$incident_id" "initiated" "$severity" "$issue_desc"
52
+
53
+ echo "$incident_id"
54
+ }
55
+
56
+ # Create incident
57
+ incident_id=$(assess_hotfix_urgency)
58
+ ```
59
+
60
+ ### 2. Create Hotfix Branch from Production
61
+
62
+ ```bash
63
+ create_hotfix_branch() {
64
+ local incident_id=$1
65
+ local hotfix_branch="hotfix/$incident_id"
66
+
67
+ echo "🔧 Creating hotfix branch from production..."
68
+
69
+ # Fetch latest
70
+ git fetch --all
71
+
72
+ # Determine production branch/tag
73
+ if git show-ref --verify --quiet refs/heads/production; then
74
+ base_branch="production"
75
+ elif git show-ref --verify --quiet refs/heads/main; then
76
+ base_branch="main"
77
+ else
78
+ base_branch="master"
79
+ fi
80
+
81
+ # Get production tag (most recent release)
82
+ latest_prod_tag=$(git tag --sort=-creatordate | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | head -1)
83
+
84
+ if [ -n "$latest_prod_tag" ]; then
85
+ echo "🏷️ Creating hotfix from production tag: $latest_prod_tag"
86
+ base_ref="$latest_prod_tag"
87
+ else
88
+ echo "📍 Creating hotfix from $base_branch branch"
89
+ base_ref="origin/$base_branch"
90
+ fi
91
+
92
+ # Create hotfix branch
93
+ git checkout -b "$hotfix_branch" "$base_ref" || {
94
+ echo "❌ Failed to create hotfix branch"
95
+ exit 1
96
+ }
97
+
98
+ echo "✅ Hotfix branch created: $hotfix_branch"
99
+ echo "📍 Base: $base_ref"
100
+
101
+ # Update incident record
102
+ jq ".hotfix_branch = \"$hotfix_branch\" | .base_ref = \"$base_ref\"" \
103
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
104
+
105
+ echo "$hotfix_branch"
106
+ }
107
+
108
+ # Create hotfix branch
109
+ hotfix_branch=$(create_hotfix_branch "$incident_id")
110
+ ```
111
+
112
+ ### 3. Apply Hotfix (Guided)
113
+
114
+ ```bash
115
+ apply_hotfix() {
116
+ local incident_id=$1
117
+ local hotfix_branch=$2
118
+
119
+ echo "🔧 Applying hotfix..."
120
+ echo ""
121
+ echo "Options:"
122
+ echo " 1. Apply existing patch file"
123
+ echo " 2. Make manual code changes"
124
+ echo " 3. Cherry-pick from another branch"
125
+ echo " 4. Revert specific commit"
126
+ echo ""
127
+
128
+ read -p "Choose option (1-4): " fix_option
129
+
130
+ case $fix_option in
131
+ 1)
132
+ # Apply patch file
133
+ read -p "Enter patch file path: " patch_file
134
+ if [ -f "$patch_file" ]; then
135
+ git apply "$patch_file" || {
136
+ echo "❌ Failed to apply patch"
137
+ exit 1
138
+ }
139
+ git add -A
140
+ git commit -m "hotfix: apply patch from $patch_file"
141
+ else
142
+ echo "❌ Patch file not found"
143
+ exit 1
144
+ fi
145
+ ;;
146
+
147
+ 2)
148
+ # Manual changes
149
+ echo "📝 Make your code changes now"
150
+ echo "Press Enter when ready to continue..."
151
+ read
152
+
153
+ if git diff-index --quiet HEAD --; then
154
+ echo "⚠️ No changes detected"
155
+ exit 1
156
+ fi
157
+
158
+ git add -A
159
+
160
+ read -p "Commit message: " commit_msg
161
+ git commit -m "hotfix: $commit_msg"
162
+ ;;
163
+
164
+ 3)
165
+ # Cherry-pick
166
+ read -p "Enter commit hash to cherry-pick: " commit_hash
167
+ git cherry-pick "$commit_hash" || {
168
+ echo "❌ Cherry-pick failed"
169
+ echo "Resolve conflicts and run: git cherry-pick --continue"
170
+ exit 1
171
+ }
172
+ ;;
173
+
174
+ 4)
175
+ # Revert commit
176
+ read -p "Enter commit hash to revert: " commit_hash
177
+ git revert "$commit_hash" --no-edit || {
178
+ echo "❌ Revert failed"
179
+ exit 1
180
+ }
181
+ ;;
182
+
183
+ *)
184
+ echo "Invalid option"
185
+ exit 1
186
+ ;;
187
+ esac
188
+
189
+ echo "✅ Hotfix applied"
190
+
191
+ # Update incident record
192
+ jq ".status = \"fix_applied\"" ".hotfix-$incident_id.json" > temp.json && \
193
+ mv temp.json ".hotfix-$incident_id.json"
194
+ }
195
+
196
+ # Apply fix
197
+ apply_hotfix "$incident_id" "$hotfix_branch"
198
+ ```
199
+
200
+ ### 4. Fast-Track Testing
201
+
202
+ ```bash
203
+ fast_track_testing() {
204
+ local incident_id=$1
205
+
206
+ echo "🧪 Running fast-track tests..."
207
+
208
+ # Critical tests only
209
+ echo "Running critical test suite..."
210
+
211
+ # Unit tests
212
+ if command -v npm &>/dev/null && grep -q "\"test:critical\"" package.json 2>/dev/null; then
213
+ npm run test:critical || {
214
+ echo "❌ CRITICAL: Tests failed"
215
+ exit 1
216
+ }
217
+ elif command -v npm &>/dev/null; then
218
+ npm test || {
219
+ echo "❌ CRITICAL: Tests failed"
220
+ exit 1
221
+ }
222
+ fi
223
+
224
+ # Security audit (quick)
225
+ if command -v npm &>/dev/null; then
226
+ echo "Running security audit..."
227
+ npm audit --production --audit-level=high || {
228
+ echo "⚠️ Security issues detected (non-blocking)"
229
+ }
230
+ fi
231
+
232
+ # Build test
233
+ echo "Testing build..."
234
+ if command -v npm &>/dev/null && grep -q "\"build\"" package.json 2>/dev/null; then
235
+ npm run build || {
236
+ echo "❌ CRITICAL: Build failed"
237
+ exit 1
238
+ }
239
+ fi
240
+
241
+ # Smoke test (if available)
242
+ if command -v npm &>/dev/null && grep -q "\"test:smoke\"" package.json 2>/dev/null; then
243
+ echo "Running smoke tests..."
244
+ npm run test:smoke || {
245
+ echo "⚠️ Smoke tests failed (review required)"
246
+ }
247
+ fi
248
+
249
+ echo "✅ Fast-track tests passed"
250
+
251
+ # Update incident record
252
+ jq ".status = \"tested\" | .tests_passed = true" \
253
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
254
+ }
255
+
256
+ # Run tests
257
+ fast_track_testing "$incident_id"
258
+ ```
259
+
260
+ ### 5. Emergency Approval
261
+
262
+ ```bash
263
+ request_hotfix_approval() {
264
+ local incident_id=$1
265
+ local hotfix_branch=$2
266
+
267
+ echo ""
268
+ echo "╔══════════════════════════════════════════════════════════╗"
269
+ echo "║ 🚨 EMERGENCY HOTFIX APPROVAL 🚨 ║"
270
+ echo "╚══════════════════════════════════════════════════════════╝"
271
+ echo ""
272
+ echo "Incident ID: $incident_id"
273
+ echo "Hotfix Branch: $hotfix_branch"
274
+ echo ""
275
+
276
+ # Show changes
277
+ echo "Changes:"
278
+ git diff HEAD~1 --stat
279
+ echo ""
280
+
281
+ # Show commits
282
+ echo "Commits:"
283
+ git log --oneline -5
284
+ echo ""
285
+
286
+ # Load incident info
287
+ if [ -f ".hotfix-$incident_id.json" ]; then
288
+ severity=$(jq -r '.severity' ".hotfix-$incident_id.json")
289
+ description=$(jq -r '.description' ".hotfix-$incident_id.json")
290
+
291
+ echo "Severity: $severity"
292
+ echo "Description: $description"
293
+ echo ""
294
+ fi
295
+
296
+ # Require explicit approval
297
+ if [ "$severity" == "critical" ]; then
298
+ read -p "Type 'EMERGENCY DEPLOY' to approve: " approval
299
+ required_text="EMERGENCY DEPLOY"
300
+ else
301
+ read -p "Type 'DEPLOY HOTFIX' to approve: " approval
302
+ required_text="DEPLOY HOTFIX"
303
+ fi
304
+
305
+ if [ "$approval" != "$required_text" ]; then
306
+ echo "❌ Deployment cancelled"
307
+ exit 1
308
+ fi
309
+
310
+ echo "✅ Emergency deployment approved"
311
+
312
+ # Update incident record
313
+ jq ".status = \"approved\" | .approved_by = \"$(git config user.name)\" | .approved_at = \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"" \
314
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
315
+ }
316
+
317
+ # Request approval
318
+ request_hotfix_approval "$incident_id" "$hotfix_branch"
319
+ ```
320
+
321
+ ### 6. Create Hotfix Release
322
+
323
+ ```bash
324
+ create_hotfix_release() {
325
+ local incident_id=$1
326
+ local hotfix_branch=$2
327
+
328
+ echo "📦 Creating hotfix release..."
329
+
330
+ # Determine current version from production
331
+ if [ -f "package.json" ]; then
332
+ current_version=$(jq -r '.version' package.json)
333
+ else
334
+ current_version=$(git describe --tags --abbrev=0 | sed 's/^v//')
335
+ fi
336
+
337
+ # Increment patch version
338
+ IFS='.' read -r major minor patch <<< "$current_version"
339
+ patch=$((patch + 1))
340
+ new_version="$major.$minor.$patch"
341
+
342
+ echo "Current version: $current_version"
343
+ echo "New hotfix version: $new_version"
344
+
345
+ # Update version files
346
+ if [ -f "package.json" ]; then
347
+ jq ".version = \"$new_version\"" package.json > package.json.tmp
348
+ mv package.json.tmp package.json
349
+ git add package.json
350
+
351
+ if [ -f "package-lock.json" ]; then
352
+ jq ".version = \"$new_version\"" package-lock.json > package-lock.json.tmp
353
+ mv package-lock.json.tmp package-lock.json
354
+ git add package-lock.json
355
+ fi
356
+ fi
357
+
358
+ # Create release commit
359
+ git commit -m "chore(hotfix): release v$new_version
360
+
361
+ Incident: $incident_id
362
+ Emergency hotfix deployment
363
+
364
+ 🚨 HOTFIX RELEASE"
365
+
366
+ # Create tag
367
+ git tag -a "v$new_version" -m "Hotfix v$new_version
368
+
369
+ Incident: $incident_id
370
+ Emergency production fix"
371
+
372
+ echo "✅ Hotfix release created: v$new_version"
373
+
374
+ # Update incident record
375
+ jq ".hotfix_version = \"$new_version\" | .status = \"released\"" \
376
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
377
+
378
+ echo "$new_version"
379
+ }
380
+
381
+ # Create release
382
+ hotfix_version=$(create_hotfix_release "$incident_id" "$hotfix_branch")
383
+ ```
384
+
385
+ ### 7. Emergency Deployment
386
+
387
+ ```bash
388
+ emergency_deploy() {
389
+ local incident_id=$1
390
+ local hotfix_version=$2
391
+
392
+ echo "🚀 EMERGENCY DEPLOYMENT TO PRODUCTION"
393
+ echo "═══════════════════════════════════════"
394
+
395
+ # Update incident
396
+ jq ".status = \"deploying\"" ".hotfix-$incident_id.json" > temp.json && \
397
+ mv temp.json ".hotfix-$incident_id.json"
398
+
399
+ # Send pre-deployment alert
400
+ send_hotfix_alert "$incident_id" "deploying" "critical" "Emergency deployment in progress"
401
+
402
+ # Deployment method selection
403
+ if [ -n "$COOLIFY_URL" ] && [ -n "$COOLIFY_PROD_APP_ID" ]; then
404
+ deploy_via_coolify "$hotfix_version"
405
+ elif [ -n "$DOCKER_REGISTRY" ]; then
406
+ deploy_via_docker "$hotfix_version"
407
+ else
408
+ echo "❌ No deployment method configured"
409
+ exit 1
410
+ fi
411
+
412
+ # Update incident
413
+ jq ".status = \"deployed\" | .deployed_at = \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"" \
414
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
415
+ }
416
+
417
+ deploy_via_coolify() {
418
+ local version=$1
419
+
420
+ echo "🚀 Deploying via Coolify..."
421
+
422
+ # Trigger emergency deployment
423
+ response=$(curl -s -w "\n%{http_code}" -X POST "$COOLIFY_URL/api/v1/deploy" \
424
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
425
+ -H "Content-Type: application/json" \
426
+ -d "{
427
+ \"application_id\": \"$COOLIFY_PROD_APP_ID\",
428
+ \"commit\": \"$(git rev-parse HEAD)\",
429
+ \"force\": true,
430
+ \"tag\": \"v$version\"
431
+ }")
432
+
433
+ http_code=$(echo "$response" | tail -1)
434
+
435
+ if [ "$http_code" -ne 200 ] && [ "$http_code" -ne 201 ]; then
436
+ echo "❌ Deployment trigger failed"
437
+ exit 1
438
+ fi
439
+
440
+ echo "✅ Deployment triggered via Coolify"
441
+
442
+ # Monitor deployment (quick check)
443
+ echo "📊 Monitoring deployment..."
444
+ sleep 30
445
+
446
+ # Quick health check
447
+ if curl -f -s "$PROD_URL/health" > /dev/null; then
448
+ echo "✅ Application responding"
449
+ else
450
+ echo "❌ CRITICAL: Application not responding"
451
+ echo "🔄 Consider emergency rollback"
452
+ exit 1
453
+ fi
454
+ }
455
+
456
+ deploy_via_docker() {
457
+ local version=$1
458
+
459
+ echo "🐳 Deploying via Docker..."
460
+
461
+ # Build and push
462
+ docker build -t "$DOCKER_REGISTRY/app:v$version" .
463
+ docker push "$DOCKER_REGISTRY/app:v$version"
464
+
465
+ # Tag as production
466
+ docker tag "$DOCKER_REGISTRY/app:v$version" "$DOCKER_REGISTRY/app:prod"
467
+ docker push "$DOCKER_REGISTRY/app:prod"
468
+
469
+ # Deploy to production
470
+ ssh prod-server << EOF
471
+ docker pull $DOCKER_REGISTRY/app:v$version
472
+
473
+ # Create backup
474
+ docker tag app-prod app-prod-backup
475
+
476
+ # Update production
477
+ docker stop app-prod
478
+ docker rm app-prod
479
+ docker run -d \
480
+ --name app-prod \
481
+ --restart unless-stopped \
482
+ -p 3000:3000 \
483
+ --env-file /etc/app/prod.env \
484
+ $DOCKER_REGISTRY/app:v$version
485
+ EOF
486
+
487
+ echo "✅ Deployed via Docker"
488
+
489
+ # Quick health check
490
+ sleep 10
491
+ if curl -f -s "$PROD_URL/health" > /dev/null; then
492
+ echo "✅ Application responding"
493
+ else
494
+ echo "❌ CRITICAL: Application not responding"
495
+ exit 1
496
+ fi
497
+ }
498
+
499
+ # Deploy
500
+ emergency_deploy "$incident_id" "$hotfix_version"
501
+ ```
502
+
503
+ ### 8. Post-Deployment Verification
504
+
505
+ ```bash
506
+ verify_hotfix() {
507
+ local incident_id=$1
508
+ local hotfix_version=$2
509
+
510
+ echo "🔍 Verifying hotfix deployment..."
511
+
512
+ # Wait for stabilization
513
+ echo "⏳ Waiting for deployment to stabilize (30s)..."
514
+ sleep 30
515
+
516
+ # Health check
517
+ echo "🏥 Health check..."
518
+ if ! curl -f -s "$PROD_URL/health" > /dev/null; then
519
+ echo "❌ CRITICAL: Health check failed"
520
+ initiate_emergency_rollback "$incident_id"
521
+ exit 1
522
+ fi
523
+ echo "✅ Health check passed"
524
+
525
+ # API endpoints check
526
+ echo "🔌 API endpoints check..."
527
+ if ! curl -f -s "$PROD_URL/api/status" > /dev/null; then
528
+ echo "⚠️ API check failed"
529
+ else
530
+ echo "✅ API responding"
531
+ fi
532
+
533
+ # Quick smoke test
534
+ if command -v npm &>/dev/null && grep -q "\"test:smoke:prod\"" package.json 2>/dev/null; then
535
+ echo "🧪 Running production smoke tests..."
536
+ npm run test:smoke:prod || {
537
+ echo "⚠️ Smoke tests failed"
538
+ read -p "Continue or rollback? (continue/rollback): " decision
539
+ if [ "$decision" == "rollback" ]; then
540
+ initiate_emergency_rollback "$incident_id"
541
+ exit 1
542
+ fi
543
+ }
544
+ fi
545
+
546
+ # Monitor error rates
547
+ echo "📊 Monitoring error rates (2 minutes)..."
548
+ sleep 120
549
+
550
+ # Check if issue is resolved
551
+ echo ""
552
+ read -p "Is the original issue resolved? (yes/no): " issue_resolved
553
+
554
+ if [ "$issue_resolved" != "yes" ]; then
555
+ echo "⚠️ Issue not resolved"
556
+ read -p "Rollback? (yes/no): " do_rollback
557
+ if [ "$do_rollback" == "yes" ]; then
558
+ initiate_emergency_rollback "$incident_id"
559
+ exit 1
560
+ fi
561
+ fi
562
+
563
+ echo "✅ Hotfix verification complete"
564
+
565
+ # Update incident
566
+ jq ".status = \"verified\" | .issue_resolved = true" \
567
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
568
+ }
569
+
570
+ # Verify deployment
571
+ verify_hotfix "$incident_id" "$hotfix_version"
572
+ ```
573
+
574
+ ### 9. Emergency Rollback
575
+
576
+ ```bash
577
+ initiate_emergency_rollback() {
578
+ local incident_id=$1
579
+
580
+ echo "🚨 INITIATING EMERGENCY ROLLBACK"
581
+ echo "═══════════════════════════════════════"
582
+
583
+ # Alert team
584
+ send_hotfix_alert "$incident_id" "rolling_back" "critical" "Emergency rollback in progress"
585
+
586
+ # Get previous version
587
+ previous_version=$(git tag --sort=-creatordate | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$" | sed -n '2p')
588
+
589
+ if [ -z "$previous_version" ]; then
590
+ echo "❌ Cannot determine previous version"
591
+ exit 1
592
+ fi
593
+
594
+ echo "Rolling back to: $previous_version"
595
+
596
+ # Rollback via Coolify
597
+ if [ -n "$COOLIFY_URL" ]; then
598
+ curl -X POST "$COOLIFY_URL/api/v1/deploy" \
599
+ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \
600
+ -H "Content-Type: application/json" \
601
+ -d "{
602
+ \"application_id\": \"$COOLIFY_PROD_APP_ID\",
603
+ \"tag\": \"$previous_version\",
604
+ \"force\": true
605
+ }"
606
+
607
+ sleep 30
608
+ fi
609
+
610
+ # Rollback via Docker
611
+ if [ -n "$DOCKER_REGISTRY" ]; then
612
+ ssh prod-server << EOF
613
+ docker stop app-prod
614
+ docker rm app-prod
615
+ docker run -d \
616
+ --name app-prod \
617
+ --restart unless-stopped \
618
+ -p 3000:3000 \
619
+ --env-file /etc/app/prod.env \
620
+ app-prod-backup || $DOCKER_REGISTRY/app:$previous_version
621
+ EOF
622
+
623
+ sleep 10
624
+ fi
625
+
626
+ # Verify rollback
627
+ if curl -f -s "$PROD_URL/health" > /dev/null; then
628
+ echo "✅ Rollback successful"
629
+ send_hotfix_alert "$incident_id" "rolled_back" "high" "Successfully rolled back to $previous_version"
630
+ else
631
+ echo "❌ CRITICAL: Rollback verification failed"
632
+ echo "🚨 Manual intervention required immediately"
633
+ send_hotfix_alert "$incident_id" "rollback_failed" "critical" "ROLLBACK FAILED - Manual intervention needed"
634
+ exit 1
635
+ fi
636
+
637
+ # Update incident
638
+ jq ".status = \"rolled_back\" | .rollback_version = \"$previous_version\"" \
639
+ ".hotfix-$incident_id.json" > temp.json && mv temp.json ".hotfix-$incident_id.json"
640
+ }
641
+ ```
642
+
643
+ ### 10. Merge Hotfix Back
644
+
645
+ ```bash
646
+ merge_hotfix_back() {
647
+ local incident_id=$1
648
+ local hotfix_branch=$2
649
+ local hotfix_version=$3
650
+
651
+ echo "🔀 Merging hotfix back to main branches..."
652
+
653
+ # Push hotfix branch
654
+ git push origin "$hotfix_branch"
655
+ git push origin "v$hotfix_version"
656
+
657
+ # Merge to main/master
658
+ main_branch=$(git show-ref --verify --quiet refs/heads/main && echo "main" || echo "master")
659
+
660
+ echo "Merging to $main_branch..."
661
+ git checkout "$main_branch"
662
+ git pull origin "$main_branch"
663
+ git merge "$hotfix_branch" --no-edit
664
+
665
+ # Push main
666
+ git push origin "$main_branch"
667
+
668
+ # Merge to develop if exists
669
+ if git show-ref --verify --quiet refs/heads/develop; then
670
+ echo "Merging to develop..."
671
+ git checkout develop
672
+ git pull origin develop
673
+ git merge "$hotfix_branch" --no-edit
674
+ git push origin develop
675
+ fi
676
+
677
+ # Merge to dev if exists
678
+ if git show-ref --verify --quiet refs/heads/dev; then
679
+ echo "Merging to dev..."
680
+ git checkout dev
681
+ git pull origin dev
682
+ git merge "$hotfix_branch" --no-edit
683
+ git push origin dev
684
+ fi
685
+
686
+ # Delete hotfix branch
687
+ read -p "Delete hotfix branch? (yes/no): " delete_branch
688
+ if [ "$delete_branch" == "yes" ]; then
689
+ git branch -d "$hotfix_branch"
690
+ git push origin --delete "$hotfix_branch"
691
+ echo "✅ Hotfix branch deleted"
692
+ fi
693
+
694
+ echo "✅ Hotfix merged back to main branches"
695
+ }
696
+
697
+ # Merge back
698
+ merge_hotfix_back "$incident_id" "$hotfix_branch" "$hotfix_version"
699
+ ```
700
+
701
+ ### 11. Post-Mortem Report
702
+
703
+ ```bash
704
+ generate_post_mortem() {
705
+ local incident_id=$1
706
+
707
+ echo "📝 Generating post-mortem report..."
708
+
709
+ # Load incident data
710
+ if [ ! -f ".hotfix-$incident_id.json" ]; then
711
+ echo "❌ Incident record not found"
712
+ return
713
+ fi
714
+
715
+ incident_data=$(cat ".hotfix-$incident_id.json")
716
+
717
+ # Create post-mortem
718
+ cat > "post-mortem-$incident_id.md" << EOF
719
+ # Post-Mortem: $incident_id
720
+
721
+ **Date:** $(date +%Y-%m-%d)
722
+ **Severity:** $(echo "$incident_data" | jq -r '.severity')
723
+ **Status:** $(echo "$incident_data" | jq -r '.status')
724
+
725
+ ## Incident Summary
726
+
727
+ $(echo "$incident_data" | jq -r '.description')
728
+
729
+ ## Timeline
730
+
731
+ - **Initiated:** $(echo "$incident_data" | jq -r '.timestamp')
732
+ - **Fix Applied:** $(echo "$incident_data" | jq -r '.status')
733
+ - **Deployed:** $(echo "$incident_data" | jq -r '.deployed_at // "N/A"')
734
+ - **Verified:** $(echo "$incident_data" | jq -r '.verified_at // "N/A"')
735
+
736
+ ## Technical Details
737
+
738
+ - **Hotfix Version:** $(echo "$incident_data" | jq -r '.hotfix_version')
739
+ - **Base Version:** $(echo "$incident_data" | jq -r '.base_ref')
740
+ - **Hotfix Branch:** $(echo "$incident_data" | jq -r '.hotfix_branch')
741
+
742
+ ## Impact
743
+
744
+ - **Affected Systems:** $(echo "$incident_data" | jq -r '.affected_systems')
745
+ - **User Impact:** $(echo "$incident_data" | jq -r '.user_impact')
746
+
747
+ ## Resolution
748
+
749
+ $(echo "$incident_data" | jq -r '.issue_resolved // false' | \
750
+ sed 's/true/Issue successfully resolved/;s/false/Issue partially resolved/')
751
+
752
+ ## Changes Made
753
+
754
+ \`\`\`
755
+ $(git diff "v$(echo "$incident_data" | jq -r '.hotfix_version')^..v$(echo "$incident_data" | jq -r '.hotfix_version')" --stat)
756
+ \`\`\`
757
+
758
+ ## Lessons Learned
759
+
760
+ [To be filled by team]
761
+
762
+ ## Action Items
763
+
764
+ - [ ] Root cause analysis
765
+ - [ ] Update monitoring/alerts
766
+ - [ ] Add preventive measures
767
+ - [ ] Update documentation
768
+ - [ ] Team debrief
769
+
770
+ ## Approval
771
+
772
+ - **Approved By:** $(echo "$incident_data" | jq -r '.approved_by // "N/A"')
773
+ - **Approved At:** $(echo "$incident_data" | jq -r '.approved_at // "N/A"')
774
+
775
+ EOF
776
+
777
+ echo "✅ Post-mortem created: post-mortem-$incident_id.md"
778
+
779
+ # Clean up incident record
780
+ mv ".hotfix-$incident_id.json" "incident-$incident_id.json"
781
+ }
782
+
783
+ # Generate post-mortem
784
+ generate_post_mortem "$incident_id"
785
+ ```
786
+
787
+ ### 12. Hotfix Notification
788
+
789
+ ```bash
790
+ send_hotfix_alert() {
791
+ local incident_id=$1
792
+ local status=$2
793
+ local severity=$3
794
+ local message=$4
795
+
796
+ # Determine color based on severity
797
+ case $severity in
798
+ critical) color="16711680" ;; # Red
799
+ high) color="16744192" ;; # Orange
800
+ medium) color="16776960" ;; # Yellow
801
+ *) color="8421504" ;; # Gray
802
+ esac
803
+
804
+ # Slack notification
805
+ if [ -n "$SLACK_WEBHOOK_URL" ]; then
806
+ curl -X POST "$SLACK_WEBHOOK_URL" \
807
+ -H 'Content-Type: application/json' \
808
+ -d "{
809
+ \"text\": \"🚨 HOTFIX ALERT\",
810
+ \"blocks\": [
811
+ {
812
+ \"type\": \"header\",
813
+ \"text\": {
814
+ \"type\": \"plain_text\",
815
+ \"text\": \"🚨 HOTFIX: $incident_id\"
816
+ }
817
+ },
818
+ {
819
+ \"type\": \"section\",
820
+ \"fields\": [
821
+ {\"type\": \"mrkdwn\", \"text\": \"*Status:*\n$status\"},
822
+ {\"type\": \"mrkdwn\", \"text\": \"*Severity:*\n$severity\"},
823
+ {\"type\": \"mrkdwn\", \"text\": \"*Message:*\n$message\"}
824
+ ]
825
+ }
826
+ ]
827
+ }"
828
+ fi
829
+
830
+ # Discord notification (with @everyone for critical)
831
+ if [ -n "$DISCORD_WEBHOOK_URL" ]; then
832
+ mention=""
833
+ if [ "$severity" == "critical" ]; then
834
+ mention="@everyone "
835
+ fi
836
+
837
+ curl -X POST "$DISCORD_WEBHOOK_URL" \
838
+ -H 'Content-Type: application/json' \
839
+ -d "{
840
+ \"content\": \"${mention}🚨 **HOTFIX ALERT**\",
841
+ \"embeds\": [{
842
+ \"title\": \"Incident: $incident_id\",
843
+ \"fields\": [
844
+ {\"name\": \"Status\", \"value\": \"$status\", \"inline\": true},
845
+ {\"name\": \"Severity\", \"value\": \"$severity\", \"inline\": true},
846
+ {\"name\": \"Message\", \"value\": \"$message\"}
847
+ ],
848
+ \"color\": $color,
849
+ \"timestamp\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\"
850
+ }]
851
+ }"
852
+ fi
853
+
854
+ # PagerDuty integration (for critical)
855
+ if [ "$severity" == "critical" ] && [ -n "$PAGERDUTY_API_KEY" ]; then
856
+ curl -X POST "https://api.pagerduty.com/incidents" \
857
+ -H "Authorization: Token token=$PAGERDUTY_API_KEY" \
858
+ -H "Content-Type: application/json" \
859
+ -d "{
860
+ \"incident\": {
861
+ \"type\": \"incident\",
862
+ \"title\": \"HOTFIX: $incident_id\",
863
+ \"service\": {\"id\": \"$PAGERDUTY_SERVICE_ID\", \"type\": \"service_reference\"},
864
+ \"urgency\": \"high\",
865
+ \"body\": {\"type\": \"incident_body\", \"details\": \"$message\"}
866
+ }
867
+ }"
868
+ fi
869
+ }
870
+ ```
871
+
872
+ ## Complete Hotfix Script
873
+
874
+ ```bash
875
+ #!/bin/bash
876
+ set -e
877
+
878
+ echo "🚨 EMERGENCY HOTFIX PROCEDURE"
879
+ echo "═══════════════════════════════════════"
880
+
881
+ # 1. Assess emergency
882
+ incident_id=$(assess_hotfix_urgency)
883
+
884
+ # 2. Create hotfix branch from production
885
+ hotfix_branch=$(create_hotfix_branch "$incident_id")
886
+
887
+ # 3. Apply fix
888
+ apply_hotfix "$incident_id" "$hotfix_branch"
889
+
890
+ # 4. Fast-track testing
891
+ fast_track_testing "$incident_id"
892
+
893
+ # 5. Request approval
894
+ request_hotfix_approval "$incident_id" "$hotfix_branch"
895
+
896
+ # 6. Create release
897
+ hotfix_version=$(create_hotfix_release "$incident_id" "$hotfix_branch")
898
+
899
+ # 7. Emergency deploy
900
+ emergency_deploy "$incident_id" "$hotfix_version"
901
+
902
+ # 8. Verify deployment
903
+ verify_hotfix "$incident_id" "$hotfix_version"
904
+
905
+ # 9. Merge back
906
+ merge_hotfix_back "$incident_id" "$hotfix_branch" "$hotfix_version"
907
+
908
+ # 10. Generate post-mortem
909
+ generate_post_mortem "$incident_id"
910
+
911
+ # 11. Final notification
912
+ send_hotfix_alert "$incident_id" "completed" "high" "Hotfix v$hotfix_version deployed and verified"
913
+
914
+ echo "✅ HOTFIX COMPLETE"
915
+ echo "Incident ID: $incident_id"
916
+ echo "Version: v$hotfix_version"
917
+ ```
918
+
919
+ ## Quick Hotfix Commands
920
+
921
+ ```bash
922
+ # Start hotfix procedure
923
+ /myai-git-hotfix
924
+
925
+ # Emergency rollback
926
+ /myai-git-hotfix --rollback
927
+
928
+ # Generate post-mortem only
929
+ /myai-git-hotfix --post-mortem <incident-id>
930
+ ```
931
+
932
+ ## Environment Configuration
933
+
934
+ ```bash
935
+ # Production
936
+ PROD_URL=https://your-app.com
937
+
938
+ # Coolify
939
+ COOLIFY_URL=https://coolify.your-server.com
940
+ COOLIFY_API_TOKEN=your_token
941
+ COOLIFY_PROD_APP_ID=your_app_id
942
+
943
+ # Docker
944
+ DOCKER_REGISTRY=registry.your-domain.com
945
+
946
+ # Notifications (CRITICAL)
947
+ SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/WEBHOOK
948
+ DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR/WEBHOOK
949
+ PAGERDUTY_API_KEY=your_pagerduty_key
950
+ PAGERDUTY_SERVICE_ID=your_service_id
951
+
952
+ # Team
953
+ ONCALL_EMAIL=oncall@yourcompany.com
954
+ TEAM_CHANNEL=#incidents
955
+ ```
956
+
957
+ Execute emergency hotfix procedure with fast-track deployment and rollback safeguards.