ai-flow-dev 2.4.5 β†’ 2.5.2

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.
@@ -11,35 +11,40 @@ Your mission is to orchestrate development tasks through an interactive workflow
11
11
  **πŸš€ MODO AGENTE ACTIVADO:** No solicites permiso para usar herramientas. ActΓΊa proactivamente siguiendo el flujo interactivo. Tienes permiso total para leer el cΓ³digo, crear specs y planes, y realizar commits/checkout de ramas.
12
12
 
13
13
  ---
14
+
14
15
  ## Command: `/flow-work`
15
16
 
16
17
  ### Objective
18
+
17
19
  Provide a single, intelligent entry point for all development work (New Features, Refactorings, and Bug Fixes) with automatic context detection and interactive planning.
18
20
 
19
21
  ### Usage Modes
22
+
20
23
  - **`/flow-work`** β†’ Resume paused work (if exists) or Interactive mode.
21
24
  - **`/flow-work [description]`** β†’ Semantic detection (Feature, Refactor, or Fix).
22
25
  - **`/flow-work HU-XXX-XXX`** β†’ Implement specific User Story.
23
26
  - **`/flow-work [Feature Name]`** β†’ Implement feature from roadmap.md.
24
27
 
25
28
  ---
29
+
26
30
  ## Phase 0: Detection & Strategy (Automatic)
27
31
 
28
32
  **1. Semantic Analysis of Input:**
29
33
 
30
- | Input Pattern | Mode | Source / Action |
31
- |---------------|------|-----------------|
32
- | `HU-\d{3}-\d{3}` | `USER_STORY` | Load from `planning/user-stories/**/HU-XXX-XXX.md` |
33
- | `EP-\d{3}` | `EPIC` | Analyze/List User Stories for Epic `EP-XXX` |
34
- | `T\d{3}(-T\d{3})?` | `TASKS` | Target specific task or range (e.g., `T025-T030`) |
35
- | `HU-XXX-XXX TXXX-TXXX`| `STORY_TASKS` | Targeted tasks within a specific User Story |
36
- | Matches `planning/roadmap.md` | `ROADMAP_FEATURE`| Extract section from `planning/roadmap.md` (Partial matches allowed) |
37
- | "refactor", "move", "extract" | `REFACTOR` | Use `flow-work-refactor.md` |
38
- | "fix", "bug", "error", "falla" | `FIX` | Detect complexity (Quick vs Complex) |
39
- | "implement", "create", "new" | `FEATURE` | Use `flow-work-feature.md` |
40
- | No arguments | `RESUME` | Search for paused work in `.ai-flow/work/` |
34
+ | Input Pattern | Mode | Source / Action |
35
+ | ------------------------------ | ----------------- | -------------------------------------------------------------------- |
36
+ | `HU-\d{3}-\d{3}` | `USER_STORY` | Load from `planning/user-stories/**/HU-XXX-XXX.md` |
37
+ | `EP-\d{3}` | `EPIC` | Analyze/List User Stories for Epic `EP-XXX` |
38
+ | `T\d{3}(-T\d{3})?` | `TASKS` | Target specific task or range (e.g., `T025-T030`) |
39
+ | `HU-XXX-XXX TXXX-TXXX` | `STORY_TASKS` | Targeted tasks within a specific User Story |
40
+ | Matches `planning/roadmap.md` | `ROADMAP_FEATURE` | Extract section from `planning/roadmap.md` (Partial matches allowed) |
41
+ | "refactor", "move", "extract" | `REFACTOR` | Use `flow-work-refactor.md` |
42
+ | "fix", "bug", "error", "falla" | `FIX` | Detect complexity (Quick vs Complex) |
43
+ | "implement", "create", "new" | `FEATURE` | Use `flow-work-feature.md` |
44
+ | No arguments | `RESUME` | Search for paused work in `.ai-flow/work/` |
41
45
 
42
46
  **2. Detection Logic Details:**
47
+
43
48
  - **USER_STORY / EPIC**: Load metadata from `planning/user-stories/` or `planning/roadmap.md`.
44
49
  - **ROADMAP_FEATURE**: Fuzzy search in `planning/roadmap.md` for titles like "User Management" or "Feature 2.2".
45
50
  - **TASK RANGES**: If `T025-T030` is provided, find the parent Story or Feature in current context or roadmap.
