ai-flow-dev 2.1.9 → 2.2.1

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 (77) hide show
  1. package/README.md +26 -29
  2. package/dist/cli.js +10 -4
  3. package/dist/cli.js.map +1 -1
  4. package/package.json +1 -1
  5. package/prompts/backend/flow-build-phase-0.md +278 -1738
  6. package/prompts/backend/flow-build-phase-1.md +19 -0
  7. package/prompts/backend/flow-build-phase-10.md +1 -0
  8. package/prompts/backend/flow-build-phase-2.md +19 -0
  9. package/prompts/backend/flow-build-phase-3.md +19 -0
  10. package/prompts/backend/flow-build-phase-4.md +19 -0
  11. package/prompts/backend/flow-build-phase-5.md +19 -0
  12. package/prompts/backend/flow-build-phase-6.md +19 -0
  13. package/prompts/backend/flow-build-phase-7.md +19 -0
  14. package/prompts/backend/flow-build-phase-8.md +6 -7
  15. package/prompts/backend/flow-build-phase-9.md +15 -0
  16. package/prompts/backend/flow-build.md +59 -836
  17. package/prompts/backend/flow-check-review.md +20 -0
  18. package/prompts/backend/flow-check-test.md +14 -0
  19. package/prompts/backend/flow-check.md +65 -0
  20. package/prompts/backend/flow-commit.md +51 -0
  21. package/prompts/backend/flow-docs-sync.md +53 -53
  22. package/prompts/backend/flow-work-feature.md +42 -0
  23. package/prompts/backend/flow-work-fix.md +33 -0
  24. package/prompts/backend/flow-work-refactor.md +32 -0
  25. package/prompts/backend/flow-work-resume.md +32 -0
  26. package/prompts/backend/flow-work.md +127 -0
  27. package/prompts/frontend/flow-build-phase-0.md +323 -426
  28. package/prompts/frontend/flow-build-phase-1.md +433 -404
  29. package/prompts/frontend/flow-build-phase-10.md +33 -0
  30. package/prompts/frontend/flow-build-phase-2.md +508 -872
  31. package/prompts/frontend/flow-build-phase-3.md +629 -562
  32. package/prompts/frontend/flow-build-phase-4.md +438 -382
  33. package/prompts/frontend/flow-build-phase-5.md +559 -362
  34. package/prompts/frontend/flow-build-phase-6.md +383 -452
  35. package/prompts/frontend/flow-build-phase-7.md +818 -392
  36. package/prompts/frontend/flow-build-phase-8.md +27 -16
  37. package/prompts/frontend/flow-build-phase-9.md +94 -0
  38. package/prompts/frontend/flow-build.md +68 -414
  39. package/prompts/frontend/flow-check-review.md +20 -0
  40. package/prompts/frontend/flow-check-test.md +14 -0
  41. package/prompts/frontend/flow-check.md +65 -0
  42. package/prompts/frontend/flow-commit.md +51 -0
  43. package/prompts/frontend/flow-docs-sync.md +36 -34
  44. package/prompts/frontend/flow-work-feature.md +42 -0
  45. package/prompts/frontend/flow-work-fix.md +33 -0
  46. package/prompts/frontend/flow-work-refactor.md +32 -0
  47. package/prompts/frontend/flow-work-resume.md +32 -0
  48. package/prompts/frontend/flow-work.md +127 -0
  49. package/prompts/mobile/flow-build-phase-0.md +335 -319
  50. package/prompts/mobile/flow-build-phase-1.md +438 -493
  51. package/prompts/mobile/flow-build-phase-10.md +32 -0
  52. package/prompts/mobile/flow-build-phase-2.md +458 -464
  53. package/prompts/mobile/flow-build-phase-3.md +613 -487
  54. package/prompts/mobile/flow-build-phase-4.md +439 -258
  55. package/prompts/mobile/flow-build-phase-5.md +582 -250
  56. package/prompts/mobile/flow-build-phase-6.md +389 -359
  57. package/prompts/mobile/flow-build-phase-7.md +871 -285
  58. package/prompts/mobile/flow-build-phase-8.md +27 -16
  59. package/prompts/mobile/flow-build-phase-9.md +90 -0
  60. package/prompts/mobile/flow-build.md +67 -426
  61. package/prompts/mobile/flow-check-review.md +20 -0
  62. package/prompts/mobile/flow-check-test.md +14 -0
  63. package/prompts/mobile/flow-check.md +65 -0
  64. package/prompts/mobile/flow-commit.md +51 -0
  65. package/prompts/mobile/flow-docs-sync.md +37 -40
  66. package/prompts/mobile/flow-work-feature.md +42 -0
  67. package/prompts/mobile/flow-work-fix.md +33 -0
  68. package/prompts/mobile/flow-work-refactor.md +32 -0
  69. package/prompts/mobile/flow-work-resume.md +32 -0
  70. package/prompts/mobile/flow-work.md +127 -0
  71. package/prompts/shared/smart-skip-preflight.md +214 -0
  72. package/prompts/backend/flow-dev-commit.md +0 -829
  73. package/prompts/backend/flow-dev-feature.md +0 -1948
  74. package/prompts/backend/flow-dev-fix.md +0 -952
  75. package/prompts/backend/flow-dev-refactor.md +0 -690
  76. package/prompts/backend/flow-dev-review.md +0 -372
  77. package/prompts/backend/flow-dev-work.md +0 -1081
