ai-flow-dev 2.7.0 → 2.8.0

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 (171) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +573 -570
  3. package/package.json +74 -74
  4. package/prompts/backend/flow-build-phase-0.md +535 -535
  5. package/prompts/backend/flow-build-phase-1.md +626 -626
  6. package/prompts/backend/flow-build-phase-10.md +340 -340
  7. package/prompts/backend/flow-build-phase-2.md +573 -573
  8. package/prompts/backend/flow-build-phase-3.md +834 -834
  9. package/prompts/backend/flow-build-phase-4.md +554 -554
  10. package/prompts/backend/flow-build-phase-5.md +703 -703
  11. package/prompts/backend/flow-build-phase-6.md +524 -524
  12. package/prompts/backend/flow-build-phase-7.md +1001 -1001
  13. package/prompts/backend/flow-build-phase-8.md +1407 -1407
  14. package/prompts/backend/flow-build-phase-9.md +477 -477
  15. package/prompts/backend/flow-build.md +137 -137
  16. package/prompts/backend/flow-check-review.md +656 -20
  17. package/prompts/backend/flow-check-test.md +526 -14
  18. package/prompts/backend/flow-check.md +725 -67
  19. package/prompts/backend/flow-commit.md +88 -119
  20. package/prompts/backend/flow-docs-sync.md +354 -354
  21. package/prompts/backend/flow-finish.md +919 -0
  22. package/prompts/backend/flow-release.md +949 -0
  23. package/prompts/backend/flow-work-feature.md +61 -61
  24. package/prompts/backend/flow-work-fix.md +46 -46
  25. package/prompts/backend/flow-work-refactor.md +48 -48
  26. package/prompts/backend/flow-work-resume.md +34 -34
  27. package/prompts/backend/flow-work.md +1098 -1286
  28. package/prompts/desktop/flow-build-phase-0.md +359 -359
  29. package/prompts/desktop/flow-build-phase-1.md +295 -295
  30. package/prompts/desktop/flow-build-phase-10.md +357 -357
  31. package/prompts/desktop/flow-build-phase-2.md +282 -282
  32. package/prompts/desktop/flow-build-phase-3.md +291 -291
  33. package/prompts/desktop/flow-build-phase-4.md +308 -308
  34. package/prompts/desktop/flow-build-phase-5.md +269 -269
  35. package/prompts/desktop/flow-build-phase-6.md +350 -350
  36. package/prompts/desktop/flow-build-phase-7.md +297 -297
  37. package/prompts/desktop/flow-build-phase-8.md +541 -541
  38. package/prompts/desktop/flow-build-phase-9.md +439 -439
  39. package/prompts/desktop/flow-build.md +156 -156
  40. package/prompts/desktop/flow-check-review.md +656 -20
  41. package/prompts/desktop/flow-check-test.md +526 -14
  42. package/prompts/desktop/flow-check.md +725 -67
  43. package/prompts/desktop/flow-commit.md +88 -119
  44. package/prompts/desktop/flow-docs-sync.md +354 -354
  45. package/prompts/desktop/flow-finish.md +910 -0
  46. package/prompts/desktop/flow-release.md +662 -0
  47. package/prompts/desktop/flow-work-feature.md +61 -61
  48. package/prompts/desktop/flow-work-fix.md +46 -46
  49. package/prompts/desktop/flow-work-refactor.md +48 -48
  50. package/prompts/desktop/flow-work-resume.md +34 -34
  51. package/prompts/desktop/flow-work.md +1202 -1390
  52. package/prompts/frontend/flow-build-phase-0.md +425 -425
  53. package/prompts/frontend/flow-build-phase-1.md +626 -626
  54. package/prompts/frontend/flow-build-phase-10.md +33 -33
  55. package/prompts/frontend/flow-build-phase-2.md +573 -573
  56. package/prompts/frontend/flow-build-phase-3.md +782 -782
  57. package/prompts/frontend/flow-build-phase-4.md +554 -554
  58. package/prompts/frontend/flow-build-phase-5.md +703 -703
  59. package/prompts/frontend/flow-build-phase-6.md +524 -524
  60. package/prompts/frontend/flow-build-phase-7.md +1001 -1001
  61. package/prompts/frontend/flow-build-phase-8.md +872 -872
  62. package/prompts/frontend/flow-build-phase-9.md +94 -94
  63. package/prompts/frontend/flow-build.md +137 -137
  64. package/prompts/frontend/flow-check-review.md +656 -20
  65. package/prompts/frontend/flow-check-test.md +526 -14
  66. package/prompts/frontend/flow-check.md +725 -67
  67. package/prompts/frontend/flow-commit.md +88 -119
  68. package/prompts/frontend/flow-docs-sync.md +550 -550
  69. package/prompts/frontend/flow-finish.md +910 -0
  70. package/prompts/frontend/flow-release.md +519 -0
  71. package/prompts/frontend/flow-work-api.md +1540 -0
  72. package/prompts/frontend/flow-work-feature.md +61 -61
  73. package/prompts/frontend/flow-work-fix.md +38 -38
  74. package/prompts/frontend/flow-work-refactor.md +48 -48
  75. package/prompts/frontend/flow-work-resume.md +34 -34
  76. package/prompts/frontend/flow-work.md +1583 -1320
  77. package/prompts/mobile/flow-build-phase-0.md +425 -425
  78. package/prompts/mobile/flow-build-phase-1.md +626 -626
  79. package/prompts/mobile/flow-build-phase-10.md +32 -32
  80. package/prompts/mobile/flow-build-phase-2.md +573 -573
  81. package/prompts/mobile/flow-build-phase-3.md +782 -782
  82. package/prompts/mobile/flow-build-phase-4.md +554 -554
  83. package/prompts/mobile/flow-build-phase-5.md +703 -703
  84. package/prompts/mobile/flow-build-phase-6.md +524 -524
  85. package/prompts/mobile/flow-build-phase-7.md +1001 -1001
  86. package/prompts/mobile/flow-build-phase-8.md +888 -888
  87. package/prompts/mobile/flow-build-phase-9.md +90 -90
  88. package/prompts/mobile/flow-build.md +135 -135
  89. package/prompts/mobile/flow-check-review.md +656 -20
  90. package/prompts/mobile/flow-check-test.md +526 -14
  91. package/prompts/mobile/flow-check.md +725 -67
  92. package/prompts/mobile/flow-commit.md +88 -119
  93. package/prompts/mobile/flow-docs-sync.md +620 -620
  94. package/prompts/mobile/flow-finish.md +910 -0
  95. package/prompts/mobile/flow-release.md +751 -0
  96. package/prompts/mobile/flow-work-api.md +1493 -0
  97. package/prompts/mobile/flow-work-feature.md +61 -61
  98. package/prompts/mobile/flow-work-fix.md +46 -46
  99. package/prompts/mobile/flow-work-refactor.md +48 -48
  100. package/prompts/mobile/flow-work-resume.md +34 -34
  101. package/prompts/mobile/flow-work.md +1593 -1329
  102. package/prompts/shared/mermaid-guidelines.md +102 -102
  103. package/prompts/shared/scope-levels.md +114 -114
  104. package/prompts/shared/smart-skip-preflight.md +214 -214
  105. package/prompts/shared/story-points.md +55 -55
  106. package/prompts/shared/task-format.md +74 -74
  107. package/prompts/shared/task-summary-template.md +277 -277
  108. package/templates/AGENT.template.md +443 -443
  109. package/templates/backend/.clauderules.template +112 -112
  110. package/templates/backend/.cursorrules.template +102 -102
  111. package/templates/backend/README.template.md +2 -2
  112. package/templates/backend/ai-instructions.template.md +2 -2
  113. package/templates/backend/copilot-instructions.template.md +2 -2
  114. package/templates/backend/docs/api.template.md +320 -320
  115. package/templates/backend/docs/business-flows.template.md +97 -97
  116. package/templates/backend/docs/code-standards.template.md +2 -2
  117. package/templates/backend/docs/contributing.template.md +3 -3
  118. package/templates/backend/docs/data-model.template.md +520 -520
  119. package/templates/backend/docs/testing.template.md +2 -2
  120. package/templates/backend/project-brief.template.md +2 -2
  121. package/templates/backend/specs/configuration.template.md +2 -2
  122. package/templates/backend/specs/security.template.md +2 -2
  123. package/templates/desktop/.clauderules.template +112 -112
  124. package/templates/desktop/.cursorrules.template +102 -102
  125. package/templates/desktop/README.template.md +170 -170
  126. package/templates/desktop/ai-instructions.template.md +366 -366
  127. package/templates/desktop/copilot-instructions.template.md +140 -140
  128. package/templates/desktop/docs/docs/api.template.md +320 -320
  129. package/templates/desktop/docs/docs/architecture.template.md +724 -724
  130. package/templates/desktop/docs/docs/business-flows.template.md +102 -102
  131. package/templates/desktop/docs/docs/code-standards.template.md +792 -792
  132. package/templates/desktop/docs/docs/contributing.template.md +149 -149
  133. package/templates/desktop/docs/docs/data-model.template.md +520 -520
  134. package/templates/desktop/docs/docs/operations.template.md +720 -720
  135. package/templates/desktop/docs/docs/testing.template.md +722 -722
  136. package/templates/desktop/project-brief.template.md +150 -150
  137. package/templates/desktop/specs/specs/configuration.template.md +121 -121
  138. package/templates/desktop/specs/specs/security.template.md +392 -392
  139. package/templates/frontend/README.template.md +2 -2
  140. package/templates/frontend/ai-instructions.template.md +2 -2
  141. package/templates/frontend/docs/api-integration.template.md +362 -362
  142. package/templates/frontend/docs/components.template.md +2 -2
  143. package/templates/frontend/docs/error-handling.template.md +360 -360
  144. package/templates/frontend/docs/operations.template.md +107 -107
  145. package/templates/frontend/docs/performance.template.md +124 -124
  146. package/templates/frontend/docs/pwa.template.md +119 -119
  147. package/templates/frontend/docs/state-management.template.md +2 -2
  148. package/templates/frontend/docs/styling.template.md +2 -2
  149. package/templates/frontend/docs/testing.template.md +2 -2
  150. package/templates/frontend/project-brief.template.md +2 -2
  151. package/templates/frontend/specs/accessibility.template.md +95 -95
  152. package/templates/frontend/specs/configuration.template.md +2 -2
  153. package/templates/frontend/specs/security.template.md +175 -175
  154. package/templates/fullstack/README.template.md +252 -252
  155. package/templates/fullstack/ai-instructions.template.md +444 -444
  156. package/templates/fullstack/project-brief.template.md +157 -157
  157. package/templates/fullstack/specs/configuration.template.md +340 -340
  158. package/templates/mobile/README.template.md +167 -167
  159. package/templates/mobile/ai-instructions.template.md +196 -196
  160. package/templates/mobile/docs/app-store.template.md +135 -135
  161. package/templates/mobile/docs/architecture.template.md +63 -63
  162. package/templates/mobile/docs/native-features.template.md +94 -94
  163. package/templates/mobile/docs/navigation.template.md +59 -59
  164. package/templates/mobile/docs/offline-strategy.template.md +65 -65
  165. package/templates/mobile/docs/permissions.template.md +56 -56
  166. package/templates/mobile/docs/state-management.template.md +85 -85
  167. package/templates/mobile/docs/testing.template.md +109 -109
  168. package/templates/mobile/project-brief.template.md +69 -69
  169. package/templates/mobile/specs/build-configuration.template.md +91 -91
  170. package/templates/mobile/specs/deployment.template.md +92 -92
  171. package/templates/work.template.md +47 -47