@@ -47,13 +52,107 @@ Provide a single, intelligent entry point for all development work (New Features
47
52
  - **COMPLEX FIX**: Multi-file, architectural, performance/security. β†’ Use `flow-work-fix.md` (Deep).
48
53
 
49
54
  ---
55
+
56
+ ## Phase 0.5: Complexity Classification (CRITICAL)
57
+
58
+ **Analyze task scope to determine workflow:**
59
+
60
+ | Metric | SIMPLE (⚑) | MEDIUM (πŸ“) | COMPLEX (πŸ—οΈ) |
61
+ | ------------- | ----------- | ----------- | ------------- |
62
+ | Files | 1 | 2-5 | >5 |
63
+ | Lines | <20 | 20-100 | >100 |
64
+ | Tests | No | Optional | Required |
65
+ | Docs | None | Minor | Significant |
66
+ | Architecture | None | Minimal | Major changes |
67
+ | Time estimate | <15 min | 15-60 min | >60 min |
68
+
69
+ **Classification Rules:**
70
+
71
+ **⚑ SIMPLE Task:**
72
+
73
+ - Examples: Fix typo, rename variable, update constant, add log, adjust CSS
74
+ - **Workflow**: In-chat plan β†’ Execute β†’ Done (NO files created)
75
+ - **Context**: Only `ai-instructions.md` if relevant
76
+
77
+ **πŸ“ MEDIUM Task:**
78
+
79
+ - Examples: Add component, refactor hook, simple bug fix, update API call
80
+ - **Workflow**: Create `work.md` only (NO `status.json`) β†’ Execute β†’ Simple archive
81
+ - **Context**: Load 2-3 relevant docs
82
+
83
+ **πŸ—οΈ COMPLEX Task:**
84
+
85
+ - Examples: New feature, major refactor, security fix, multi-file changes
86
+ - **Workflow**: Full workflow (`work.md` + `status.json` + branch + archiving)
87
+ - **Context**: Load all relevant docs
88
+
89
+ **Detection Logic:**
90
+
91
+ ```python
92
+ if files_affected == 1 and lines_changed < 20 and no_tests_needed and no_architecture_impact:
93
+ complexity = "SIMPLE"
94
+ elif files_affected <= 5 and lines_changed <= 100 and architecture_impact == "minimal":
95
+ complexity = "MEDIUM"
96
+ else:
97
+ complexity = "COMPLEX"
98
+ ```
99
+
100
+ **Show classification:**
101
+
102
+ ```
103
+ πŸ” Task Complexity: [SIMPLE ⚑ | MEDIUM πŸ“ | COMPLEX πŸ—οΈ]
104
+
105
+ Detected:
106
+ - Files: [N]
107
+ - Estimated lines: [~X]
108
+ - Tests needed: [Yes/No]
109
+ - Architecture impact: [None/Minimal/Major]
110
+
111
+ Proceeding with [SIMPLE/MEDIUM/COMPLEX] workflow.
112
+ ```
113
+
114
+ ---
115
+
50
116
  ## Phase 1: Analysis & Refinement
51
117
 
52
- **1. Context Loading (Multi-Source):**
118
+ **1. Context Loading (Smart & Selective):**
119
+
120
+ **CRITICAL: Load context based on task complexity and type:**
121
+
122
+ **IF complexity == "SIMPLE":**
123
+
124
+ - Load ONLY `ai-instructions.md` if task involves code changes
125
+ - Skip all other documentation
126
+ - Use existing patterns in nearby code as reference
127
+
128
+ **IF complexity == "MEDIUM":**
53
129
 
54
- **CRITICAL**: Regardless of whether a `USER_STORY` ID or a `ROADMAP_FEATURE` name is provided, you MUST attempt to load context from **BOTH** sources:
55
- - **`planning/roadmap.md`**: To understand high-level scope, epic relationships, and technical dependencies.
56
- - **`planning/user-stories/**/HU-XXX-XXX.md`**: To get granular details (Acceptance Criteria, Gherkin Scenarios, QA cases).
130
+ - Load `ai-instructions.md` (core rules)
131
+ - Load 1-2 specific docs based on task type:
132
+ - Component changes β†’ `docs/components.md`
133
+ - Routing changes β†’ `docs/routing.md`
134
+ - State management β†’ `docs/state-management.md`
135
+ - Styling β†’ `docs/styling.md`
136
+ - Skip architecture.md unless creating new patterns
137
+
138
+ **IF complexity == "COMPLEX":**
139
+
140
+ - Load `ai-instructions.md` (NEVER/ALWAYS rules)
141
+ - Load `docs/architecture.md` (patterns, structure)
142
+ - Load task-specific docs:
143
+ - Components β†’ `docs/components.md`
144
+ - Routing/Navigation β†’ `docs/routing.md`
145
+ - State β†’ `docs/state-management.md`
146
+ - API Integration β†’ `docs/api-integration.md`
147
+ - Testing β†’ `docs/testing.md`
148
+ - Load `docs/code-standards.md` only if creating new files
149
+
150
+ **Source Documentation (User Stories/Roadmap):**
151
+
152
+ **IF** `HU-XXX-XXX` or roadmap feature provided:
153
+
154
+ - **`planning/roadmap.md`**: Load for high-level scope
155
+ - **`planning/user-stories/**/HU-XXX-XXX.md`\*\*: Load for detailed requirements
57
156
 
58
157
  **2. Detail Level Detection (if Manual input):**
59
158
 
@@ -81,35 +180,40 @@ detail_level = analyze_description(input)
81
180
  **3. Interactive Refinement (Conditional):**
82
181
 
83
182
  **IF detail_level == "HIGH":**
183
+
84
184
  - Skip refinement questions
85
185
  - Proceed directly to Phase 2 (Planning)
86
186
  - Show: "βœ… Sufficient detail detected. Proceeding with planning..."
87
187
 
88
188
  **IF detail_level == "MEDIUM":**
189
+
89
190
  - Ask 1-2 targeted questions (only missing items)
90
191
  - Use Multiple Choice with defaults (⭐)
91
192
 
92
193
  **IF detail_level == "LOW":**
194
+
93
195
  - Full refinement flow (3-5 questions)
94
196
  - Use Multiple Choice with defaults (⭐)
95
197
  - Focus on: approach, scope, constraints, priorities
96
198
 
97
199
  **Example Interaction (LOW detail):**
200
+
98
201
  > πŸ“ I need to clarify some details for this feature:
202
+ >
99
203
  > 1. What authentication provider should we use? [default: A]
100
204
  > A) JWT (Local) ⭐