@@ -1,515 +1,412 @@
1
- # Phase 0: Context Discovery (Frontend)
1
+ ## PHASE 0: Context Discovery (2-5 min)
2
2
 
3
- **⚡ AUTOMATED ANALYSIS - Minimal User Input Required**
3
+ > **Order for this phase:** ALWAYS executed FIRST if an existing project is detected. Skip ONLY for new projects.
4
4
 
5
- This phase automatically analyzes your existing frontend codebase to pre-populate answers for the build questionnaire.
6
- ---
7
- ## 🎯 Objective
5
+ > **📌 Scope-based behavior:**
6
+ > - **Interactive Mode:** Ask user for permission to scan files layer by layer.
7
+ > - **Autonomous Mode:** Scan all layers automatically and present the final report.
8
8
 
9
- Detect the current frontend stack, architecture patterns, and configuration from existing code to:
9
+ ### Objective
10
+ Efficiently analyze existing projects using a **layered, incremental approach**.
10
11
 
11
- 1. **Skip redundant questions** - Don't ask what can be detected
12
- 2. **Validate assumptions** - Confirm detected patterns with user
13
- 3. **Save time** - Reduce questionnaire from ~90 min to ~40 min
14
- 4. **Maintain accuracy** - User can override any detection
15
- ---
16
- ## 📋 Detection Layers (Progressive)
12
+ ---
17
13
 
18
- ### Layer 0: Cache Check (0-2 seconds)
14
+ ## 🚫 Critical Exclusion Rules
15
+ To avoid false-positive detections, **IGNORE** the following folders and files during all detection steps:
16
+ - `.ai-flow/` (contains AI Flow internal cache and prompts)
17
+ - `.agent/` (contains AI workflows)
18
+ - `docs/` and `specs/` (if they contain AI Flow generated documentation)
19
+ - `project-brief.md`, `ai-instructions.md`, `AGENT.md`
19
20
 
20
- Check if `.ai-flow/cache/frontend-context.json` exists and is fresh (<7 days old).
21
+ **A project is considered "Existing" only if it contains functional source code or framework configuration files OUTSIDE these excluded paths.**
22
+
23
+ ---
24
+
25
+ ## 0.0 Check for Existing Analysis (Layer 0)
26
+
27
+ Check if `.ai-flow/cache/docs-analysis.json` exists and is fresh.
21
28
 
22
29
  **If found:**
30
+ Ask user to use cached analysis or re-analyze.
23
31
 
24
- ```json
25
- {
26
- "framework": "React",
27
- "frameworkVersion": "18.2.0",
28
- "buildTool": "Vite",
29
- "typescript": true,
30
- "stateManagement": "Zustand",
31
- "styling": "Tailwind CSS",
32
- "componentPattern": "Atomic Design",
33
- "lastAnalyzed": "2025-01-20T10:30:00Z"
34
- }
35
- ```
32
+ **If not found:**
33
+ Proceed to Layer 1.
36
34
 
