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,105 @@ 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 method, refactor function, simple bug fix, update API endpoint
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
+ - Database changes β†’ `docs/data-model.md`
133
+ - API changes β†’ `docs/api.md`
134
+ - Security β†’ `specs/security.md`
135
+ - Skip architecture.md unless creating new patterns
136
+
137
+ **IF complexity == "COMPLEX":**
138
+
139
+ - Load `ai-instructions.md` (NEVER/ALWAYS rules)
140
+ - Load `docs/architecture.md` (patterns, structure)
141
+ - Load task-specific docs:
142
+ - Database β†’ `docs/data-model.md`
143
+ - Security/Auth β†’ `specs/security.md`
144
+ - API β†’ `docs/api.md`
145
+ - Tests β†’ `docs/testing.md`
146
+ - Load `docs/code-standards.md` only if creating new files
147
+
148
+ **Source Documentation (User Stories/Roadmap):**
149
+
150
+ **IF** `HU-XXX-XXX` or roadmap feature provided:
151
+
152
+ - **`planning/roadmap.md`**: Load for high-level scope
153
+ - **`planning/user-stories/**/HU-XXX-XXX.md`\*\*: Load for detailed requirements
57
154
 
58
155
  **2. Detail Level Detection (if Manual input):**
59
156
 
@@ -81,35 +178,40 @@ detail_level = analyze_description(input)
81
178
  **3. Interactive Refinement (Conditional):**
82
179
 
83
180
  **IF detail_level == "HIGH":**
181
+
84
182
  - Skip refinement questions
85
183
  - Proceed directly to Phase 2 (Planning)
86
184
  - Show: "βœ… Sufficient detail detected. Proceeding with planning..."
87
185
 
88
186
  **IF detail_level == "MEDIUM":**
187
+
89
188
  - Ask 1-2 targeted questions (only missing items)
90
189
  - Use Multiple Choice with defaults (⭐)
91
190
 
92
191
  **IF detail_level == "LOW":**
192
+
93
193
  - Full refinement flow (3-5 questions)
94
194
  - Use Multiple Choice with defaults (⭐)
95
195
  - Focus on: approach, scope, constraints, priorities
96
196
 
97
197
  **Example Interaction (LOW detail):**
198
+
98
199
  > πŸ“ I need to clarify some details for this feature:
200
+ >
99
201
  > 1. What authentication provider should we use? [default: A]
100
202
  > A) JWT (Local) ⭐
101
203
  > B) OAuth2 (Google/GitHub)
102
204
  > C) Firebase Auth
103
- >
104
205
  > 2. Should we implement audit logs for this? [default: B]
105
206
  > A) Yes
106
207
  > B) No ⭐
107
208
  >
108
- > Your answers (or Enter for defaults): _
209
+ > Your answers (or Enter for defaults): \_
109
210
 
110
211
  **4. Refined Objective Generation (if Manual):**
111
212
 
112
213
  After refinement, generate clear objective statement:
214
+
113
215
  ```
114
216
  βœ… Refined Objective:
115
217
 
@@ -127,6 +229,7 @@ Is this correct? (Yes/Edit/Cancel): _
127
229
  **5. Documentation Compliance Check:**
128
230
 
129
231
  Read relevant documentation:
232
+
130
233
  - `ai-instructions.md` (NEVER/ALWAYS rules)
131
234
  - `docs/architecture.md` (patterns, structure)
132
235
  - `docs/code-standards.md` (naming, quality)
@@ -137,6 +240,7 @@ Read relevant documentation:
137
240
  Compare refined objective against documentation:
138
241
 
139
242
  **IF deviation detected:**
243
+
140
244
  ```
141
245
  🚨 POTENTIAL DEVIATION
142
246
 
@@ -155,6 +259,7 @@ Your choice: _
155
259
  ```
156
260
 
157
261
  **IF user chooses B (Override):**
262
+
158
263
  ```
159
264
  ⚠️ OVERRIDE CONFIRMATION
160
265
 