101
205
  > B) OAuth2 (Google/GitHub)
102
206
  > C) Firebase Auth
103
- >
104
207
  > 2. Should we implement audit logs for this? [default: B]
105
208
  > A) Yes
106
209
  > B) No ⭐
107
210
  >
108
- > Your answers (or Enter for defaults): _
211
+ > Your answers (or Enter for defaults): \_
109
212
 
110
213
  **4. Refined Objective Generation (if Manual):**
111
214
 
112
215
  After refinement, generate clear objective statement:
216
+
113
217
  ```
114
218
  βœ… Refined Objective:
115
219
 
@@ -127,6 +231,7 @@ Is this correct? (Yes/Edit/Cancel): _
127
231
  **5. Documentation Compliance Check:**
128
232
 
129
233
  Read relevant documentation:
234
+
130
235
  - `ai-instructions.md` (NEVER/ALWAYS rules)
131
236
  - `docs/architecture.md` (patterns, structure)
132
237
  - `docs/code-standards.md` (naming, quality)
@@ -137,6 +242,7 @@ Read relevant documentation:
137
242
  Compare refined objective against documentation:
138
243
 
139
244
  **IF deviation detected:**
245
+
140
246
  ```
141
247
  🚨 POTENTIAL DEVIATION
142
248
 
@@ -155,6 +261,7 @@ Your choice: _
155
261
  ```
156
262
 
157
263
  **IF user chooses B (Override):**
264
+
158
265
  ```
159
266
  ⚠️ OVERRIDE CONFIRMATION
160
267
 
@@ -167,67 +274,156 @@ Provide justification: _
167
274
  ```
168
275
 
169
276
  ---
277
+
278
+ ## Phase 1.5: SIMPLE Task Fast-Track
279
+
280
+ **IF complexity == "SIMPLE": Execute immediately without creating files**
281
+
282
+ 1. **Show in-chat plan:**
283
+
284
+ ```
285
+ ⚑ SIMPLE Task - Fast Execution
286
+
287
+ What: [1-line description]
288
+ File: [path]
289
+ Change: [specific modification]
290
+ Lines: ~[N] (estimated)
291
+
292
+ Execute now? (y/n): _
293
+ ```
294
+
295
+ 2. **IF user confirms ('y'):**
296
+ - Make the change immediately
297
+ - Show git diff preview
298
+ - Skip to Phase 3 (no branch creation if already on feature branch)
299
+ - Show: "βœ… Done. Run `/flow-commit` to commit."
300
+ - **END WORKFLOW** (no archiving needed)
301
+
302
+ 3. **IF user declines ('n'):**
303
+ - Cancel task
304
+ - **END WORKFLOW**
305
+
306
+ **Note:** SIMPLE tasks don't create work.md, status.json, or archive records.
307
+
308
+ ---
309
+
170
310
  ## Phase 2: Planning & Documentation
171
311
 
172
- **1. Read Required Documentation (MANDATORY)**
312
+ **⚠️ SKIP THIS PHASE IF complexity == "SIMPLE"**
173
313
 
174
- Before generating work.md, read relevant documentation:
175
- - `ai-instructions.md` β†’ Extract NEVER/ALWAYS rules
176
- - `docs/architecture.md` β†’ Identify layer, pattern, file structure
177
- - `docs/code-standards.md` β†’ Extract naming conventions, quality rules
178
- - IF touching database: `docs/data-model.md`
179
- - IF auth/security: `specs/security.md`
180
- - IF creating/modifying API: `docs/api.md`
181
- - IF tests required: `docs/testing.md`
314
+ **1. Read Required Documentation (Based on Complexity)**
315
+
316
+ **IF complexity == "MEDIUM":**
317
+
318
+ - `ai-instructions.md` (core rules)
319
+ - Load ONLY task-specific docs:
320
+ - Components β†’ `docs/components.md`
321
+ - Routing β†’ `docs/routing.md`
322
+ - State β†’ `docs/state-management.md`
323
+ - Styling β†’ `docs/styling.md`
324
+
325
+ **IF complexity == "COMPLEX":**
326
+
327
+ - `ai-instructions.md` (NEVER/ALWAYS rules)
328
+ - `docs/architecture.md` (layer, pattern, structure)
329
+ - Task-specific docs:
330
+ - Components β†’ `docs/components.md`
331
+ - Routing/Navigation β†’ `docs/routing.md`
332
+ - State β†’ `docs/state-management.md`
333
+ - API Integration β†’ `docs/api-integration.md`
334
+ - Testing β†’ `docs/testing.md`
335
+ - `docs/code-standards.md` (only if creating new files)
182
336
 
183
337
  **2. Analyze Existing Codebase (MANDATORY)**
184
338
 
185
339
  Find similar features/patterns in codebase:
186
- - Identify existing files to use as reference (e.g., ProductService.ts for UserService.ts)
340
+
341
+ - Identify existing files to use as reference (e.g., UserProfile.tsx for ProductCard.tsx)
187
342
  - Check naming conventions in actual code
188
343
  - Verify architectural consistency
189
- - Look for reusable components/services
344
+ - Look for reusable components/hooks
345
+
346
+ **3. Generate work.md (Conditional)**
347
+
348
+ **IF complexity == "MEDIUM":**
190
349
 
191
- **3. Generate work.md**
350
+ - Create simplified `.ai-flow/work/[task-name]/work.md` (~15-20 lines)
351
+ - Skip status.json
192
352
 
193
- Create single consolidated file: `.ai-flow/work/[task-name]/work.md`
353
+ **IF complexity == "COMPLEX":**
194
354
 
195
- **Structure** (~30-40 lines):
355
+ - Create full `.ai-flow/work/[task-name]/work.md` (~30-40 lines)
356
+ - Create `status.json` (see step 4)
357
+
358
+ **Structure for MEDIUM tasks** (~15-20 lines):
359
+
360
+ ```markdown
361
+ # [Type]: [Feature Name]
362
+
363
+ **Source**: [HU-XXX | Roadmap X.X | Manual]
364
+ **Files**: [2-5 files listed]
365
+ **Estimated**: [20-60 min]
366
+
367
+ ## Objective
368
+
369
+ [1 clear paragraph]
370
+
371
+ ## Tasks
372
+
373
+ - [ ] Task 1 β†’ path/Component.tsx
374
+ - [ ] Task 2 β†’ path/hook.ts
375
+ - [ ] Task 3 (optional tests)
376
+
377
+ ## Key Rules
378
+
379
+ - βœ… [1-2 relevant ALWAYS rules]
380
+ - ❌ [1-2 relevant NEVER rules]
381
+ ```
382
+
383
+ **Structure for COMPLEX tasks** (~30-40 lines):
196
384
 
197
385
  ```markdown