37
- **Action:** Ask user: "Found cached analysis from X days ago. Use it? (Y/n)"
38
-
39
- **If yes:** Skip to validation step
40
-
41
- **If no or cache doesn't exist:** Proceed to Layer 1
42
- ---
43
- ### Layer 1: Fast Metadata Scan (10-20 seconds)
44
-
45
- **Purpose:** Detect framework, build tool, package manager, TypeScript
46
-
47
- #### Files to Check
48
-
49
- 1. **package.json** (REQUIRED)
50
- 2. **vite.config._ / webpack.config._ / angular.json** (build tool)
51
- 3. **tsconfig.json** (TypeScript)
52
- 4. **tailwind.config._ / postcss.config._** (styling)
53
-
54
- #### Detection Logic
55
-
56
- ```typescript
57
- // 1. Read package.json
58
- const pkg = JSON.parse(await fs.readFile('package.json', 'utf-8'));
59
-
60
- // 2. Detect UI Framework
61
- const framework = pkg.dependencies?.react
62
- ? 'React'
63
- : pkg.dependencies?.vue
64
- ? 'Vue'
65
- : pkg.dependencies?.['@angular/core']
66
- ? 'Angular'
67
- : pkg.dependencies?.svelte
68
- ? 'Svelte'
69
- : pkg.dependencies?.['solid-js']
70
- ? 'Solid'
71
- : null;
72
-
73
- // 3. Detect Meta-Framework
74
- const metaFramework = pkg.dependencies?.next
75
- ? 'Next.js'
76
- : pkg.dependencies?.nuxt
77
- ? 'Nuxt'
78
- : pkg.dependencies?.['@analogjs/platform']
79
- ? 'Analog'
80
- : pkg.dependencies?.['@sveltejs/kit']
81
- ? 'SvelteKit'
82
- : pkg.dependencies?.['solid-start']
83
- ? 'Solid Start'
84
- : null;
85
-
86
- // 4. Detect Build Tool
87
- const buildTool =
88
- (await fs.exists('vite.config.ts')) || (await fs.exists('vite.config.js'))
89
- ? 'Vite'
90
- : (await fs.exists('webpack.config.js'))
91
- ? 'Webpack'
92
- : (await fs.exists('angular.json'))
93
- ? 'Angular CLI'
94
- : (await fs.exists('rollup.config.js'))
95
- ? 'Rollup'
96
- : metaFramework
97
- ? `${metaFramework} (built-in)`
98
- : 'Unknown';
99
-
100
- // 5. Detect TypeScript
101
- const typescript = await fs.exists('tsconfig.json');
102
-
103
- // 6. Detect State Management
104
- const stateManagement = pkg.dependencies?.zustand
105
- ? 'Zustand'
106
- : pkg.dependencies?.['@reduxjs/toolkit']
107
- ? 'Redux Toolkit'
108
- : pkg.dependencies?.pinia
109
- ? 'Pinia'
110
- : pkg.dependencies?.['@ngrx/store']
111
- ? 'NgRx'
112
- : pkg.dependencies?.xstate
113
- ? 'XState'
114
- : null;
115
-
116
- // 7. Detect Data Fetching
117
- const dataFetching =
118
- pkg.dependencies?.['@tanstack/react-query'] || pkg.dependencies?.['@tanstack/vue-query']
119
- ? 'TanStack Query'
120
- : pkg.dependencies?.swr
121
- ? 'SWR'
122
- : pkg.dependencies?.['@apollo/client']
123
- ? 'Apollo Client'
124
- : pkg.dependencies?.['@urql/core']
125
- ? 'urql'
126
- : null;
127
-
128
- // 8. Detect Styling
129
- const styling =
130
- pkg.devDependencies?.tailwindcss || pkg.dependencies?.tailwindcss
131
- ? 'Tailwind CSS'
132
- : pkg.dependencies?.['styled-components']
133
- ? 'Styled Components'
134
- : pkg.dependencies?.['@emotion/react']
135
- ? 'Emotion'
136
- : (await fs.exists('*.module.css'))
137
- ? 'CSS Modules'
138
- : pkg.dependencies?.sass || pkg.devDependencies?.sass
139
- ? 'Sass/SCSS'
140
- : null;
141
-
142
- // 9. Detect Component Library
143
- const componentLibrary = pkg.dependencies?.['@mui/material']
144
- ? 'Material UI'
145
- : pkg.dependencies?.['@chakra-ui/react']
146
- ? 'Chakra UI'
147
- : pkg.dependencies?.antd
148
- ? 'Ant Design'
149
- : pkg.dependencies?.vuetify
150
- ? 'Vuetify'
151
- : pkg.dependencies?.['@angular/material']
152
- ? 'Angular Material'
153
- : pkg.dependencies?.['@shadcn/ui']
154
- ? 'shadcn/ui'
155
- : null;
156
-
157
- // 10. Detect Testing
158
- const unitTest = pkg.devDependencies?.vitest
159
- ? 'Vitest'
160
- : pkg.devDependencies?.jest
161
- ? 'Jest'
162
- : pkg.devDependencies?.['@jest/core']
163
- ? 'Jest'
164
- : null;
165
-
166
- const e2eTest = pkg.devDependencies?.['@playwright/test']
167
- ? 'Playwright'
168
- : pkg.devDependencies?.cypress
169
- ? 'Cypress'
170
- : pkg.devDependencies?.puppeteer
171
- ? 'Puppeteer'
172
- : null;
173
- ```
35
+ ---
174
36
 
175
- #### Layer 1 Output
37
+ // turbo
38
+ ## ⚡ Layer 1: Fast Metadata Scan (10-20 seconds)
176
39
 
177
- ```
178
- ✅ DETECTED:
179
-
180
- Framework: React 18.2.0 (with Next.js 14.0.0)
181
- Build Tool: Vite 5.0.0
182
- TypeScript: Yes
183
- State Management: Zustand 4.4.0
184
- Data Fetching: TanStack Query 5.0.0
185
- Styling: Tailwind CSS 3.3.0
186
- Component Library: None
187
- Testing: Vitest + Playwright
188
-
189
- Continue to Layer 2 for structural analysis? (Y/n)
190
- ```
191
- ---
192
- ### Layer 2: Structural Analysis (30-90 seconds)
40
+ **Purpose:** Detect framework, language, build tool, and existing AI configurations.
193
41
 