@@ -167,67 +272,154 @@ Provide justification: _
167
272
  ```
168
273
 
169
274
  ---
275
+
276
+ ## Phase 1.5: SIMPLE Task Fast-Track
277
+
278
+ **IF complexity == "SIMPLE": Execute immediately without creating files**
279
+
280
+ 1. **Show in-chat plan:**
281
+
282
+ ```
283
+ ⚑ SIMPLE Task - Fast Execution
284
+
285
+ What: [1-line description]
286
+ File: [path]
287
+ Change: [specific modification]
288
+ Lines: ~[N] (estimated)
289
+
290
+ Execute now? (y/n): _
291
+ ```
292
+
293
+ 2. **IF user confirms ('y'):**
294
+ - Make the change immediately
295
+ - Show git diff preview
296
+ - Skip to Phase 3 (no branch creation if already on feature branch)
297
+ - Show: "βœ… Done. Run `/flow-commit` to commit."
298
+ - **END WORKFLOW** (no archiving needed)
299
+
300
+ 3. **IF user declines ('n'):**
301
+ - Cancel task
302
+ - **END WORKFLOW**
303
+
304
+ **Note:** SIMPLE tasks don't create work.md, status.json, or archive records.
305
+
306
+ ---
307
+
170
308
  ## Phase 2: Planning & Documentation
171
309
 
172
- **1. Read Required Documentation (MANDATORY)**
310
+ **⚠️ SKIP THIS PHASE IF complexity == "SIMPLE"**
173
311
 
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`
312
+ **1. Read Required Documentation (Based on Complexity)**
313
+
314
+ **IF complexity == "MEDIUM":**
315
+
316
+ - `ai-instructions.md` (core rules)
317
+ - Load ONLY task-specific docs:
318
+ - Database β†’ `docs/data-model.md`
319
+ - API β†’ `docs/api.md`
320
+ - Security β†’ `specs/security.md`
321
+
322
+ **IF complexity == "COMPLEX":**
323
+
324
+ - `ai-instructions.md` (NEVER/ALWAYS rules)
325
+ - `docs/architecture.md` (layer, pattern, structure)
326
+ - Task-specific docs:
327
+ - Database β†’ `docs/data-model.md`
328
+ - Security/Auth β†’ `specs/security.md`
329
+ - API β†’ `docs/api.md`
330
+ - Tests β†’ `docs/testing.md`
331
+ - `docs/code-standards.md` (only if creating new files)
182
332
 
183
333
  **2. Analyze Existing Codebase (MANDATORY)**
184
334
 
185
335
  Find similar features/patterns in codebase:
336
+
186
337
  - Identify existing files to use as reference (e.g., ProductService.ts for UserService.ts)
187
338
  - Check naming conventions in actual code
188
339
  - Verify architectural consistency
189
340
  - Look for reusable components/services
190
341
 
191
- **3. Generate work.md**
342
+ **3. Generate work.md (Conditional)**
343
+
344
+ **IF complexity == "MEDIUM":**
345
+
346
+ - Create simplified `.ai-flow/work/[task-name]/work.md` (~15-20 lines)
347
+ - Skip status.json
192
348
 
193
- Create single consolidated file: `.ai-flow/work/[task-name]/work.md`
349
+ **IF complexity == "COMPLEX":**
194
350
 
195
- **Structure** (~30-40 lines):
351
+ - Create full `.ai-flow/work/[task-name]/work.md` (~30-40 lines)
352
+ - Create `status.json` (see step 4)
353
+
354
+ **Structure for MEDIUM tasks** (~15-20 lines):
355
+
356
+ ```markdown
357
+ # [Type]: [Feature Name]
358
+
359
+ **Source**: [HU-XXX | Roadmap X.X | Manual]
360
+ **Files**: [2-5 files listed]
361
+ **Estimated**: [20-60 min]
362
+
363
+ ## Objective
364
+
365
+ [1 clear paragraph]
366
+
367
+ ## Tasks
368
+
369
+ - [ ] Task 1 β†’ path/file.ts
370
+ - [ ] Task 2 β†’ path/file.ts
371
+ - [ ] Task 3 (optional tests)
372
+
373
+ ## Key Rules
374
+
375
+ - βœ… [1-2 relevant ALWAYS rules]
376
+ - ❌ [1-2 relevant NEVER rules]
377
+ ```
378
+
379
+ **Structure for COMPLEX tasks** (~30-40 lines):
196
380
 