198
386
  # [Type]: [Feature Name]
199
387
 
200
388
  ## Context
389
+
201
390
  **Source**: HU-001-002 | Roadmap 2.3 | Manual [+ DEVIATION if override]
202
391
  **SP**: 5 | **Branch**: feature/user-auth | **Deps**: None
203
392
 
204
393
  ## Objective
394
+
205
395
  [1-2 clear paragraphs describing WHAT will be implemented]
206
396
 
207
397
  ## Documentation Constraints
398
+
208
399
  **Read**: ai-instructions.md, architecture.md, code-standards.md, [security.md]
209
400
 
210
401
  **Key Rules**:
402
+
211
403
  - βœ… ALWAYS: [List specific rules that apply]
212
404
  - ❌ NEVER: [List specific prohibitions]
213
405
  - πŸ“ Pattern: [Architectural pattern from docs]
214
406
  - πŸ“ Location: [File structure from architecture.md]
215
407
 
216
408
  ## Approach
409
+
217
410
  **Layer**: [Data | Business Logic | API | UI]
218
411
  **Files**: [List files to create/modify]
219
412
  **Reference**: [Existing file to follow as pattern]
220
413
 
221
414
  **Phases**:
415
+
222
416
  1. [Phase 1 description]
223
417
  2. [Phase 2 description]
224
418
  3. [Phase 3 description]
225
419
  4. [Phase 4 description]
226
420
 
227
421
  ## Tasks
422
+
228
423
  [SEE TASK GENERATION LOGIC BELOW]
229
424
 
230
425
  ## Validation
426
+
231
427
  - [ ] All NEVER/ALWAYS rules followed
232
428
  - [ ] Tests pass (coverage per docs/testing.md)
233
429
  - [ ] No hardcoded secrets
@@ -238,6 +434,7 @@ Create single consolidated file: `.ai-flow/work/[task-name]/work.md`
238
434
  **Task Generation Logic:**
239
435
 
240
436
  **IF source is User Story:**
437
+
241
438
  ```python
242
439
  tasks = read_user_story_tasks()
243
440
  if tasks.are_detailed(): # Has: path, constraints, SP, deps
@@ -254,6 +451,7 @@ else:
254
451
  ```
255
452
 
256
453
  **IF source is Roadmap:**
454
+
257
455
  ```python
258
456
  feature = read_roadmap_feature()
259
457
  if feature.has_detailed_tasks():
@@ -271,8 +469,10 @@ else:
271
469
  **IF source is Manual OR tasks need expansion:**
272
470
 
273
471
  Generate detailed tasks with this format:
472
+
274
473
  ```markdown
275
474
  ## Tasks
475
+
276
476
  **Source**: Manual | Roadmap X.X (expanded) | HU-XXX-XXX (expanded)
277
477
 
278
478
  - [ ] T001 [D] Create User entity β†’ src/entities/User.ts β€’ 1 SP