@@ -0,0 +1,910 @@
1
+ ---
2
+ description: Finalization Workflow - Archive, Generate Descriptions, and Push
3
+ ---
4
+
5
+ # AI Flow - Finish Workflow
6
+
7
+ **YOU ARE AN EXPERT DEVELOPMENT WORKFLOW AUTOMATION SPECIALIST.**
8
+
9
+ Your mission is to finalize completed work by archiving metrics, generating professional PR/Jira descriptions with AI analysis, and optionally pushing changes when the user executes `/flow-finish`.
10
+
11
+ **🚀 MODO AGENTE ACTIVADO:** Actúa proactivamente, ejecuta validaciones y commits automáticamente si es necesario. Solicita confirmación solo antes del push final.
12
+
13
+ ---
14
+
15
+ ## Command: `/flow-finish`
16
+
17
+ ### Objective
18
+
19
+ Automate the complete finalization of development work with:
20
+
21
+ - **Smart validation** (only if needed - skip if already executed)
22
+ - **Smart commit** (only if uncommitted changes exist)
23
+ - **Automatic archiving** (metrics to analytics.jsonl)
24
+ - **AI-powered descriptions** (professional PR and Jira descriptions with optimized token usage)
25
+ - **Optional push** (always ask for confirmation)
26
+ - **Cleanup** (remove work folder after success)
27
+
28
+ ---
29
+
30
+ ## Workflow: 5 Steps
31
+
32
+ ### Step 0: Pre-Flight Checks & State Detection
33
+
34
+ **🔍 CRITICAL VALIDATION** - Detect complete state BEFORE any costly operations:
35
+
36
+ ```bash
37
+ # 1. Verify active work exists
38
+ if [ ! -d ".ai-flow/work" ] || [ -z "$(ls -A .ai-flow/work)" ]; then
39
+ echo "❌ No hay trabajo activo en .ai-flow/work/"
40
+ echo "💡 Inicia trabajo con: /flow-work"
41
+ exit 1
42
+ fi
43
+
44
+ # 2. Detect work folder (should be only one)
45
+ TASK_FOLDER=$(ls .ai-flow/work/ | head -n 1)
46
+ TASK_PATH=".ai-flow/work/$TASK_FOLDER"
47
+
48
+ # 3. Check if already PAUSED
49
+ if [ -f "$TASK_PATH/PAUSED" ]; then
50
+ echo "⏸️ Esta tarea está pausada."
51
+ echo "💡 Reanuda con: /flow-work"
52
+ exit 1
53
+ fi
54
+
55
+ # 4. Check if already archived
56
+ if [ ! -f "$TASK_PATH/work.md" ]; then
57
+ echo "✅ Esta tarea ya fue archivada."
58
+ exit 0
59
+ fi
60
+
61
+ # 5. Detect current branch
62
+ CURRENT_BRANCH=$(git branch --show-current)
63
+
64
+ # 6. Verify branch protection
65
+ PROTECTED_BRANCHES="main|master|develop|development"
66
+ if [[ "$CURRENT_BRANCH" =~ ^($PROTECTED_BRANCHES)$ ]]; then
67
+ echo "⚠️ ERROR: No puedes finalizar trabajo en branch protegido: $CURRENT_BRANCH"
68
+ echo "💡 Crea un feature branch primero con: git checkout -b feature/[nombre]"
69
+ exit 1
70
+ fi
71
+
72
+ # 7. Detect uncommitted changes
73
+ UNCOMMITTED=$(git status --porcelain)
74
+ HAS_UNCOMMITTED_CHANGES=false
75
+ if [ -n "$UNCOMMITTED" ]; then
76
+ HAS_UNCOMMITTED_CHANGES=true
77
+ fi
78
+
79
+ # 8. Read validation state (if status.json exists)
80
+ if [ -f "$TASK_PATH/status.json" ]; then
81
+ TESTS_EXECUTED=$(jq -r '.validation.tests.executed' "$TASK_PATH/status.json")
82
+ TESTS_PASSED=$(jq -r '.validation.tests.passed' "$TASK_PATH/status.json")
83
+ TESTS_FAILED=$(jq -r '.validation.tests.failed' "$TASK_PATH/status.json")
84
+ LINT_EXECUTED=$(jq -r '.validation.lint.executed' "$TASK_PATH/status.json")
85
+ LAST_VALIDATION_TIMESTAMP=$(jq -r '.validation.lastExecuted' "$TASK_PATH/status.json" 2>/dev/null || echo "0")
86
+ else
87
+ TESTS_EXECUTED=false
88
+ TESTS_PASSED=0
89
+ TESTS_FAILED=0
90
+ LINT_EXECUTED=false
91
+ LAST_VALIDATION_TIMESTAMP="0"
92
+ fi
93
+
94
+ # 9. Detect if there are changes since last validation
95
+ LAST_COMMIT_TIMESTAMP=$(git log -1 --format=%ct 2>/dev/null || echo "0")
96
+ NEEDS_REVALIDATION=false
97
+ if [ "$TESTS_EXECUTED" = "true" ] && [ "$LAST_COMMIT_TIMESTAMP" -gt "$LAST_VALIDATION_TIMESTAMP" ]; then
98
+ NEEDS_REVALIDATION=true
99
+ fi
100
+
101
+ # 10. Show current state summary
102
+ echo ""
103
+ echo "---"
104
+ echo "📊 Estado Actual del Trabajo"
105
+ echo "---"
106
+ echo "📂 Tarea: $TASK_FOLDER"
107
+ echo "🌿 Branch: $CURRENT_BRANCH"
108
+ echo "📝 Uncommitted changes: $([ "$HAS_UNCOMMITTED_CHANGES" = true ] && echo "⚠️ Sí" || echo "✅ No")"
109
+ echo "🧪 Tests ejecutados: $([ "$TESTS_EXECUTED" = "true" ] && echo "✅ Sí ($TESTS_PASSED passed, $TESTS_FAILED failed)" || echo "❌ No")"
110
+ echo "🔍 Lint ejecutado: $([ "$LINT_EXECUTED" = "true" ] && echo "✅ Sí" || echo "❌ No")"
111
+ echo "♻️ Requiere re-validación: $([ "$NEEDS_REVALIDATION" = true ] && echo "⚠️ Sí" || echo "✅ No")"
112
+ echo ""
113
+ ```
114
+
115
+ ---
116
+
117
+ ### Step 1: Smart Validation
118
+
119
+ **Only execute `/flow-check` if:**
120
+ - `TESTS_EXECUTED == false` (never executed), **OR**
121
+ - `NEEDS_REVALIDATION == true` (commits after last validation)
122
+
123
+ ```bash
124
+ SHOULD_RUN_CHECK=false
125
+
126
+ if [ "$TESTS_EXECUTED" = "false" ]; then
127
+ echo "🧪 Tests no ejecutados. Ejecutando /flow-check..."
128
+ SHOULD_RUN_CHECK=true
129
+ elif [ "$NEEDS_REVALIDATION" = "true" ]; then
130
+ echo "🔄 Cambios detectados desde última validación. Ejecutando /flow-check..."
131
+ SHOULD_RUN_CHECK=true
132
+ else
133
+ echo "✅ Validación previa OK. Saltando /flow-check"
134
+ fi
135
+
136
+ if [ "$SHOULD_RUN_CHECK" = "true" ]; then
137
+ # INVOKE /flow-check HERE
138
+ # Execute the complete /flow-check workflow
139
+ # This will update status.json with results
140
+
141
+ # After execution, re-read validation results
142
+ TESTS_PASSED=$(jq -r '.validation.tests.passed' "$TASK_PATH/status.json" 2>/dev/null || echo "0")
143
+ TESTS_FAILED=$(jq -r '.validation.tests.failed' "$TASK_PATH/status.json" 2>/dev/null || echo "0")
144
+
145
+ # If tests FAIL → STOP EVERYTHING
146
+ if [ "$TESTS_FAILED" -gt 0 ]; then
147
+ echo ""
148
+ echo "❌ TESTS FALLIDOS"
149
+ echo "---"
150
+ echo "$TESTS_FAILED test(s) fallaron."
151
+ echo ""
152
+ echo "🛑 WORKFLOW DETENIDO"
153
+ echo "💡 Arregla los tests y vuelve a ejecutar /flow-finish"
154
+ exit 1
155
+ fi
156
+ fi
157
+ ```
158
+
159
+ ---
160
+
161
+ ### Step 2: Smart Commit
162
+
163
+ **Only execute `/flow-commit` if:**
164
+ - `HAS_UNCOMMITTED_CHANGES == true`
165
+
166
+ ```bash
167
+ if [ "$HAS_UNCOMMITTED_CHANGES" = "true" ]; then
168
+ echo "📝 Cambios sin commitear detectados. Ejecutando /flow-commit..."
169
+
170
+ # INVOKE /flow-commit HERE
171
+ # Execute the complete /flow-commit workflow
172
+ # This will update status.json with new commits
173
+ else
174
+ echo "✅ No hay cambios sin commitear. Saltando /flow-commit"
175
+ fi
176
+
177
+ # Verify working directory is clean
178
+ FINAL_STATUS=$(git status --porcelain)
179
+ if [ -n "$FINAL_STATUS" ]; then
180
+ echo "⚠️ Aún hay cambios sin commitear después de /flow-commit"
181
+ echo "$FINAL_STATUS"
182
+ echo ""
183
+ echo "🛑 WORKFLOW DETENIDO"
184
+ echo "💡 Commitea manualmente o revisa los cambios"
185
+ exit 1
186
+ fi
187
+ ```
188
+
189
+ ---
190
+
191
+ ### Step 3: Archive, Cleanup & Commit
192
+
193
+ **Execute ALWAYS, before asking for push:**
194
+
195
+ ```bash
196
+ echo ""
197
+ echo "📦 Archivando y limpiando trabajo..."
198
+ echo ""
199
+
200
+ # 1. Extract metadata for analytics
201
+ if [ -f "$TASK_PATH/status.json" ]; then
202
+ # COMPLEX: has status.json
203
+ TASK_TYPE=$(jq -r '.type' "$TASK_PATH/status.json")
204
+ TASK_SOURCE=$(jq -r '.source' "$TASK_PATH/status.json")
205
+ CREATED_AT=$(jq -r '.timestamps.created' "$TASK_PATH/status.json")
206
+ COMPLETED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
207
+
208
+ # Calculate duration in minutes
209
+ CREATED_TS=$(date -d "$CREATED_AT" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%SZ" "$CREATED_AT" +%s 2>/dev/null || echo "0")
210
+ COMPLETED_TS=$(date +%s)
211
+ DURATION_MIN=$(( ($COMPLETED_TS - $CREATED_TS) / 60 ))
212
+
213
+ TOTAL_TASKS=$(jq -r '.progress.totalTasks' "$TASK_PATH/status.json")
214
+ COMMIT_COUNT=$(jq -r '.git.commits | length' "$TASK_PATH/status.json")
215
+ VALIDATION_PASSED=$( [ "$TESTS_FAILED" -eq 0 ] && echo "true" || echo "false" )
216
+ else
217
+ # MEDIUM: only work.md + git
218
+ TASK_TYPE="unknown"
219
+ # Detect type from folder name patterns
220
+ if echo "$TASK_FOLDER" | grep -qiE '^(feature|feat)'; then
221
+ TASK_TYPE="feature"
222
+ elif echo "$TASK_FOLDER" | grep -qiE '^(fix|bugfix)'; then
223
+ TASK_TYPE="fix"
224
+ elif echo "$TASK_FOLDER" | grep -qiE '^refactor'; then
225
+ TASK_TYPE="refactor"
226
+ fi
227
+
228
+ TASK_SOURCE="manual"
229
+
230
+ # First commit timestamp
231
+ FIRST_COMMIT=$(git log --reverse --format=%ct --all -- "$TASK_PATH/work.md" 2>/dev/null | head -n 1)
232
+ CREATED_AT=$(date -u -d "@$FIRST_COMMIT" +"%Y-%m-%dT%H:%M:%SZ" 2>/dev/null || date -u +"%Y-%m-%dT%H:%M:%SZ")
233
+ COMPLETED_AT=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
234
+
235
+ CREATED_TS=$FIRST_COMMIT
236
+ COMPLETED_TS=$(date +%s)
237
+ DURATION_MIN=$(( ($COMPLETED_TS - $CREATED_TS) / 60 ))
238
+
239
+ # Count checkboxes in work.md
240
+ TOTAL_TASKS=$(grep -c '^\- \[ \]' "$TASK_PATH/work.md" 2>/dev/null || echo "0")
241
+
242
+ # Count commits in branch
243
+ COMMIT_COUNT=$(git log --oneline "$CURRENT_BRANCH" ^main 2>/dev/null | wc -l | tr -d ' ')
244
+
245
+ VALIDATION_PASSED="true"
246
+ fi
247
+
248
+ # Extract Story Points from work.md
249
+ STORY_POINTS=$(grep -oP '• \K\d+(?= SP)' "$TASK_PATH/work.md" 2>/dev/null | awk '{sum+=$1} END {print sum}')
250
+ STORY_POINTS=${STORY_POINTS:-0}
251
+
252
+ # Calculate hours and minutes
253
+ DURATION_HOURS=$(( DURATION_MIN / 60 ))
254
+ DURATION_MINS=$(( DURATION_MIN % 60 ))
255
+
256
+ # 2. Build JSON analytics
257
+ ANALYTICS_JSON="{\"task\":\"$TASK_FOLDER\",\"type\":\"$TASK_TYPE\",\"src\":\"$TASK_SOURCE\",\"dur\":$DURATION_MIN,\"start\":\"$CREATED_AT\",\"end\":\"$COMPLETED_AT\",\"tasks\":$TOTAL_TASKS,\"sp\":$STORY_POINTS,\"commits\":$COMMIT_COUNT,\"valid\":$VALIDATION_PASSED}"
258
+
259
+ # 3. Append to analytics.jsonl
260
+ mkdir -p .ai-flow/archive
261
+ echo "$ANALYTICS_JSON" >> .ai-flow/archive/analytics.jsonl
262
+
263
+ echo "✅ Métricas archivadas en analytics.jsonl"
264
+
265
+ # 4. Delete work folder
266
+ rm -rf "$TASK_PATH"
267
+ echo "✅ Carpeta de trabajo eliminada"
268
+
269
+ # 5. Commit analytics
270
+ git add .ai-flow/archive/analytics.jsonl
271
+
272
+ # Check if there's something to commit
273
+ if git diff --cached --quiet; then
274
+ echo "✅ Analytics ya commiteado previamente"
275
+ else
276
+ git commit -m "chore: archive $TASK_TYPE task '$TASK_FOLDER' (${DURATION_HOURS}h ${DURATION_MINS}min, ${STORY_POINTS} SP)"
277
+ echo "✅ Analytics commiteado"
278
+ fi
279
+
280
+ echo ""
281
+ echo "---"
282
+ echo "📊 Resumen del Trabajo Completado"
283
+ echo "---"
284
+ echo "📂 Tarea: $TASK_FOLDER"
285
+ echo "🏷️ Tipo: $TASK_TYPE"
286
+ echo "⏱️ Duración: ${DURATION_HOURS}h ${DURATION_MINS}min"
287
+ echo "📊 Story Points: $STORY_POINTS SP"
288
+ echo "💾 Commits: $COMMIT_COUNT"
289
+ echo "🧪 Validación: $([ "$VALIDATION_PASSED" = "true" ] && echo "✅ Passed" || echo "⚠️ With warnings")"
290
+ echo "🌿 Branch: $CURRENT_BRANCH"
291
+ echo ""
292
+ ```
293
+
294
+ ---
295
+
296
+ ### Step 4: AI-Powered Description Generation
297
+
298
+ **Generate professional descriptions using AI with optimized token consumption:**
299
+
300
+ ```bash
301
+ echo "---"
302
+ echo "📋 Generando descripciones para PR y Jira con IA..."
303
+ echo "---"
304
+ echo ""
305
+
306
+ # ============================================
307
+ # LAYER 1: Bash Extraction (0 tokens)
308
+ # ============================================
309
+
310
+ # Extract objective from work.md
311
+ function extract_objective_from_work_md() {
312
+ if [ ! -f ".ai-flow/work/$TASK_FOLDER/work.md" ]; then
313
+ # Work folder already deleted, try to reconstruct from commits
314
+ git log "$CURRENT_BRANCH" --format="%B" -1 | head -n 3 | tr '\n' ' ' | sed 's/ */ /g'
315
+ return
316
+ fi
317
+
318
+ # Extract Objective section
319
+ awk '/^## Objective$/,/^## [^O]/' ".ai-flow/work/$TASK_FOLDER/work.md" 2>/dev/null | \
320
+ grep -v '^##' | sed '/^$/d' | head -n 3 | tr '\n' ' ' | sed 's/ */ /g' | sed 's/^ *//;s/ *$//'
321
+ }
322
+
323
+ # Extract completed tasks
324
+ function extract_completed_tasks() {
325
+ if [ ! -f ".ai-flow/work/$TASK_FOLDER/work.md" ]; then
326
+ echo "Tareas completadas (ver commits)"
327
+ return
328
+ fi
329
+
330
+ awk '/^## Tasks$/,/^## [^T]/' ".ai-flow/work/$TASK_FOLDER/work.md" 2>/dev/null | \
331
+ grep '^\- \[x\]' | sed 's/^\- \[x\] /✅ /' | head -n 8
332
+ }
333
+
334
+ # Categorize changed files
335
+ function categorize_changed_files() {
336
+ local all_files=$(git diff --name-only main..HEAD 2>/dev/null || git diff --name-only --staged)
337
+
338
+ local backend_count=$(echo "$all_files" | grep -icE '(controller|service|repository|handler|route|api)' 2>/dev/null || echo 0)
339
+ local frontend_count=$(echo "$all_files" | grep -icE '(component|view|page|screen|widget)' 2>/dev/null || echo 0)
340
+ local db_count=$(echo "$all_files" | grep -icE '(migration|entity|model|schema|\.sql)' 2>/dev/null || echo 0)
341
+ local test_count=$(echo "$all_files" | grep -icE '(test|spec|e2e)' 2>/dev/null || echo 0)
342
+ local doc_count=$(echo "$all_files" | grep -icE '\.md$' 2>/dev/null || echo 0)
343
+ local config_count=$(echo "$all_files" | grep -icE '(\.json|\.yaml|\.yml|\.env|docker|k8s)' 2>/dev/null || echo 0)
344
+
345
+ cat <<EOF
346
+ - Backend: $backend_count files
347
+ - Frontend: $frontend_count files
348
+ - Database: $db_count files
349
+ - Tests: $test_count files
350
+ - Documentation: $doc_count files
351
+ - Configuration: $config_count files
352
+ EOF
353
+ }
354
+
355
+ # Detect file purpose
356
+ function detect_file_purpose() {
357
+ local file=$1
358
+
359
+ case "$file" in
360
+ *controller*|*route*|*handler*) echo "API endpoint" ;;
361
+ *service*|*repository*) echo "Business logic" ;;
362
+ *entity*|*model*|*schema*) echo "Data model" ;;
363
+ *test*|*spec*) echo "Tests" ;;
364
+ *migration*) echo "Database migration" ;;
365
+ *.md) echo "Documentation" ;;
366
+ *) echo "Source code" ;;
367
+ esac
368
+ }
369
+
370
+ # Show top 3 files by impact
371
+ function show_top_3_files_summary() {
372
+ local top_files=$(git diff --stat main..HEAD 2>/dev/null | sort -rn -k3 | head -n 3 | awk '{print $1}')
373
+
374
+ echo "### Most Impacted Files"
375
+ for file in $top_files; do
376
+ local lines_changed=$(git diff --stat main..HEAD -- "$file" 2>/dev/null | tail -n 1 | awk '{print $4}')
377
+ local file_type=$(detect_file_purpose "$file")
378
+ echo "- \`$file\` ($lines_changed lines) - $file_type"
379
+ done
380
+ }
381
+
382
+ # Detect deployment requirements
383
+ function detect_deployment_requirements() {
384
+ local changed_files=$(git diff --name-only main..HEAD 2>/dev/null || echo "")
385
+
386
+ # Migrations (universal)
387
+ HAS_MIGRATIONS=false
388
+ MIGRATION_FILES=""
389
+ if echo "$changed_files" | grep -qiE '(migration|migrate|schema|upgrade|\.sql$)'; then
390
+ HAS_MIGRATIONS=true
391
+ MIGRATION_FILES=$(echo "$changed_files" | grep -iE '(migration|migrate)' | wc -l | tr -d ' ')
392
+ fi
393
+
394
+ # Environment variables (universal)
395
+ NEW_ENV_VARS=""
396
+ ENV_FILES=$(echo "$changed_files" | grep -iE '(\.env\.example|\.env\.template|\.env\.sample|env\.example|env\.sample)')
397
+ if [ -n "$ENV_FILES" ]; then
398
+ NEW_ENV_VARS=$(git diff main..HEAD -- $ENV_FILES 2>/dev/null | grep -E '^\+[A-Z_0-9]+=' | sed 's/^+//' | cut -d'=' -f1 | sort -u)
399
+ fi
400
+
401
+ # Dependencies (language-agnostic)
402
+ HAS_NEW_DEPS=false
403
+ INSTALL_CMD=""
404
+
405
+ if echo "$changed_files" | grep -qE 'package\.json'; then
406
+ HAS_NEW_DEPS=true
407
+ INSTALL_CMD="npm install"
408
+ elif echo "$changed_files" | grep -qE '(requirements\.txt|pyproject\.toml|Pipfile)'; then
409
+ HAS_NEW_DEPS=true
410
+ INSTALL_CMD="pip install -r requirements.txt"
411
+ elif echo "$changed_files" | grep -qE 'composer\.json'; then
412
+ HAS_NEW_DEPS=true
413
+ INSTALL_CMD="composer install"
414
+ elif echo "$changed_files" | grep -qE 'Gemfile'; then
415
+ HAS_NEW_DEPS=true
416
+ INSTALL_CMD="bundle install"
417
+ elif echo "$changed_files" | grep -qE 'go\.(mod|sum)'; then
418
+ HAS_NEW_DEPS=true
419
+ INSTALL_CMD="go mod download"
420
+ elif echo "$changed_files" | grep -qE 'Cargo\.(toml|lock)'; then
421
+ HAS_NEW_DEPS=true
422
+ INSTALL_CMD="cargo build"
423
+ elif echo "$changed_files" | grep -qE '\.csproj'; then
424
+ HAS_NEW_DEPS=true
425
+ INSTALL_CMD="dotnet restore"
426
+ elif echo "$changed_files" | grep -qE 'pom\.xml'; then
427
+ HAS_NEW_DEPS=true
428
+ INSTALL_CMD="mvn install"
429
+ elif echo "$changed_files" | grep -qE 'build\.gradle'; then
430
+ HAS_NEW_DEPS=true
431
+ INSTALL_CMD="gradle build"
432
+ fi
433
+
434
+ # Determine if showing deployment section
435
+ SHOW_DEPLOYMENT_NOTES=false
436
+ if [ "$HAS_MIGRATIONS" = "true" ] || [ -n "$NEW_ENV_VARS" ] || [ "$HAS_NEW_DEPS" = "true" ]; then
437
+ SHOW_DEPLOYMENT_NOTES=true
438
+ fi
439
+
440
+ # Export variables
441
+ export HAS_MIGRATIONS
442
+ export MIGRATION_FILES
443
+ export NEW_ENV_VARS
444
+ export HAS_NEW_DEPS
445
+ export INSTALL_CMD
446
+ export SHOW_DEPLOYMENT_NOTES
447
+ }
448
+
449
+ # Detect area of impact
450
+ function detect_impact_area() {
451
+ local changed_files=$(git diff --name-only main..HEAD 2>/dev/null || echo "")
452
+ local area="General"
453
+ local module=""
454
+
455
+ # Backend API (framework-agnostic)
456
+ if echo "$changed_files" | grep -qiE '(controller|service|repository|handler|route|api|endpoint)'; then
457
+ area="Backend API"
458
+
459
+ # Module by subdirectory or filename
460
+ if echo "$changed_files" | grep -qiE '(auth|login|jwt|user|session)'; then
461
+ module="Authentication"
462
+ elif echo "$changed_files" | grep -qiE '(payment|billing|stripe|paypal)'; then
463
+ module="Payments"
464
+ elif echo "$changed_files" | grep -qiE '(notification|email|sms|push)'; then
465
+ module="Notifications"
466
+ elif echo "$changed_files" | grep -qiE '(report|analytics|dashboard)'; then
467
+ module="Analytics"
468
+ fi
469
+
470
+ # Frontend (framework-agnostic)
471
+ elif echo "$changed_files" | grep -qiE '(component|view|page|screen|widget|template)'; then
472
+ area="Frontend"
473
+
474
+ if echo "$changed_files" | grep -qiE '(auth|login)'; then
475
+ module="Authentication UI"
476
+ elif echo "$changed_files" | grep -qiE '(dashboard|home)'; then
477
+ module="Dashboard"
478
+ elif echo "$changed_files" | grep -qiE '(profile|account|settings)'; then
479
+ module="User Profile"
480
+ fi
481
+
482
+ # Mobile (agnostic: React Native, Flutter, Native)
483
+ elif echo "$changed_files" | grep -qiE '(ios/|android/|mobile/|\.swift|\.kt|\.dart)'; then
484
+ area="Mobile"
485
+
486
+ # Database (agnostic)
487
+ elif echo "$changed_files" | grep -qiE '(migration|schema|seed|model|entity|\.sql)'; then
488
+ area="Database"
489
+ module="Schema"
490
+
491
+ # Infrastructure (agnostic)
492
+ elif echo "$changed_files" | grep -qiE '(docker|k8s|kubernetes|terraform|ansible|\.yaml|\.yml|ci|cd|\.github|\.gitlab)'; then
493
+ area="Infrastructure"
494
+ module="DevOps"
495
+
496
+ # Testing (agnostic)
497
+ elif echo "$changed_files" | grep -qiE '(test|spec|\.test\.|\.spec\.|e2e|integration)'; then
498
+ area="Testing"
499
+
500
+ # Documentation
501
+ elif echo "$changed_files" | grep -qiE '(\.md$|docs?/|README)'; then
502
+ area="Documentation"
503
+ fi
504
+
505
+ # Final format
506
+ if [ -n "$module" ]; then
507
+ echo "$area - $module"
508
+ else
509
+ echo "$area"
510
+ fi
511
+ }
512
+
513
+ # Detect Git platform and generate commit URLs
514
+ function get_commit_urls() {
515
+ local remote_url=$(git config --get remote.origin.url 2>/dev/null)
516
+
517
+ if [ -z "$remote_url" ]; then
518
+ echo "⚠️ No se detectó remote origin, commits sin links"
519
+ COMMIT_URL_PATTERN=""
520
+ PLATFORM="Unknown"
521
+ return 1
522
+ fi
523
+
524
+ # Normalize URL (SSH -> HTTPS)
525
+ local base_url=""
526
+
527
+ # GitHub
528
+ if echo "$remote_url" | grep -qE 'github\.com'; then
529
+ base_url=$(echo "$remote_url" | sed -E 's|git@github.com:(.*)|https://github.com/\1|' | sed 's|\.git$||')
530
+ COMMIT_URL_PATTERN="${base_url}/commit/"
531
+ PLATFORM="GitHub"
532
+
533
+ # GitLab
534
+ elif echo "$remote_url" | grep -qE 'gitlab\.com'; then
535
+ base_url=$(echo "$remote_url" | sed -E 's|git@gitlab.com:(.*)|https://gitlab.com/\1|' | sed 's|\.git$||')
536
+ COMMIT_URL_PATTERN="${base_url}/-/commit/"
537
+ PLATFORM="GitLab"
538
+
539
+ # Bitbucket
540
+ elif echo "$remote_url" | grep -qE 'bitbucket\.org'; then
541
+ base_url=$(echo "$remote_url" | sed -E 's|git@bitbucket.org:(.*)|https://bitbucket.org/\1|' | sed 's|\.git$||')
542
+ COMMIT_URL_PATTERN="${base_url}/commits/"
543
+ PLATFORM="Bitbucket"
544
+
545
+ # Azure DevOps
546
+ elif echo "$remote_url" | grep -qE 'dev\.azure\.com'; then
547
+ base_url=$(echo "$remote_url" | sed -E 's|git@ssh\.dev\.azure\.com:v3/(.*)|https://dev.azure.com/\1|' | sed 's|\.git$||')
548
+ COMMIT_URL_PATTERN="${base_url}/commit/"
549
+ PLATFORM="Azure DevOps"
550
+
551
+ # GitLab Self-Hosted
552
+ elif echo "$remote_url" | grep -qE 'gitlab'; then
553
+ base_url=$(echo "$remote_url" | sed -E 's|git@([^:]+):(.*)|https://\1/\2|' | sed 's|\.git$||')
554
+ COMMIT_URL_PATTERN="${base_url}/-/commit/"
555
+ PLATFORM="GitLab (Self-Hosted)"
556
+
557
+ # GitHub Enterprise
558
+ elif echo "$remote_url" | grep -qE 'github'; then
559
+ base_url=$(echo "$remote_url" | sed -E 's|git@([^:]+):(.*)|https://\1/\2|' | sed 's|\.git$||')
560
+ COMMIT_URL_PATTERN="${base_url}/commit/"
561
+ PLATFORM="GitHub Enterprise"
562
+
563
+ else
564
+ echo "⚠️ Plataforma Git no reconocida, commits sin links"
565
+ COMMIT_URL_PATTERN=""
566
+ PLATFORM="Unknown"
567
+ return 1
568
+ fi
569
+
570
+ echo "✅ Detectado: $PLATFORM"
571
+ export COMMIT_URL_PATTERN
572
+ export PLATFORM
573
+ }
574
+
575
+ # Generate commit list with links
576
+ function generate_commit_links() {
577
+ local max_commits=${1:-5}
578
+ local commits=$(git log main..HEAD --format="%h" -${max_commits} 2>/dev/null)
579
+ local total_commits=$(git log main..HEAD --format="%h" 2>/dev/null | wc -l | tr -d ' ')
580
+
581
+ # For summary line (first 5 hashes)
582
+ COMMIT_HASHES_SUMMARY=""
583
+ local count=0
584
+
585
+ for hash in $commits; do
586
+ if [ $count -lt 5 ]; then
587
+ if [ -n "$COMMIT_HASHES_SUMMARY" ]; then
588
+ COMMIT_HASHES_SUMMARY="${COMMIT_HASHES_SUMMARY}, "
589
+ fi
590
+
591
+ if [ -n "$COMMIT_URL_PATTERN" ]; then
592
+ COMMIT_HASHES_SUMMARY="${COMMIT_HASHES_SUMMARY}[${hash}](${COMMIT_URL_PATTERN}${hash})"
593
+ else
594
+ COMMIT_HASHES_SUMMARY="${COMMIT_HASHES_SUMMARY}\`${hash}\`"
595
+ fi
596
+ fi
597
+ count=$((count + 1))
598
+ done
599
+
600
+ # Add indicator if more commits
601
+ if [ $total_commits -gt 5 ]; then
602
+ COMMIT_HASHES_SUMMARY="${COMMIT_HASHES_SUMMARY}, ... (${total_commits} total)"
603
+ elif [ $total_commits -gt 0 ]; then
604
+ COMMIT_HASHES_SUMMARY="${COMMIT_HASHES_SUMMARY} (${total_commits} total)"
605
+ else
606
+ COMMIT_HASHES_SUMMARY="No commits"
607
+ fi
608
+
609
+ export COMMIT_HASHES_SUMMARY
610
+ export TOTAL_COMMITS=$total_commits
611
+ }
612
+
613
+ # ============================================
614
+ # LAYER 2: Smart Summary (0 tokens)
615
+ # ============================================
616
+
617
+ WORK_OBJECTIVE=$(extract_objective_from_work_md)
618
+ WORK_TASKS=$(extract_completed_tasks)
619
+ COMMIT_SUBJECTS=$(git log main..HEAD --format="%s" 2>/dev/null | head -10)
620
+ COMMIT_BREAKING=$(git log main..HEAD --grep="BREAKING CHANGE:" --format="%s" 2>/dev/null)
621
+ HAS_BREAKING_CHANGES=false
622
+ if [ -n "$COMMIT_BREAKING" ]; then
623
+ HAS_BREAKING_CHANGES=true
624
+ fi
625
+
626
+ FILES_BY_CATEGORY=$(categorize_changed_files)
627
+ TOP_FILES=$(show_top_3_files_summary)
628
+ detect_deployment_requirements
629
+ IMPACT_AREA=$(detect_impact_area)
630
+ get_commit_urls
631
+ generate_commit_links 5
632
+
633
+ # File statistics
634
+ FILES_STAT=$(git diff --stat main..HEAD 2>/dev/null | tail -n 1)
635
+ FILES_COUNT=$(echo "$FILES_STAT" | awk '{print $1}' | tr -d ' ')
636
+ LINES_ADDED=$(echo "$FILES_STAT" | grep -oP '\d+(?= insertion)' 2>/dev/null || echo "0")
637
+ LINES_DELETED=$(echo "$FILES_STAT" | grep -oP '\d+(?= deletion)' 2>/dev/null || echo "0")
638
+
639
+ # Test metrics (from status.json or default)
640
+ TESTS_TOTAL="N/A"
641
+ TESTS_PASSED="N/A"
642
+ TESTS_NEW="0"
643
+ COVERAGE="N/A"
644
+
645
+ if [ -f "$TASK_PATH/status.json" ]; then
646
+ TESTS_PASSED=$(jq -r '.validation.tests.passed // "N/A"' "$TASK_PATH/status.json" 2>/dev/null)
647
+ TESTS_FAILED=$(jq -r '.validation.tests.failed // 0' "$TASK_PATH/status.json" 2>/dev/null)
648
+ TESTS_TOTAL=$((TESTS_PASSED + TESTS_FAILED))
649
+ TESTS_NEW=$(jq -r '.validation.tests.new // 0' "$TASK_PATH/status.json" 2>/dev/null)
650
+ COVERAGE=$(jq -r '.validation.tests.coverage // "N/A"' "$TASK_PATH/status.json" 2>/dev/null)
651
+ fi
652
+
653
+ # Create structured summary for AI
654
+ cat > /tmp/ai-context-summary.md <<EOF
655
+ # Context Summary for AI Analysis
656
+
657
+ ## Work Overview
658
+ Objective: $WORK_OBJECTIVE
659
+ Completed Tasks:
660
+ $WORK_TASKS
661
+ Type: $TASK_TYPE
662
+ Story Points: $STORY_POINTS
663
+
664
+ ## Changes Made
665
+ Commits (subjects only):
666
+ $COMMIT_SUBJECTS
667
+
668
+ Breaking Changes: $([ "$HAS_BREAKING_CHANGES" = true ] && echo "YES" || echo "NO")
669
+
670
+ Files Changed by Category:
671
+ $FILES_BY_CATEGORY
672
+
673
+ ## Technical Metrics
674
+ - Duration: ${DURATION_HOURS}h ${DURATION_MINS}min
675
+ - Commits: $TOTAL_COMMITS
676
+ - Files: $FILES_COUNT (+$LINES_ADDED/-$LINES_DELETED)
677
+ - Tests: $TESTS_PASSED/$TESTS_TOTAL passing ($TESTS_NEW new)
678
+ - Coverage: $COVERAGE%
679
+ - Branch: $CURRENT_BRANCH
680
+
681
+ ## Deployment Requirements
682
+ $([ "$HAS_MIGRATIONS" = "true" ] && echo "Migrations: YES ($MIGRATION_FILES files)" || echo "Migrations: NO")
683
+ $([ -n "$NEW_ENV_VARS" ] && echo "Env Vars: $NEW_ENV_VARS" || echo "Env Vars: None")
684
+ $([ "$HAS_NEW_DEPS" = "true" ] && echo "Dependencies: YES (install: $INSTALL_CMD)" || echo "Dependencies: NO")
685
+
686
+ $TOP_FILES
687
+ EOF
688
+
689
+ # ============================================
690
+ # LAYER 3: AI Generation (~800-1200 tokens)
691
+ # ============================================
692
+
693
+ echo "🤖 Analizando contexto y generando descripciones profesionales..."
694
+ echo ""
695
+ ```
696
+
697
+ **NOW INVOKE AI TO GENERATE DESCRIPTIONS:**
698
+
699
+ Read the structured summary from `/tmp/ai-context-summary.md` (400-600 words) and generate two professional descriptions:
700
+
701
+ **AI Prompt:**
702
+
703
+ ```markdown
704
+ Genera dos descripciones profesionales (PR y Jira) basándote en este resumen estructurado:
705
+
706
+ <context-summary>
707
+ $(cat /tmp/ai-context-summary.md)
708
+ </context-summary>
709
+
710
+ <commit-links>
711
+ Platform: $PLATFORM
712
+ Base URL Pattern: $COMMIT_URL_PATTERN
713
+ Commit Hashes Summary: $COMMIT_HASHES_SUMMARY
714
+ </commit-links>
715
+
716
+ <formatting-requirements>
717
+ - Área de impacto detectada: $IMPACT_AREA
718
+ - Mostrar deployment notes: $([ "$SHOW_DEPLOYMENT_NOTES" = "true" ] && echo "SÍ" || echo "NO")
719
+ - Breaking changes: $([ "$HAS_BREAKING_CHANGES" = "true" ] && echo "SÍ (resaltar con ⚠️)" || echo "NO")
720
+ - Branch: $CURRENT_BRANCH
721
+ - Story Points: $STORY_POINTS SP
722
+ - Duration: ${DURATION_HOURS}h ${DURATION_MINS}min
723
+ </formatting-requirements>
724
+
725
+ **Requisitos:**
726
+
727
+ 1. **PR Description (GitHub/GitLab/Bitbucket):**
728
+ - Título: ## ${TASK_TYPE^}: [nombre descriptivo basado en objective]
729
+ - Header con branch, SP, duration
730
+ - Sección "Área de Impacto" con valor: $IMPACT_AREA
731
+ - Contexto: Resume el problema/necesidad en 2-3 líneas (extrae de objective)
732
+ - Solución Implementada: Resume enfoque técnico en 2-3 líneas (infiere de commits)
733
+ - Cambios principales: Lista 5-7 cambios significativos (analiza commit subjects)
734
+ - Validación: Tabla con Tests, Coverage, Lint, Docs
735
+ - Métricas: Tabla con Commits, Archivos, Breaking Changes
736
+ - Deployment Notes: Solo SI $SHOW_DEPLOYMENT_NOTES=true, incluir requirements específicos
737
+ - Referencias: Commits con links usando $COMMIT_HASHES_SUMMARY
738
+ - Reviewer checklist
739
+
740
+ 2. **Jira Description (Markdown estándar):**
741
+ - Similar estructura pero más concisa
742
+ - Enfoque en resultado de negocio
743
+ - Métricas en tabla
744
+ - Deployment notes si aplica
745
+ - Referencias con commits
746
+
747
+ **Reglas Importantes:**
748
+ - Usa lenguaje profesional pero claro
749
+ - Sé específico con cambios técnicos
750
+ - Usa los commit links ya formateados en $COMMIT_HASHES_SUMMARY
751
+ - Escapa caracteres especiales para Markdown válido (backticks, pipes, asteriscos)
752
+ - Usa separadores `---` (no `━━━━`)
753
+ - Si breaking changes, resáltalos con ⚠️ en sección Métricas
754
+ - Si deployment notes, sé específico con cada requirement
755
+
756
+ **Output en formato (CRÍTICO - respetar delimitadores):**
757
+
758
+ \`\`\`markdown
759
+ <!-- PR_DESCRIPTION_START -->
760
+ [contenido completo de PR description aquí]
761
+ <!-- PR_DESCRIPTION_END -->
762
+
763
+ <!-- JIRA_DESCRIPTION_START -->
764
+ [contenido completo de Jira description aquí]
765
+ <!-- JIRA_DESCRIPTION_END -->
766
+ \`\`\`
767
+
768
+ Analiza el contexto y genera las descripciones óptimas ahora.
769
+ ```
770
+
771
+ **After AI generates the descriptions, extract and save them:**
772
+
773
+ ```bash
774
+ # Extract PR description
775
+ sed -n '/<!-- PR_DESCRIPTION_START -->/,/<!-- PR_DESCRIPTION_END -->/p' /tmp/ai-output.md | \
776
+ sed '1d;$d' > /tmp/pr-description.md
777
+
778
+ # Extract Jira description
779
+ sed -n '/<!-- JIRA_DESCRIPTION_START -->/,/<!-- JIRA_DESCRIPTION_END -->/p' /tmp/ai-output.md | \
780
+ sed '1d;$d' > /tmp/jira-description.md
781
+
782
+ # Display descriptions
783
+ echo ""
784
+ echo "---"
785
+ echo "📋 DESCRIPCIÓN PARA PULL REQUEST (GitHub/GitLab/Bitbucket)"
786
+ echo "---"
787
+ echo ""
788
+ cat /tmp/pr-description.md
789
+ echo ""
790
+ echo ""
791
+ echo "---"
792
+ echo "🎫 DESCRIPCIÓN PARA JIRA/CLICKUP/LINEAR (Markdown)"
793
+ echo "---"
794
+ echo ""
795
+ cat /tmp/jira-description.md
796
+ echo ""
797
+ echo ""
798
+ echo "💡 Copia las descripciones de arriba para tus tickets"
799
+ echo ""
800
+ ```
801
+
802
+ ---
803
+
804
+ ### Step 5: Git Push (Optional)
805
+
806
+ **Always ask before pushing:**
807
+
808
+ ```bash
809
+ echo "---"
810
+ echo "🚀 ¿Realizar push a origin/$CURRENT_BRANCH?"
811
+ echo ""
812
+ echo "Esto subirá:"
813
+ echo " - $TOTAL_COMMITS commits de trabajo"
814
+ echo " - 1 commit de analytics archivado"
815
+ echo ""
816
+ read -p "Confirmar push (y/N): " CONFIRM_PUSH
817
+
818
+ if [[ "$CONFIRM_PUSH" =~ ^[Yy]$ ]]; then
819
+ echo ""
820
+ echo "⬆️ Subiendo cambios a origin/$CURRENT_BRANCH..."
821
+ echo ""
822
+
823
+ git push origin "$CURRENT_BRANCH"
824
+
825
+ if [ $? -eq 0 ]; then
826
+ echo ""
827
+ echo "---"
828
+ echo "✅ PUSH EXITOSO"
829
+ echo "---"
830
+ echo ""
831
+ echo "📊 Trabajo completado y subido correctamente"
832
+ echo "🌿 Branch: $CURRENT_BRANCH (pushed)"
833
+ echo ""
834
+ echo "💡 Siguiente paso: Crear Pull Request"
835
+ echo ""
836
+ echo " GitHub CLI:"
837
+ echo " gh pr create --title \"$TASK_TYPE: $TASK_FOLDER\" --body-file /tmp/pr-description.md"
838
+ echo ""
839
+ echo " GitLab CLI:"
840
+ echo " glab mr create --title \"$TASK_TYPE: $TASK_FOLDER\" --description \"\$(cat /tmp/pr-description.md)\""
841
+ echo ""
842
+ echo " Bitbucket CLI:"
843
+ echo " bb pr create --title \"$TASK_TYPE: $TASK_FOLDER\" --description \"\$(cat /tmp/pr-description.md)\""
844
+ echo ""
845
+ echo " O abre tu repositorio web y crea el PR manualmente"
846
+ echo ""
847
+ else
848
+ echo ""
849
+ echo "❌ ERROR AL HACER PUSH"
850
+ echo ""
851
+ echo "Posibles causas:"
852
+ echo " - Conflicto con remote"
853
+ echo " - Branch no tiene upstream configurado"
854
+ echo " - Permisos insuficientes"
855
+ echo ""
856
+ echo "💡 Comandos útiles:"
857
+ echo " git pull origin $CURRENT_BRANCH --rebase"
858
+ echo " git push -u origin $CURRENT_BRANCH"
859
+ echo ""
860
+ exit 1
861
+ fi
862
+ else
863
+ echo ""
864
+ echo "⏭️ Push cancelado por el usuario"
865
+ echo ""
866
+ echo "✅ Trabajo archivado y commiteado localmente"
867
+ echo ""
868
+ echo "💡 Puedes hacer push manualmente cuando estés listo:"
869
+ echo " git push origin $CURRENT_BRANCH"
870
+ echo ""
871
+ echo "⚠️ No olvides crear el PR después del push"
872
+ echo ""
873
+ fi
874
+ ```
875
+
876
+ ---
877
+
878
+ ## Summary
879
+
880
+ **Token Consumption Estimate:**
881
+
882
+ - **Step 1 (/flow-check):** ~1,800 tokens (only if needed)
883
+ - **Step 2 (/flow-commit):** ~1,000 tokens (only if uncommitted changes)
884
+ - **Step 4 (AI Descriptions):** ~1,200 tokens (optimized summary + generation)
885
+
886
+ **Total:** ~4,000 tokens for full execution with validation and commit
887
+ **Total:** ~1,200 tokens if check/commit already executed
888
+ **Total:** ~0 tokens if no changes detected (smart skip)
889
+
890
+ **Benefits:**
891
+
892
+ - ✅ Professional quality descriptions (senior-level)
893
+ - ✅ Optimized token usage (66% reduction vs full diff analysis)
894
+ - ✅ One command does everything
895
+ - ✅ Smart skip for validation/commit
896
+ - ✅ Tests are blocking (prevents broken code)
897
+ - ✅ Archive before push (guarantees versioning)
898
+ - ✅ Commit links (6 Git platforms supported)
899
+ - ✅ Language/framework agnostic
900
+ - ✅ Deployment notes auto-detection
901
+
902
+ ---
903
+
904
+ ## Notes
905
+
906
+ - This workflow completes the development cycle started by `/flow-work`
907
+ - Always archives analytics to `.ai-flow/archive/analytics.jsonl` before push
908
+ - Generates descriptions using AI with optimized context (structured summary, not full diffs)
909
+ - Push is always optional (user confirmation required)
910
+ - Work folder cleanup only happens after successful archiving