194
- **Purpose:** Analyze component structure, routing, and architecture patterns
42
+ **Context Links:**
43
+ - Node.js: [package.json](file:///package.json)
44
+ - Python: [requirements.txt](file:///requirements.txt) | [pyproject.toml](file:///pyproject.toml)
45
+ - PHP: [composer.json](file:///composer.json)
46
+ - Go: [go.mod](file:///go.mod)
47
+ - Java: [pom.xml](file:///pom.xml) | [build.gradle](file:///build.gradle)
195
48
 
196
- #### Files to Analyze
49
+ ### 0.1.1 Universal Tech Stack Detection
50
+ **Action:** Use your internal knowledge to detect the language and framework by scanning the root configuration files (package.json, pyproject.toml, etc.).
197
51
 
198
- - **Component files:** `src/**/*.{jsx,tsx,vue,svelte}`
199
- - **Routes:** `src/routes/**`, `src/pages/**`, `app/**`
200
- - **Store files:** `src/store/**`, `src/state/**`
201
- - **Config files:** `src/config/**`
52
+ **Detect (but don't be limited to):**
53
+ - **Node.js:** NestJS, Express, Fastify, etc.
54
+ - **Python:** FastAPI, Django, Flask, etc.
55
+ - **PHP:** Laravel, Symfony, etc.
56
+ - **Java/Kotlin:** Spring Boot, Micronaut, Ktor, etc.
57
+ - **Go:** Gin, Echo, Fiber, etc.
58
+ - **C#/.NET, Ruby, Rust, Elixir.**
202
59
 
203
- #### Detection Patterns
60
+ ### 0.1.2 Find AI & Documentation
61
+ - Find existing AI configs (`AGENT.md`, `.cursorrules`, etc.)
62
+ - Scan for `README.md` and existing `docs/`.
204
63
 
205
- ```typescript
206
- // 1. Component Pattern Detection
207
- const componentPattern = detectComponentPattern(srcFiles);
64
+ ### Layer 1 Output
65
+ Show a summary of detected Name, Language, Framework, ORM, and Documentation files.
208
66
 
209
- function detectComponentPattern(files: string[]): string {
210
- const hasAtomic = files.some(
211
- (f) => f.includes('/atoms/') || f.includes('/molecules/') || f.includes('/organisms/')
212
- );
213
- const hasFeatures = files.some((f) => f.includes('/features/'));
214
- const hasDomains = files.some((f) => f.includes('/domains/'));
215
- const hasPages = files.some((f) => f.includes('/pages/'));
67
+ ---
216
68
 
217
- if (hasAtomic) return 'Atomic Design';
218
- if (hasFeatures) return 'Feature-based';
219
- if (hasDomains) return 'Domain-driven';
220
- if (hasPages) return 'Pages-based';
221
- return 'Flat';
222
- }
69
+ ## 0.2 Layer 2: Structural Analysis (30-90 seconds)
223
70
 
224
- // 2. Routing Strategy
225
- const routingStrategy = detectRouting(srcFiles);
71
+ **Purpose:** Analyze directory organization and architecture patterns without reading code line-by-line.
226
72
 
227
- function detectRouting(files: string[]): string {
228
- const hasAppDir = files.some((f) => f.startsWith('app/'));
229
- const hasPagesDir = files.some((f) => f.startsWith('pages/'));
230
- const hasSrcRoutes = files.some((f) => f.includes('/routes/'));
73
+ ### 0.2.1 Pattern Detection
74
+ 1. **Identify Pattern:** Feature-based, Layer-based, Modular Monolith, or Hybrid.
75
+ 2. **Entity Detection:** Scan for Schema/Entity files based on the detected ORM (Prisma, TypeORM, Django Models, etc.).
76
+ 3. **Maturity Check:** Assess documentation and test coverage ratio.
231
77
 
232
- if (hasAppDir) return 'App Router (Next.js 13+)';
233
- if (hasPagesDir) return 'Pages Router';
234
- if (hasSrcRoutes) return 'File-based routing';
78
+ ### Layer 2 Output
79
+ Summary of Architecture Pattern, Code Structure counts (Controllers, Services, etc.), and Recommended Build Scope (MVP/Production/Enterprise).
235
80
 
236
- // Check for react-router/vue-router in code
237
- const hasReactRouter = files.some((f) => {
238
- const content = fs.readFileSync(f, 'utf-8');
239
- return content.includes('react-router-dom');
240
- });
81
+ ---
241
82
 
242
- if (hasReactRouter) return 'React Router (code-based)';
243
- return 'Unknown';
244
- }
83
+ ## 0.3 Layer 3: Selective Deep Analysis (1-5 minutes, OPTIONAL)
245
84
 
246
- // 3. API Integration Pattern
247
- const apiPattern = detectAPIPattern(srcFiles);
85
+ **Purpose:** Read and parse representative code files for detailed insights into API endpoints, data relationships, and security patterns.
248
86
 
249
- function detectAPIPattern(files: string[]): string {
250
- const hasApiDir = files.some((f) => f.includes('/api/'));
251
- const hasServicesDir = files.some((f) => f.includes('/services/'));
252
- const hasHooksDir = files.some((f) => f.includes('/hooks/use') && f.includes('query'));
87
+ ### 0.3.1 Areas of Analysis
88
+ - **API Endpoints:** Parse routes/controllers.
89
+ - **Data Model:** Map entity relationships.
90
+ - **Security:** Detect auth patterns (JWT, OAuth), validation (Zod, Pydantic), and middleware.
253
91
 
254
- if (hasHooksDir) return 'Custom hooks with TanStack Query';
255
- if (hasServicesDir) return 'Service layer pattern';
256
- if (hasApiDir) return 'API client pattern';
257
- return 'Unknown';
258
- }
92
+ ### 0.3.2 Sampling Strategy
93
+ Use stratified sampling to read only the most relevant files (e.g., core controllers and entities) to stay within context limits.
259
94
 
260
- // 4. Component Examples (Extract 2-3 representative components)
261
- const componentExamples = extractComponentExamples(srcFiles);
262
-
263
- function extractComponentExamples(files: string[]): Component[] {
264
- // Find 2-3 well-structured components
265
- const candidates = files.filter((f) => {
266
- const content = fs.readFileSync(f, 'utf-8');
267
- return content.includes('export') && content.length > 50 && content.length < 500;
268
- });
269
-
270
- return candidates.slice(0, 3).map((file) => ({
271
- name: path.basename(file, path.extname(file)),
272
- path: file,
273
- snippet: fs.readFileSync(file, 'utf-8').slice(0, 200),
274
- }));
275
- }
276
- ```
95
+ ---
277
96
 
278
- #### Layer 2 Output
97
+ ## Validation & Synthesis
279
98
 
280
- ```
281
- ARCHITECTURE DETECTED:
99
+ ### Present Findings
100
+ Show the final "🔍 BACKEND STACK DETECTED" report and ask for confirmation.
101
+
102
+ ### 💾 Cache & Pre-populate
103
+ 1. **Export:** Save results to `.ai-flow/cache/docs-analysis.json`.
104
+ 2. **Pre-populate:** Fill answers for Phases 1-7 based on detected data.
282
105
 
283
- Component Pattern: Atomic Design
284
- - atoms/: 12 components
285
- - molecules/: 23 components
286
- - organisms/: 8 components
106
+ ---
287
107
 
288
- Routing: App Router (Next.js 13+)
289
- - app/: 15 routes
290
- - Dynamic routes: 5
108
+ ## 0.4 Layer 4: Documentation Audit (30-90s, CONDITIONAL)
291
109
 
292
- API Integration: Custom hooks with TanStack Query
293
- - hooks/useQuery*.ts: 8 hooks
294
- - services/api.ts: REST client
110
+ **Trigger:** Only if `docs/` or `specs/` directories exist with content.
295
111
 
296
- Example Components:
297
- 1. atoms/Button.tsx (56 lines) - Reusable button with variants
298
- 2. molecules/UserCard.tsx (89 lines) - User card with avatar
299
- 3. organisms/ProductGrid.tsx (124 lines) - Product grid with pagination
112
+ **Purpose:** Validate existing documentation against implemented code to detect inconsistencies.
113
+
114
+ ### 0.4.1 Ask User Permission
300
115
 
301
- Continue to Layer 3 for deep analysis? (Y/n)
302
116
  ```
303
- ---
304
- ### Layer 3: Selective Deep Analysis (Optional, 60-120 seconds)
117
+ 📚 Existing documentation detected (12 files in docs/, 3 in specs/)
305
118
 
306
- **Purpose:** Extract advanced patterns, conventions, and documentation
119
+ Would you like to audit documentation vs code?
120
+ A) Yes, audit and show inconsistencies (recommended) ⭐
121
+ B) No, skip audit (continue to Phase 1)
307
122
 
308
- **Only proceed if:**
123
+ > _
124
+ ```
309
125
 
310
- - User confirms (not automatic)
311
- - Project is large (>50 components)
312
- - Accuracy is critical
126
+ **If user selects B:** Skip to section 0.5 (Validation & Synthesis).
313
127
 
314
- #### Advanced Detection
128
+ ### 0.4.2 Parse Existing Documentation
315
129
 
316
- ```typescript
317
- // 1. Naming Conventions
318
- const namingConvention = analyzeNamingPatterns(srcFiles);
130
+ **Action:** Extract documented information from:
131
+ - `docs/architecture.md` Architecture patterns
132
+ - `docs/data-model.md` Entities and fields
133
+ - `docs/api.md` → Endpoints and methods
134
+ - `specs/requirements.md` → Business requirements
319
135
 
320
- function analyzeNamingPatterns(files: string[]): NamingConvention {
321
- const componentNames = files.map((f) => path.basename(f, path.extname(f)));
136
+ **Save to:** `.ai-flow/cache/docs-snapshot.json`
322
137
 
323
- const pascalCase = componentNames.filter((n) => /^[A-Z][a-zA-Z0-9]*$/.test(n)).length;
324
- const camelCase = componentNames.filter((n) => /^[a-z][a-zA-Z0-9]*$/.test(n)).length;
325
- const kebabCase = componentNames.filter((n) => /^[a-z][a-z0-9-]*$/.test(n)).length;
138
+ ### 0.4.3 Compare Code vs Documentation
326
139
 
327
- const dominant = Math.max(pascalCase, camelCase, kebabCase);
140
+ **Compare:**
141
+ 1. **Entities:** Schema files (Prisma, TypeORM, etc.) vs `docs/data-model.md`
142
+ 2. **Endpoints:** Controllers/Routes vs `docs/api.md`
143
+ 3. **Architecture:** Code structure vs `docs/architecture.md`
144
+ 4. **Tech Stack:** `package.json` vs documented stack
328
145
 
329
- return {
330
- files: dominant === kebabCase ? 'kebab-case' : 'PascalCase',
331
- components: dominant === pascalCase ? 'PascalCase' : 'camelCase',
332
- hooks: files.some((f) => f.includes('use')) ? 'use* (hooks)' : 'N/A',
333
- };
334
- }
146
+ **Detect:**
147
+ - Items in code but not in docs (undocumented features)
148
+ - Items in docs but not in code (missing implementations or obsolete docs)
149
+ - Mismatches in fields, types, or patterns
335
150
 
336
- // 2. Code Quality Patterns
337
- const qualityPatterns = analyzeQualityPatterns(srcFiles);
338
-
339
- function analyzeQualityPatterns(files: string[]): QualityPatterns {
340
- let hasTypeScript = 0;
341
- let hasPropTypes = 0;
342
- let hasTests = 0;
343
- let hasStories = 0;
344
-
345
- files.forEach((file) => {
346
- if (file.endsWith('.ts') || file.endsWith('.tsx')) hasTypeScript++;
347
- const content = fs.readFileSync(file, 'utf-8');
348
- if (content.includes('PropTypes')) hasPropTypes++;
349
- });
350
-
351
- const testFiles = files.filter((f) => f.includes('.test.') || f.includes('.spec.'));
352
- hasTests = testFiles.length;
353
-
354
- const storyFiles = files.filter((f) => f.includes('.stories.'));
355
- hasStories = storyFiles.length;
356
-
357
- return {
358
- typeScriptCoverage: (hasTypeScript / files.length) * 100,
359
- propTypesUsage: hasPropTypes > 0,
360
- testCoverage: `${hasTests} test files`,
361
- storybookUsage: hasStories > 0,
362
- };
363
- }
151
+ ### 0.4.4 Classify Inconsistencies
364
152
 
365
- // 3. Accessibility Patterns
366
- const a11yPatterns = analyzeAccessibility(srcFiles);
153
+ **Severity Levels:**
367
154
 
368
- function analyzeAccessibility(files: string[]): A11yPatterns {
369
- let ariaUsage = 0;
370
- let semanticHTML = 0;
155
+ 🔴 **CRITICAL** (Requires user decision):
156
+ - Documented entity/endpoint not implemented
157
+ - Major architectural mismatch
371
158
 
372
- files.forEach((file) => {
373
- const content = fs.readFileSync(file, 'utf-8');
374
- if (content.includes('aria-')) ariaUsage++;
375
- if (content.includes('<button') || content.includes('<nav') || content.includes('<header')) {
376
- semanticHTML++;
377
- }
378
- });
159
+ 🟡 **MEDIUM** (Auto-correctable with confirmation):
160
+ - Implemented endpoint not documented
161
+ - Missing fields in docs
379
162
 
380
- return {
381
- ariaAttributesUsage: ariaUsage > files.length * 0.2 ? 'Frequent' : 'Rare',
382
- semanticHTMLUsage: semanticHTML > files.length * 0.5 ? 'Good' : 'Needs improvement',
383
- };
384
- }
385
- ```
163
+ 🟢 **LOW** (Auto-correctable):
164
+ - Obsolete fields in docs
165
+ - Outdated version numbers
166
+
167
+ ### 0.4.5 Generate Audit Summary
386
168
 
387
- #### Layer 3 Output
169
+ **Output:** Concise summary (full report saved for later).
388
170
 
389
171
  ```
390
- ✅ DEEP ANALYSIS COMPLETE:
172
+ ---
173
+ 📊 Documentation Audit Summary
174
+
175
+ Consistency Score: 72%
391
176
 
392
- Naming Conventions:
393
- - Files: PascalCase
394
- - Components: PascalCase
395
- - Hooks: use* prefix
177
+ 🔴 Critical: 2 issues
178
+ - Entity 'Category' documented but not in schema
179
+ - Endpoint POST /api/auth/register documented but missing
396
180
 
397
- Code Quality:
398
- - TypeScript: 95% coverage
399
- - PropTypes: Not used (TypeScript instead)
400
- - Tests: 48 test files (60% coverage)
401
- - Storybook: Yes (23 stories)
181
+ 🟡 Medium: 5 issues
182
+ - 3 endpoints implemented but not documented
183
+ - 2 entity fields missing in docs
402
184
 
403
- Accessibility:
404
- - ARIA attributes: Frequent usage
405
- - Semantic HTML: Good usage
406
- - Recommended: WCAG 2.1 AA compliance
185
+ 🟢 Minor: 3 issues
186
+ - 3 obsolete fields in documentation
407
187
 
408
- Analysis complete! Proceeding to validation...
188
+ 💡 Recommendation:
189
+ - Review critical issues before continuing
190
+ - Full audit report will be generated in Phase 8
191
+ - Auto-corrections can be applied after Phase 8
192
+ ---
409
193
  ```
410
- ---
411
- ## ✅ Validation & Confirmation
412
194
 
413
- ### Present Findings
195
+ ### 0.4.6 Handle Critical Issues (If Any)
414
196
 
415
- After detection, show user a summary and ask for confirmation:
197
+ **If critical issues found:**
416
198
 
417
199
  ```
418
- ---
419
- 🔍 FRONTEND STACK DETECTED
420
- ---
421
- ✅ Framework: React 18.2.0 (with Next.js 14.0.0)
422
- ✅ Build Tool: Vite 5.0.0
423
- ✅ TypeScript: Yes
424
- ✅ State Management: Zustand 4.4.0
425
- ✅ Data Fetching: TanStack Query 5.0.0
426
- ✅ Styling: Tailwind CSS 3.3.0
427
- ✅ Component Pattern: Atomic Design
428
- ✅ Testing: Vitest + Playwright
429
- ✅ Routing: App Router (Next.js 13+)
430
- ✅ Component Library: None
431
-
432
- Is this correct? (Y/n)
433
- ```
200
+ ⚠️ Critical inconsistencies detected!
434
201
 
435
- ### If User Says "Yes"
202
+ How would you like to proceed?
203
+ A) Continue to Phase 1 (address issues later in Phase 8) ⭐
204
+ B) Review critical issues now (interactive)
205
+ C) Cancel /flow-build (fix manually first)
436
206
 
207
+ > _
437
208
  ```
438
- ✅ Great! I'll use these detected values.
439
-
440
- I'll still ask you questions for:
441
- - Business requirements (Phase 1)
442
- - Specific conventions and preferences
443
- - Performance targets
444
- - Deployment strategy
445
209
 
446
- This will reduce the questionnaire from ~90 min to ~40 min.
210
+ **Option A (Recommended):** Continue to Phase 1
211
+ - Save audit data for Phase 8
212
+ - Phase 8 will offer to apply corrections
447
213
 
448
- Proceed to Phase 1? (Y/n)
214
+ **Option B:** Interactive review now
449
215
  ```
216
+ 🔴 Critical Issue 1/2: Entity 'Category'
217
+ Documented in docs/data-model.md but NOT in schema
450
218
 
451
- ### If User Says "No" or Makes Corrections
219
+ What should we do?
220
+ A) Mark as "To Implement" (add to roadmap)
221
+ B) Mark as "Obsolete" (remove from docs in Phase 8)
222
+ C) Skip for now
452
223
 
224
+ > _
453
225
  ```
454
- Please correct any incorrect detections:
455
226
 
456
- 1. Framework: React 18.2.0 → (Enter new value or press Enter to keep)
457
- 2. State Management: Zustand → (Enter new value or press Enter to keep)
458
- ...
227
+ **Option C:** Cancel
228
+ - User fixes issues manually
229
+ - Re-run `/flow-build` later
459
230
 
460
- (After corrections)
231
+ ### 0.4.7 Save Audit Data
461
232
 
462
- Updated! Proceeding to Phase 1...
463
- ```
464
- ---
465
- ## 💾 Cache Storage
233
+ > **📌 IMPORTANT - Phases 9-10 for Existing Projects:**
234
+ >
235
+ > If the project has **substantial functional code already implemented** (detected in Layer 1-3):
236
+ > - Set `phase9.recommendation = "SKIP"` with reason: "Project already implemented - roadmap not needed"
237
+ > - Set `phase10.recommendation = "SKIP"` with reason: "Project already implemented - user stories not needed"
238
+ >
239
+ > **Phases 9-10 are only useful for:**
240
+ > - New projects (no code yet)
241
+ > - Projects in early development (< 30% features implemented)
242
+ >
243
+ > **For existing projects**, focus on Phases 1-8 (documentation sync) instead.
466
244
 
467
- Save detected context for future use:
245
+ **Save to:** `.ai-flow/cache/audit-data.json`
468
246
 
469
- ```typescript
470
- // .ai-flow/cache/frontend-context.json
247
+ ```json
471
248
  {
472
- "framework": "React",
473
- "frameworkVersion": "18.2.0",
474
- "metaFramework": "Next.js",
475
- "metaFrameworkVersion": "14.0.0",
476
- "buildTool": "Vite",
477
- "buildToolVersion": "5.0.0",
478
- "typescript": true,
479
- "stateManagement": "Zustand",
480
- "dataFetching": "TanStack Query",
481
- "styling": "Tailwind CSS",
482
- "componentLibrary": null,
483
- "componentPattern": "Atomic Design",
484
- "routing": "App Router",
485
- "unitTest": "Vitest",
486
- "e2eTest": "Playwright",
487
- "namingConvention": "PascalCase",
488
- "testCoverage": 60,
489
- "a11yCompliance": "WCAG 2.1 AA",
490
- "lastAnalyzed": "2025-01-20T10:30:00Z",
491
- "projectPath": "/Users/username/my-app"
249
+ "auditPerformed": true,
250
+ "timestamp": "2025-12-22T16:43:00Z",
251
+ "consistencyScore": 72,
252
+ "critical": 2,
253
+ "medium": 5,
254
+ "minor": 3,
255
+ "userDecisions": {
256
+ "Category": "obsolete",
257
+ "POST /api/auth/register": "to_implement"
258
+ },
259
+ "phases": {
260
+ "phase1": {
261
+ "file": "project-brief.md",
262
+ "exists": true,
263
+ "consistencyScore": 100,
264
+ "recommendation": "SKIP",
265
+ "gaps": [],
266
+ "reason": "Complete business context documented"
267
+ },
268
+ "phase2": {
269
+ "file": "docs/data-model.md",
270
+ "exists": true,
271
+ "consistencyScore": 98,
272
+ "recommendation": "SKIP",
273
+ "gaps": [],
274
+ "reason": "All entities documented and match schema"
275
+ },
276
+ "phase3": {
277
+ "file": "docs/architecture.md",
278
+ "exists": true,
279
+ "consistencyScore": 87,
280
+ "recommendation": "HYBRID",
281
+ "gaps": ["api_versioning", "rate_limiting"],
282
+ "reason": "Architecture documented but missing 2 details"
283
+ },
284
+ "phase4": {
285
+ "file": "specs/security.md",
286
+ "exists": true,
287
+ "consistencyScore": 95,
288
+ "recommendation": "SKIP",
289
+ "gaps": [],
290
+ "reason": "Security patterns match implementation"
291
+ },
292
+ "phase5": {
293
+ "file": "docs/code-standards.md",
294
+ "exists": true,
295
+ "consistencyScore": 92,
296
+ "recommendation": "SKIP",
297
+ "gaps": [],
298
+ "reason": "Standards documented and enforced"
299
+ },
300
+ "phase6": {
301
+ "file": "docs/testing.md",
302
+ "exists": true,
303
+ "consistencyScore": 90,
304
+ "recommendation": "SKIP",
305
+ "gaps": [],
306
+ "reason": "Testing strategy documented"
307
+ },
308
+ "phase7": {
309
+ "file": "docs/deployment.md",
310
+ "exists": true,
311
+ "consistencyScore": 82,
312
+ "recommendation": "HYBRID",
313
+ "gaps": ["monitoring_strategy", "incident_runbooks"],
314
+ "reason": "Deployment documented but missing operational details"
315
+ },
316
+ "phase8": {
317
+ "file": "AGENT.md",
318
+ "exists": true,
319
+ "consistencyScore": 95,
320
+ "recommendation": "SKIP",
321
+ "gaps": [],
322
+ "reason": "Final documentation complete and up-to-date"
323
+ },
324
+ "phase9": {
325
+ "file": "docs/roadmap.md",
326
+ "exists": false,
327
+ "consistencyScore": 0,
328
+ "recommendation": "SKIP",
329
+ "gaps": [],
330
+ "reason": "Project already implemented - roadmap not needed for existing code"
331
+ },
332
+ "phase10": {
333
+ "file": "docs/user-stories/",
334
+ "exists": false,
335
+ "consistencyScore": 0,
336
+ "recommendation": "SKIP",
337
+ "gaps": [],
338
+ "reason": "Project already implemented - user stories not needed for existing features"
339
+ }
340
+ }
492
341
  }
493
342
  ```
494
343
 
495
- **Cache invalidation:** 7 days or when package.json is modified
496
- ---
497
- ## 🚀 Next Steps
344
+ **Recommendation Logic:**
345
+ - **SKIP** (≥95%): Phase can be skipped, use existing docs
346
+ - **HYBRID** (80-94%): Ask only missing questions, merge with existing docs
347
+ - **FULL** (<80% or file missing): Execute full phase with pre-filled answers
498
348
 
499
- After Phase 0 completes:
349
+ This data will be used in Phases 1-7 to:
350
+ 1. Determine if phase can be skipped
351
+ 2. Identify specific gaps to ask about
352
+ 3. Merge new answers with existing documentation
500
353
 
501
- ```
502
- Context analysis complete!
354
+ This data will be used in Phase 8 to:
355
+ 1. Generate detailed audit report
356
+ 2. Apply auto-corrections
357
+ 3. Update roadmap with "To Implement" items
503
358
 
504
- Next: Proceed to Phase 1 (Discovery & UX)
359
+ ---
505
360
 
506
- Read: .ai-flow/prompts/frontend/flow-build-phase-1-discovery.md
507
- ```
508
- ---
509
- **Last Updated:** 2025-01-XX
361
+ ## 0.5 Validation & Synthesis
362
+
363
+ ### Present Findings
364
+
365
+ Show the final report including:
366
+ 1. **🔍 BACKEND STACK DETECTED** (from Layers 1-3)
367
+ 2. **📊 Documentation Audit Summary** (from Layer 4, if executed)
368
+
369
+ Ask for confirmation to proceed to Phase 1.
370
+
371
+ ### 💾 Cache & Pre-populate
372
+
373
+ 1. **Export code analysis:** `.ai-flow/cache/docs-analysis.json`
374
+ 2. **Export audit data:** `.ai-flow/cache/audit-data.json` (if Layer 4 executed)
375
+ 3. **Pre-populate:** Fill answers for Phases 1-7 based on detected data
376
+
377
+ ### 🎯 Set Flags for Phase 8
378
+
379
+ If documentation audit was performed:
380
+ - Set flag: `auditPerformed: true`
381
+ - Phase 8 will:
382
+ - Generate detailed audit report (`docs/audit-report.md`)
383
+ - Offer to apply auto-corrections (🟡 Medium + 🟢 Low)
384
+ - Update roadmap with "To Implement" items (🔴 Critical marked as such)
385
+
386
+ ---
387
+
388
+ ✅ **Phase 0 Complete: Context Analysis Finalized**
389
+
390
+ ---
391
+
392
+ ### Phase Summary
393
+ - Pre-populated detected tech stack values.
394
+ - Architectural patterns identified.
395
+ - Context cached in `.ai-flow/cache/docs-analysis.json`.
396
+ - **Documentation audit completed** (if existing docs found).
397
+ - **Inconsistencies flagged** for Phase 8 resolution.
510
398
 
511
- **Version:** 1.2.0
399
+ ---
512
400
 
401
+ **Next Phase:** Phase 1 - Discovery & Business Requirements
513
402
 
403
+ **What happens next:**
404
+ - Phase 1-7 will use pre-populated answers (40-60% filled)
405
+ - You'll only answer questions that couldn't be auto-detected
406
+ - Phase 8 will offer to resolve documentation inconsistencies
514
407
 
408
+ Read: `.ai-flow/prompts/backend/flow-build-phase-1.md`
515
409
 
410
+ ---
411
+ _Version: 4.3 (Antigravity Optimized - With Integrated Audit)_
412
+ _Last Updated: 2025-12-22_