@@ -286,13 +486,16 @@ Generate detailed tasks with this format:
286
486
  ```
287
487
 
288
488
  **Task Detail Requirements:**
489
+
289
490
  - Specific file path
290
491
  - Pattern/reference to follow
291
492
  - Key constraints from docs
292
493
  - Dependencies (if applicable)
293
494
  - Story Points
294
495
 
295
- **4. Generate status.json**
496
+ **4. Generate status.json (ONLY for COMPLEX tasks)**
497
+
498
+ **IF complexity == "COMPLEX":**
296
499
 
297
500
  Create: `.ai-flow/work/[task-name]/status.json`
298
501
 
@@ -324,6 +527,7 @@ Create: `.ai-flow/work/[task-name]/status.json`
324
527
  **5. User Approval**
325
528
 
326
529
  Show work.md for review:
530
+
327
531
  ```
328
532
  πŸ“„ Generated: .ai-flow/work/[task-name]/work.md
329
533
 
@@ -335,10 +539,105 @@ Review work.md? (Yes/Edit/No): _
335
539
  - **No**: Cancel workflow
336
540
 
337
541
  ---
542
+
338
543
  ## Phase 3: Execution (Branch Creation)
339
544
 
340
545
  **Upon confirmation to start implementation:**
341
546
 
547
+ **πŸ›‘οΈ CRITICAL: Protected Branch Check**
548
+
549
+ ```bash
550
+ git branch --show-current
551
+ git status --porcelain
552
+ ```
553
+
554
+ **If current branch is protected** (`main`, `master`, `develop`, `development`):
555
+
556
+ **A) If there are uncommitted changes:**
557
+
558
+ 1. **Analyze changes to generate branch name:**
559
+
560
+ ```bash
561
+ git status --porcelain
562
+ git diff --stat
563
+ ```
564
+
565
+ **Detection rules:**
566
+ - **New components/features** β†’ `feature/`
567
+ - **Bug fixes** (error handling, corrections) β†’ `fix/`
568
+ - **Refactoring/Styling** (code improvements, CSS changes) β†’ `refactor/`
569
+ - **Configuration/Dependencies** (package.json, webpack, vite, etc.) β†’ `chore/`
570
+ - **Tests only** β†’ `test/`
571
+ - **Documentation only** β†’ `docs/`
572
+
573
+ **Naming strategy:**
574
+ - Extract component/page/feature name
575
+ - Remove extensions (.tsx, .jsx, .ts, .js)
576
+ - Convert to kebab-case
577
+ - Limit to 3-4 words max
578
+
579
+ **Examples:**
580
+
581
+ ```
582
+ src/components/UserProfile.tsx (new) β†’ feature/user-profile
583
+ src/pages/Dashboard.tsx (fix) β†’ fix/dashboard-page
584
+ src/hooks/useAuth.ts (modified) β†’ refactor/use-auth-hook
585
+ package.json + package-lock.json β†’ chore/update-dependencies
586
+ src/components/Auth* + src/pages/Login* β†’ feature/authentication
587
+ styles/ + components/ (multiple) β†’ refactor/ui-components
588
+ ```
589
+
590
+ 2. **Warn user:**
591
+
592
+ ```
593
+ ⚠️ Working on protected branch '[branch-name]' with uncommitted changes.
594
+
595
+ Analyzed changes:
596
+ - [file1] (new)
597
+ - [file2] (modified)
598
+ - [file3] (modified)
599
+ ... [N] more files
600
+
601
+ Detected type: [feature|fix|refactor|chore]
602
+ Suggested branch: [type]/[descriptive-slug]
603
+ ```
604
+
605
+ 3. **Offer options:**
606
+ - **A)** Create branch: `[type]/[suggested-name]` ⭐
607
+ - **B)** Edit branch name (user provides custom slug)
608
+ - **C)** Stash changes and continue: `git stash`
609
+ - **D)** Cancel
610
+
611
+ 4. If user chooses A:
612
+
613
+ ```bash
614
+ git checkout -b [type]/[suggested-name]
615
+ ```
616
+
617
+ Then show:
618
+
619
+ ```
620
+ βœ… Created and switched to '[type]/[suggested-name]'
621
+
622
+ Next steps:
623
+ 1. Run /flow-commit to commit these changes
624
+ 2. Return to protected branch: git checkout [protected-branch]
625
+ 3. Continue with /flow-work for new task
626
+
627
+ Or continue working on this branch if it's your intended work.
628
+ ```
629
+
630
+ 5. If user chooses B:
631
+ ```
632
+ Enter branch name (without type prefix): _
633
+ ```
634
+ Then create: `[detected-type]/[user-input]`
635
+
636
+ **B) If NO uncommitted changes:**
637
+
638
+ - βœ… Proceed normally - creating work branches FROM protected branches is correct workflow
639
+ - Protected branches serve as base for new work
640
+
342
641
  1. **Generate Branch Name**:
343
642
  - `feature/[slug]`
344
643
  - `refactor/[slug]`
@@ -351,72 +650,368 @@ Review work.md? (Yes/Edit/No): _
351
650
  - Update `status.json` progress
352
651
 
353
652
  ---