197
381
  ```markdown
198
382
  # [Type]: [Feature Name]
199
383
 
200
384
  ## Context
385
+
201
386
  **Source**: HU-001-002 | Roadmap 2.3 | Manual [+ DEVIATION if override]
202
387
  **SP**: 5 | **Branch**: feature/user-auth | **Deps**: None
203
388
 
204
389
  ## Objective
390
+
205
391
  [1-2 clear paragraphs describing WHAT will be implemented]
206
392
 
207
393
  ## Documentation Constraints
394
+
208
395
  **Read**: ai-instructions.md, architecture.md, code-standards.md, [security.md]
209
396
 
210
397
  **Key Rules**:
398
+
211
399
  - βœ… ALWAYS: [List specific rules that apply]
212
400
  - ❌ NEVER: [List specific prohibitions]
213
401
  - πŸ“ Pattern: [Architectural pattern from docs]
214
402
  - πŸ“ Location: [File structure from architecture.md]
215
403
 
216
404
  ## Approach
405
+
217
406
  **Layer**: [Data | Business Logic | API | UI]
218
407
  **Files**: [List files to create/modify]
219
408
  **Reference**: [Existing file to follow as pattern]
220
409
 
221
410
  **Phases**:
411
+
222
412
  1. [Phase 1 description]
223
413
  2. [Phase 2 description]
224
414
  3. [Phase 3 description]
225
415
  4. [Phase 4 description]
226
416
 
227
417
  ## Tasks
418
+
228
419
  [SEE TASK GENERATION LOGIC BELOW]
229
420
 
230
421
  ## Validation
422
+
231
423
  - [ ] All NEVER/ALWAYS rules followed
232
424
  - [ ] Tests pass (coverage per docs/testing.md)
233
425
  - [ ] No hardcoded secrets
@@ -238,6 +430,7 @@ Create single consolidated file: `.ai-flow/work/[task-name]/work.md`
238
430
  **Task Generation Logic:**
239
431
 
240
432
  **IF source is User Story:**
433
+
241
434
  ```python
242
435
  tasks = read_user_story_tasks()
243
436
  if tasks.are_detailed(): # Has: path, constraints, SP, deps
@@ -254,6 +447,7 @@ else:
254
447
  ```
255
448
 
256
449
  **IF source is Roadmap:**
450
+
257
451
  ```python
258
452
  feature = read_roadmap_feature()
259
453
  if feature.has_detailed_tasks():
@@ -271,8 +465,10 @@ else:
271
465
  **IF source is Manual OR tasks need expansion:**
272
466
 
273
467
  Generate detailed tasks with this format:
468
+
274
469
  ```markdown
275
470
  ## Tasks
471
+
276
472
  **Source**: Manual | Roadmap X.X (expanded) | HU-XXX-XXX (expanded)
277
473
 
278
474
  - [ ] T001 [D] Create User entity β†’ src/entities/User.ts β€’ 1 SP
@@ -286,13 +482,16 @@ Generate detailed tasks with this format:
286
482
  ```
287
483
 
288
484
  **Task Detail Requirements:**
485
+
289
486
  - Specific file path
290
487
  - Pattern/reference to follow
291
488
  - Key constraints from docs
292
489
  - Dependencies (if applicable)
293
490
  - Story Points
294
491
 
295
- **4. Generate status.json**
492
+ **4. Generate status.json (ONLY for COMPLEX tasks)**
493
+
494
+ **IF complexity == "COMPLEX":**
296
495
 
297
496
  Create: `.ai-flow/work/[task-name]/status.json`
298
497
 
@@ -324,6 +523,7 @@ Create: `.ai-flow/work/[task-name]/status.json`
324
523
  **5. User Approval**