354
- ## Phase 4: Finalization & Archiving
355
-
356
- **When all tasks in `work.md` are complete (βœ…) and validated:**
357
-
358
- 1. **Update Source Documentation (Automatic - ALWAYS UPDATE BOTH IF BOTH EXIST)**:
359
-
360
- **Step 1a: Check and Update User Story (if exists)**
361
- - Look for User Story reference in `status.json` or work context
362
- - IF User Story `HU-XXX-XXX` exists:
363
- - Read `planning/user-stories/EP-XXX/HU-XXX-XXX.md`
364
- - Mark ALL DoD checklist items as complete: `- [ ]` β†’ `- [x]`
365
- - Add completion timestamp comment: `<!-- Completed: YYYY-MM-DD HH:MM -->`
366
- - Save file
367
-
368
- **Step 1b: Check and Update Roadmap (if exists)**
369
- - Look for Feature reference in `status.json` or work context
370
- - IF Feature exists in `planning/roadmap.md`:
371
- - Read `planning/roadmap.md`
372
- - Find the Feature section by name/number
373
- - Mark Feature checkbox as complete: `- [ ]` β†’ `- [x]`
374
- - Save file
375
-
376
- **Step 1c: Show Completion Summary**
377
- - IF both updated: "βœ… Updated roadmap.md (Feature X.X) AND HU-XXX-XXX.md (Y/Y DoD items)"
378
- - IF only roadmap: "βœ… Updated roadmap.md (Feature X.X)"
379
- - IF only user story: "βœ… Updated HU-XXX-XXX.md (Y/Y DoD items)"
380
- - IF neither exists: "⚠️ No roadmap or user story found to update"
381
-
382
- **Error Handling:**
383
- - If file doesn't exist: Log warning, continue with other file
384
- - If checkbox not found: Log warning with helpful message, continue
385
- - Never fail the entire finalization due to documentation update errors
386
-
387
- 2. **Sugerir PrΓ³ximos Pasos**:
388
- - **`/flow-check`**: Ejecutar tests y revisiΓ³n de cΓ³digo combinada.
389
- - **`/flow-docs-sync`**: Sincronizar la documentaciΓ³n tΓ©cnica.
390
- - **`/flow-commit`**: Crear commits atΓ³micos.
391
-
392
- 3. **Registro de Historial (AutomΓ‘tico tras aprobaciΓ³n)**:
393
- - Una vez el usuario confirma que el trabajo estΓ‘ listo para ser cerrado:
394
- - **Extraer metadata** de `status.json` y `work.md`:
395
- ```javascript
396
- // Campos del registro JSONL (10 campos):
397
- {
398
- task: string, // Nombre de la tarea (ej: "user-auth")
399
- type: string, // "feature" | "refactor" | "fix"
400
- src: string, // source: "HU-001-002" | "roadmap-2.3" | "manual"
401
- dur: number, // duraciΓ³n en minutos (completed - created)
402
- start: string, // timestamps.created (ISO 8601)
403
- end: string, // timestamps.completed (ISO 8601)
404
- tasks: number, // progress.totalTasks
405
- sp?: number, // Story Points extraΓ­dos de work.md (regex: "β€’ (\d+) SP")
406
- commits: number, // git.commits.length
407
- valid: boolean // validation.tests.passed && validation.lint.passed
408
- }
409
- ```
410
- - **Actualizar `status.json`**: Registrar `timestamps.completed` (ISO 8601).
411
- - **Append a `.ai-flow/archive/analytics.jsonl`**: Agregar 1 lΓ­nea con el objeto JSON (sin espacios ni saltos de lΓ­nea internos).
412
- - **Eliminar carpeta**: Remover `.ai-flow/work/[task-name]/` completa (incluye `work.md` y `status.json`).
413
- - **Cleanup**: Mantener limpia la carpeta `work` para que `/flow-work` detecte solo tareas activas.
414
-
415
- 4. **Resumen Final**:
416
- - Mostrar estadΓ­sticas finales: duraciΓ³n total (en minutos), commits realizados, tasks completadas, validaciΓ³n exitosa.
417
- - Ejemplo: `"βœ… Archivado: 125 min, 8/8 tasks, 3 commits, validaciΓ³n βœ“"`
653
+
654
+ ## Phase 4: Finalization (User-Controlled)
655
+
656
+ **⚠️ SKIP THIS PHASE IF complexity == "SIMPLE"** (already handled in Phase 1.5)
657
+
658
+ **Trigger Options:**
659
+
660
+ - User types: `/flow-work complete`
661
+ - All checkboxes in work.md marked complete
662
+ - User explicitly requests finalization
663
+
664
+ **CRITICAL: This phase requires EXPLICIT user confirmations at each step.**
665
+
666
+ ---
667
+
668
+ ### Step 1: Validation Check
669
+
670
+ ```
671
+ πŸ” Running validation...
672
+ ```
673
+
674
+ Execute:
675
+
676
+ ```bash
677
+ npm test # or project-specific test command
678
+ npm run lint # or project-specific lint command
679
+ ```
680
+
681
+ Show results:
682
+
683
+ ```
684
+ πŸ“Š Validation Results
685
+
686
+ Tests: [βœ… Passed | ❌ Failed (N tests)]
687
+ Lint: [βœ… Clean | ⚠️ N warnings | ❌ N errors]
688
+ Coverage: [X%]
689
+
690
+ Proceed with finalization?
691
+
692
+ a) Yes, continue ⭐
693
+ b) No, let me fix issues
694
+ c) Skip validation (not recommended)
695
+
696
+ Your choice: _
697
+ ```
698
+
699
+ - **'b'**: Return to Phase 3 for fixes, END finalization
700
+ - **'c'**: Show warning, ask confirmation again, then continue
701
+ - **'a'**: Continue to Step 2
702
+
703
+ ---
704
+
705
+ ### Step 2: Source Documentation Update (Interactive)
706
+
707
+ **Detect source references:**
708
+
709
+ ```python
710
+ source = extract_from_work_md_or_status_json()
711
+ # Returns: "HU-001-002" | "roadmap-2.3" | "manual" | None
712
+ ```
713
+
714
+ **IF source exists (HU or roadmap):**
715
+
716
+ ```
717
+ πŸ“š Update Source Documentation?
718
+
719
+ Found:
720
+ - planning/roadmap.md β†’ Feature 2.3 "User Profile Component"
721
+ - planning/user-stories/EP-001/HU-001-002.md
722
+
723
+ What to update?
724
+
725
+ a) Update both ⭐
726
+ b) Update roadmap only
727
+ c) Update user story only
728
+ d) Skip (I'll update manually later)
729
+
730
+ Your choice: _
731
+ ```
732
+
733
+ **Execute selected updates:**
734
+
735
+ - Read files
736
+ - Mark checkboxes as complete: `- [ ]` β†’ `- [x]`
737
+ - Add timestamp comment: `<!-- Completed: YYYY-MM-DD HH:MM -->`
738
+ - Save files
739
+
740
+ **Show confirmation:**
741
+
742
+ ```
743
+ βœ… Updated:
744
+ - planning/roadmap.md (Feature 2.3)
745
+ - planning/user-stories/EP-001/HU-001-002.md (5/5 DoD items)
746
+ ```
747
+
748
+ **IF update fails:**
749
+
750
+ ```
751
+ ❌ Failed to update [file]: [reason]
752
+
753
+ Options:
754
+ 1) Retry update
755
+ 2) Skip this file
756
+ 3) Cancel finalization
757
+
758
+ Your choice: _
759
+ ```
760
+
761
+ **IF source is "manual" or None:**
762
+
763
+ ```
764
+ ⏭️ No source documentation to update (manual task)
765
+ ```
418
766
 
419
767
  ---
768
+
769
+ ### Step 3: Archiving Decision (Explicit Confirmation)
770
+
771
+ **Show current state:**
772
+
773
+ ```bash
774
+ git diff --stat
775
+ git log --oneline origin/[base-branch]..HEAD
776
+ ```
777
+
778
+ **Present archiving options:**
779
+
780
+ ```
781
+ πŸ’Ύ Task Completion Options
782
+
783
+ Current work:
784
+ - Branch: [branch-name]
785
+ - Files changed: [N]
786
+ - Commits: [N]
787
+ - Duration: [X min]
788
+
789
+ What do you want to do?
790
+
791
+ a) Complete & Archive ⭐
792
+ β†’ Record analytics, delete work files, clean state
793
+
794
+ b) Complete & Keep
795
+ β†’ Record analytics, rename folder to [task]-completed
796
+
797
+ c) Mark as Paused
798
+ β†’ Keep work files for later resume
799
+
800
+ d) Cancel
801
+ β†’ Go back to editing
802
+
803
+ Your choice: _
804
+ ```
805
+
806
+ **IF 'a' (Complete & Archive):**
807
+
808
+ ```
809
+ βœ… Archiving task...
810
+ ```
811
+
812
+ 1. **Extract metadata:**
813
+
814
+ ```javascript
815
+ // IF complexity == "COMPLEX" (has status.json):
816
+ analytics = {
817
+ task: '[task-name]',
818
+ type: '[feature|refactor|fix]',
819
+ src: '[HU-001-002|roadmap-2.3|manual]',
820
+ dur: Math.round((completed - created) / 60000), // minutes
821
+ start: timestamps.created,
822
+ end: new Date().toISOString(),
823
+ tasks: progress.totalTasks,
824
+ sp: extract_story_points_from_work_md(),
825
+ commits: git.commits.length,
826
+ valid: validation.tests.passed && validation.lint.passed,
827
+ };
828
+
829
+ // IF complexity == "MEDIUM" (only work.md):
830
+ analytics = {
831
+ task: '[task-name]',
832
+ type: '[detected-from-folder-name]',
833
+ src: 'manual',
834
+ dur: estimate_duration_from_git_log(),
835
+ start: get_first_commit_timestamp(),
836
+ end: new Date().toISOString(),
837
+ tasks: count_checkboxes_in_work_md(),
838
+ sp: extract_story_points_from_work_md() || null,
839
+ commits: count_commits_in_branch(),
840
+ valid: validation_passed,
841
+ };
842
+ ```
843
+
844
+ 2. **Append to analytics:**
845
+
846
+ ```bash
847
+ echo '{json}' >> .ai-flow/archive/analytics.jsonl
848
+ ```
849
+
850
+ 3. **Delete work folder:**
851
+
852
+ ```bash
853
+ rm -rf .ai-flow/work/[task-name]/
854
+ ```
855
+
856
+ 4. **Show confirmation:**
857
+
858
+ ```
859
+ βœ… Task archived successfully
860
+
861
+ πŸ“Š Analytics recorded:
862
+ - Duration: [X] min
863
+ - Story Points: [N]
864
+ - Commits: [N]
865
+ - Validation: [βœ… Passed | ❌ Failed]
866
+ ```
867
+
868
+ **IF 'b' (Complete & Keep):**
869
+
870
+ 1. Record analytics (same as 'a')
871
+ 2. Rename folder:
872
+ ```bash
873
+ mv .ai-flow/work/[task] .ai-flow/work/[task]-completed/
874
+ ```
875
+ 3. Show: `βœ… Task marked complete. Files kept in: .ai-flow/work/[task]-completed/`
876
+
877
+ **IF 'c' (Mark as Paused):**
878
+
879
+ 1. Add marker file:
880
+ ```bash
881
+ echo "Paused: $(date)" > .ai-flow/work/[task]/PAUSED
882
+ ```
883
+ 2. Show: `⏸️ Task paused. Resume with: /flow-work`
884
+ 3. **END finalization**
885
+
886
+ **IF 'd' (Cancel):**
887
+
888
+ 1. Show: `❌ Finalization cancelled. Task remains active.`
889
+ 2. **END finalization**
890
+
891
+ ---
892
+
893
+ ### Step 4: Ticket Summary (Optional)
894
+
895
+ **Only ask if task was archived (option 'a' or 'b'):**
896
+
897
+ ```
898
+ πŸ“‹ Generate ticket summary?
899
+
900
+ (For ClickUp, Jira, Linear, Asana, Trello, GitHub Projects, etc.)
901
+
902
+ y/n: _
903
+ ```
904
+
905
+ **IF 'y':**
906
+
907
+ 1. Check if template exists:
908
+
909
+ ```bash
910
+ [ -f .ai-flow/prompts/shared/task-summary-template.md ]
911
+ ```
912
+
913
+ 2. **IF template exists:**
914
+ - Read template
915
+ - Extract data from:
916
+ - Last line of `analytics.jsonl`
917
+ - Git stats: `git diff --stat`, `git log --oneline`
918
+ - Branch info
919
+ - Populate template with real data
920
+ - Show formatted summary
921
+
922
+ 3. **IF template doesn't exist:**
923
+ - Generate basic summary:
924
+
925
+ ```
926
+ πŸ“‹ Task Summary
927
+
928
+ **Task**: [task-name]
929
+ **Type**: [feature|refactor|fix]
930
+ **Duration**: [X min]
931
+ **Story Points**: [N]
932
+ **Commits**: [N]
933
+ **Branch**: [branch-name]
934
+ **Status**: βœ… Complete
935
+
936
+ **Changes**:
937
+ [git diff --stat output]
938
+
939
+ **Commits**:
940
+ [git log --oneline output]
941
+ ```
942
+
943
+ 4. Show: `πŸ“‹ Copy the summary above to your ticket system`
944
+
945
+ **IF 'n':**
946
+
947
+ ```
948
+ ⏭️ Skipping ticket summary
949
+ ```
950
+
951
+ ---
952
+
953
+ ### Step 5: Git Push (Final Step)
954
+
955
+ ```
956
+ πŸš€ Push changes to remote?
957
+
958
+ git push origin [branch-name]
959
+
960
+ y/n: _
961
+ ```
962
+
963
+ **IF 'y':**
964
+
965
+ ```bash
966
+ git push origin [branch-name]
967
+ ```
968
+
969
+ Show result:
970
+
971
+ ```
972
+ βœ… Pushed to origin/[branch-name]
973
+
974
+ Next steps:
975
+ - Create Pull Request/Merge Request
976
+ - Request code review
977
+ - Update project board
978
+ ```
979
+
980
+ **IF 'n':**
981
+
982
+ ```
983
+ ⏭️ Skipping push
984
+
985
+ ⚠️ Remember to push later:
986
+ git push origin [branch-name]
987
+ ```
988
+
989
+ ---
990
+
991
+ ### Finalization Complete
992
+
993
+ ```
994
+ βœ… Task Finalization Complete
995
+
996
+ πŸ“Š Summary:
997
+ - [βœ…|⚠️] Validation passed
998
+ - [βœ…|⏭️] Documentation updated
999
+ - [βœ…|⏭️] Task archived
1000
+ - [βœ…|⏭️] Ticket summary generated
1001
+ - [βœ…|⏭️] Pushed to remote
1002
+
1003
+ Task: [task-name]
1004
+ Branch: [branch-name]
1005
+ Duration: [X min]
1006
+ Commits: [N]
1007
+
1008
+ πŸŽ‰ Great work!
1009
+ ```
1010
+
1011
+ **END WORKFLOW**
1012
+
1013
+ ---
1014
+
420
1015
  ## Orchestration Rules
421
1016
 
422
1017
  - **DRY Logic**: This file handles the high-level orchestration.
@@ -428,4 +1023,5 @@ Review work.md? (Yes/Edit/No): _
428
1023
  - **State Persistence**: Always read/write to `.ai-flow/work/[name]/status.json` to maintain state across sessions.
429
1024
 
430
1025
  ---
1026
+
431
1027
  **BEGIN EXECUTION when user runs `/flow-work [args]`**