325
524
 
326
525
  Show work.md for review:
526
+
327
527
  ```
328
528
  πŸ“„ Generated: .ai-flow/work/[task-name]/work.md
329
529
 
@@ -335,10 +535,105 @@ Review work.md? (Yes/Edit/No): _
335
535
  - **No**: Cancel workflow
336
536
 
337
537
  ---
538
+
338
539
  ## Phase 3: Execution (Branch Creation)
339
540
 
340
541
  **Upon confirmation to start implementation:**
341
542
 
543
+ **πŸ›‘οΈ CRITICAL: Protected Branch Check**
544
+
545
+ ```bash
546
+ git branch --show-current
547
+ git status --porcelain
548
+ ```
549
+
550
+ **If current branch is protected** (`main`, `master`, `develop`, `development`):
551
+
552
+ **A) If there are uncommitted changes:**
553
+
554
+ 1. **Analyze changes to generate branch name:**
555
+
556
+ ```bash
557
+ git status --porcelain
558
+ git diff --stat
559
+ ```
560
+
561
+ **Detection rules:**
562
+ - **New files** (untracked) β†’ `feature/`
563
+ - **Bug fixes** (keywords: fix, error, bug in commit message or file content) β†’ `fix/`
564
+ - **Refactoring** (modifications without new features) β†’ `refactor/`
565
+ - **Configuration/Dependencies** (package.json, tsconfig, .env, etc.) β†’ `chore/`
566
+ - **Tests only** β†’ `test/`
567
+ - **Documentation only** β†’ `docs/`
568
+
569
+ **Naming strategy:**
570
+ - Extract most significant file/module name
571
+ - Remove extensions and path prefixes
572
+ - Convert to kebab-case
573
+ - Limit to 3-4 words max
574
+
575
+ **Examples:**
576
+
577
+ ```
578
+ src/services/UserService.ts (new) β†’ feature/user-service
579
+ src/controllers/AuthController.ts (fix) β†’ fix/auth-controller
580
+ src/utils/validator.ts (modified) β†’ refactor/validator-utils
581
+ package.json + package-lock.json β†’ chore/update-dependencies
582
+ src/services/User* + tests/ β†’ feature/user-management
583
+ Multiple modules (auth + profile) β†’ feature/auth-profile-integration
584
+ ```
585
+
586
+ 2. **Warn user:**
587
+
588
+ ```
589
+ ⚠️ Working on protected branch '[branch-name]' with uncommitted changes.
590
+
591
+ Analyzed changes:
592
+ - [file1] (new)
593
+ - [file2] (modified)
594
+ - [file3] (modified)
595
+ ... [N] more files
596
+
597
+ Detected type: [feature|fix|refactor|chore]
598
+ Suggested branch: [type]/[descriptive-slug]
599
+ ```
600
+
601
+ 3. **Offer options:**
602
+ - **A)** Create branch: `[type]/[suggested-name]` ⭐
603
+ - **B)** Edit branch name (user provides custom slug)
604
+ - **C)** Stash changes and continue: `git stash`
605
+ - **D)** Cancel
606
+
607
+ 4. If user chooses A:
608
+
609
+ ```bash
610
+ git checkout -b [type]/[suggested-name]
611
+ ```
612
+
613
+ Then show:
614
+
615
+ ```
616
+ βœ… Created and switched to '[type]/[suggested-name]'
617
+
618
+ Next steps:
619
+ 1. Run /flow-commit to commit these changes
620
+ 2. Return to protected branch: git checkout [protected-branch]
621
+ 3. Continue with /flow-work for new task
622
+
623
+ Or continue working on this branch if it's your intended work.
624
+ ```
625
+
626
+ 5. If user chooses B:
627
+ ```
628
+ Enter branch name (without type prefix): _
629
+ ```
630
+ Then create: `[detected-type]/[user-input]`
631
+
632
+ **B) If NO uncommitted changes:**
633
+
634
+ - βœ… Proceed normally - creating work branches FROM protected branches is correct workflow
635
+ - Protected branches serve as base for new work
636
+
342
637
  1. **Generate Branch Name**:
343
638
  - `feature/[slug]`
344
639
  - `refactor/[slug]`
@@ -351,72 +646,368 @@ Review work.md? (Yes/Edit/No): _
351
646
  - Update `status.json` progress
352
647
 
353
648
  ---
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 βœ“"`
649
+
650
+ ## Phase 4: Finalization (User-Controlled)
651
+
652
+ **⚠️ SKIP THIS PHASE IF complexity == "SIMPLE"** (already handled in Phase 1.5)
653
+
654
+ **Trigger Options:**
655
+
656
+ - User types: `/flow-work complete`
657
+ - All checkboxes in work.md marked complete
658
+ - User explicitly requests finalization
659
+
660
+ **CRITICAL: This phase requires EXPLICIT user confirmations at each step.**
661
+
662
+ ---
663
+
664
+ ### Step 1: Validation Check
665
+
666
+ ```
667
+ πŸ” Running validation...
668
+ ```
669
+
670
+ Execute:
671
+
672
+ ```bash
673
+ npm test # or project-specific test command
674
+ npm run lint # or project-specific lint command
675
+ ```
676
+
677
+ Show results:
678
+
679
+ ```
680
+ πŸ“Š Validation Results
681
+
682
+ Tests: [βœ… Passed | ❌ Failed (N tests)]
683
+ Lint: [βœ… Clean | ⚠️ N warnings | ❌ N errors]
684
+ Coverage: [X%]
685
+
686
+ Proceed with finalization?
687
+
688
+ a) Yes, continue ⭐
689
+ b) No, let me fix issues
690
+ c) Skip validation (not recommended)
691
+
692
+ Your choice: _
693
+ ```
694
+
695
+ - **'b'**: Return to Phase 3 for fixes, END finalization
696
+ - **'c'**: Show warning, ask confirmation again, then continue
697
+ - **'a'**: Continue to Step 2
698
+
699
+ ---
700
+
701
+ ### Step 2: Source Documentation Update (Interactive)
702
+
703
+ **Detect source references:**
704
+
705
+ ```python
706
+ source = extract_from_work_md_or_status_json()
707
+ # Returns: "HU-001-002" | "roadmap-2.3" | "manual" | None
708
+ ```
709
+
710
+ **IF source exists (HU or roadmap):**
711
+
712
+ ```
713
+ πŸ“š Update Source Documentation?
714
+
715
+ Found:
716
+ - planning/roadmap.md β†’ Feature 2.3 "User Authentication"
717
+ - planning/user-stories/EP-001/HU-001-002.md
718
+
719
+ What to update?
720
+
721
+ a) Update both ⭐
722
+ b) Update roadmap only
723
+ c) Update user story only
724
+ d) Skip (I'll update manually later)
725
+
726
+ Your choice: _
727
+ ```
728
+
729
+ **Execute selected updates:**
730
+
731
+ - Read files
732
+ - Mark checkboxes as complete: `- [ ]` β†’ `- [x]`
733
+ - Add timestamp comment: `<!-- Completed: YYYY-MM-DD HH:MM -->`
734
+ - Save files
735
+
736
+ **Show confirmation:**
737
+
738
+ ```
739
+ βœ… Updated:
740
+ - planning/roadmap.md (Feature 2.3)
741
+ - planning/user-stories/EP-001/HU-001-002.md (5/5 DoD items)
742
+ ```
743
+
744
+ **IF update fails:**
745
+
746
+ ```
747
+ ❌ Failed to update [file]: [reason]
748
+
749
+ Options:
750
+ 1) Retry update
751
+ 2) Skip this file
752
+ 3) Cancel finalization
753
+
754
+ Your choice: _
755
+ ```
756
+
757
+ **IF source is "manual" or None:**
758
+
759
+ ```
760
+ ⏭️ No source documentation to update (manual task)
761
+ ```
418
762
 
419
763
  ---
764
+
765
+ ### Step 3: Archiving Decision (Explicit Confirmation)
766
+
767
+ **Show current state:**
768
+
769
+ ```bash
770
+ git diff --stat
771
+ git log --oneline origin/[base-branch]..HEAD
772
+ ```
773
+
774
+ **Present archiving options:**
775
+
776
+ ```
777
+ πŸ’Ύ Task Completion Options
778
+
779
+ Current work:
780
+ - Branch: [branch-name]
781
+ - Files changed: [N]
782
+ - Commits: [N]
783
+ - Duration: [X min]
784
+
785
+ What do you want to do?
786
+
787
+ a) Complete & Archive ⭐
788
+ β†’ Record analytics, delete work files, clean state
789
+
790
+ b) Complete & Keep
791
+ β†’ Record analytics, rename folder to [task]-completed
792
+
793
+ c) Mark as Paused
794
+ β†’ Keep work files for later resume
795
+
796
+ d) Cancel
797
+ β†’ Go back to editing
798
+
799
+ Your choice: _
800
+ ```
801
+
802
+ **IF 'a' (Complete & Archive):**
803
+
804
+ ```
805
+ βœ… Archiving task...
806
+ ```
807
+
808
+ 1. **Extract metadata:**
809
+
810
+ ```javascript
811
+ // IF complexity == "COMPLEX" (has status.json):
812
+ analytics = {
813
+ task: '[task-name]',
814
+ type: '[feature|refactor|fix]',
815
+ src: '[HU-001-002|roadmap-2.3|manual]',
816
+ dur: Math.round((completed - created) / 60000), // minutes
817
+ start: timestamps.created,
818
+ end: new Date().toISOString(),
819
+ tasks: progress.totalTasks,
820
+ sp: extract_story_points_from_work_md(),
821
+ commits: git.commits.length,
822
+ valid: validation.tests.passed && validation.lint.passed,
823
+ };
824
+
825
+ // IF complexity == "MEDIUM" (only work.md):
826
+ analytics = {
827
+ task: '[task-name]',
828
+ type: '[detected-from-folder-name]',
829
+ src: 'manual',
830
+ dur: estimate_duration_from_git_log(),
831
+ start: get_first_commit_timestamp(),
832
+ end: new Date().toISOString(),
833
+ tasks: count_checkboxes_in_work_md(),
834
+ sp: extract_story_points_from_work_md() || null,
835
+ commits: count_commits_in_branch(),
836
+ valid: validation_passed,
837
+ };
838
+ ```
839
+
840
+ 2. **Append to analytics:**
841
+
842
+ ```bash
843
+ echo '{json}' >> .ai-flow/archive/analytics.jsonl
844
+ ```
845
+
846
+ 3. **Delete work folder:**
847
+
848
+ ```bash
849
+ rm -rf .ai-flow/work/[task-name]/
850
+ ```
851
+
852
+ 4. **Show confirmation:**
853
+
854
+ ```
855
+ βœ… Task archived successfully
856
+
857
+ πŸ“Š Analytics recorded:
858
+ - Duration: [X] min
859
+ - Story Points: [N]
860
+ - Commits: [N]
861
+ - Validation: [βœ… Passed | ❌ Failed]
862
+ ```
863
+
864
+ **IF 'b' (Complete & Keep):**
865
+
866
+ 1. Record analytics (same as 'a')
867
+ 2. Rename folder:
868
+ ```bash
869
+ mv .ai-flow/work/[task] .ai-flow/work/[task]-completed/
870
+ ```
871
+ 3. Show: `βœ… Task marked complete. Files kept in: .ai-flow/work/[task]-completed/`
872
+
873
+ **IF 'c' (Mark as Paused):**
874
+
875
+ 1. Add marker file:
876
+ ```bash
877
+ echo "Paused: $(date)" > .ai-flow/work/[task]/PAUSED
878
+ ```
879
+ 2. Show: `⏸️ Task paused. Resume with: /flow-work`
880
+ 3. **END finalization**
881
+
882
+ **IF 'd' (Cancel):**
883
+
884
+ 1. Show: `❌ Finalization cancelled. Task remains active.`
885
+ 2. **END finalization**
886
+
887
+ ---
888
+
889
+ ### Step 4: Ticket Summary (Optional)
890
+
891
+ **Only ask if task was archived (option 'a' or 'b'):**
892
+
893
+ ```
894
+ πŸ“‹ Generate ticket summary?
895
+
896
+ (For ClickUp, Jira, Linear, Asana, Trello, GitHub Projects, etc.)
897
+
898
+ y/n: _
899
+ ```
900
+
901
+ **IF 'y':**
902
+
903
+ 1. Check if template exists:
904
+
905
+ ```bash
906
+ [ -f .ai-flow/prompts/shared/task-summary-template.md ]
907
+ ```
908
+
909
+ 2. **IF template exists:**
910
+ - Read template
911
+ - Extract data from:
912
+ - Last line of `analytics.jsonl`
913
+ - Git stats: `git diff --stat`, `git log --oneline`
914
+ - Branch info
915
+ - Populate template with real data
916
+ - Show formatted summary
917
+
918
+ 3. **IF template doesn't exist:**
919
+ - Generate basic summary:
920
+
921
+ ```
922
+ πŸ“‹ Task Summary
923
+
924
+ **Task**: [task-name]
925
+ **Type**: [feature|refactor|fix]
926
+ **Duration**: [X min]
927
+ **Story Points**: [N]
928
+ **Commits**: [N]
929
+ **Branch**: [branch-name]
930
+ **Status**: βœ… Complete
931
+
932
+ **Changes**:
933
+ [git diff --stat output]
934
+
935
+ **Commits**:
936
+ [git log --oneline output]
937
+ ```
938
+
939
+ 4. Show: `πŸ“‹ Copy the summary above to your ticket system`
940
+
941
+ **IF 'n':**
942
+
943
+ ```
944
+ ⏭️ Skipping ticket summary
945
+ ```
946
+
947
+ ---
948
+
949
+ ### Step 5: Git Push (Final Step)
950
+
951
+ ```
952
+ πŸš€ Push changes to remote?
953
+
954
+ git push origin [branch-name]
955
+
956
+ y/n: _
957
+ ```
958
+
959
+ **IF 'y':**
960
+
961
+ ```bash
962
+ git push origin [branch-name]
963
+ ```
964
+
965
+ Show result:
966
+
967
+ ```
968
+ βœ… Pushed to origin/[branch-name]
969
+
970
+ Next steps:
971
+ - Create Pull Request/Merge Request
972
+ - Request code review
973
+ - Update project board
974
+ ```
975
+
976
+ **IF 'n':**
977
+
978
+ ```
979
+ ⏭️ Skipping push
980
+
981
+ ⚠️ Remember to push later:
982
+ git push origin [branch-name]
983
+ ```
984
+
985
+ ---
986
+
987
+ ### Finalization Complete
988
+
989
+ ```
990
+ βœ… Task Finalization Complete
991
+
992
+ πŸ“Š Summary:
993
+ - [βœ…|⚠️] Validation passed
994
+ - [βœ…|⏭️] Documentation updated
995
+ - [βœ…|⏭️] Task archived
996
+ - [βœ…|⏭️] Ticket summary generated
997
+ - [βœ…|⏭️] Pushed to remote
998
+
999
+ Task: [task-name]
1000
+ Branch: [branch-name]
1001
+ Duration: [X min]
1002
+ Commits: [N]
1003
+
1004
+ πŸŽ‰ Great work!
1005
+ ```
1006
+
1007
+ **END WORKFLOW**
1008
+
1009
+ ---
1010
+
420
1011
  ## Orchestration Rules
421
1012
 
422
1013
  - **DRY Logic**: This file handles the high-level orchestration.
@@ -428,4 +1019,5 @@ Review work.md? (Yes/Edit/No): _
428
1019
  - **State Persistence**: Always read/write to `.ai-flow/work/[name]/status.json` to maintain state across sessions.
429
1020
 
430
1021
  ---
1022
+
431
1023
  **BEGIN EXECUTION when user runs `/flow-work [args]`**