Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. # Full Project Scan Instructions
  2. <workflow>
  3. <critical>This workflow performs complete project documentation (Steps 1-12)</critical>
  4. <critical>Handles: initial_scan and full_rescan modes</critical>
  5. <critical>YOU MUST ALWAYS SPEAK OUTPUT In your Agent communication style with the configured `{communication_language}`</critical>
  6. <critical>YOU MUST ALWAYS WRITE all artifact and document content in `{document_output_language}`</critical>
  7. <step n="0.5" goal="Load documentation requirements data for fresh starts (not needed for resume)" if="resume_mode == false">
  8. <critical>DATA LOADING STRATEGY - Understanding the Documentation Requirements System:</critical>
  9. <action>Display explanation to user:
  10. **How Project Type Detection Works:**
  11. This workflow uses a single comprehensive CSV file to intelligently document your project:
  12. **documentation-requirements.csv** (../documentation-requirements.csv)
  13. - Contains 12 project types (web, mobile, backend, cli, library, desktop, game, data, extension, infra, embedded)
  14. - 24-column schema combining project type detection AND documentation requirements
  15. - **Detection columns**: project_type_id, key_file_patterns (used to identify project type from codebase)
  16. - **Requirement columns**: requires_api_scan, requires_data_models, requires_ui_components, etc.
  17. - **Pattern columns**: critical_directories, test_file_patterns, config_patterns, etc.
  18. - Acts as a "scan guide" - tells the workflow WHERE to look and WHAT to document
  19. - Example: For project_type_id="web", key_file_patterns includes "package.json;tsconfig.json;\*.config.js" and requires_api_scan=true
  20. **When Documentation Requirements are Loaded:**
  21. - **Fresh Start (initial_scan)**: Load all 12 rows → detect type using key_file_patterns → use that row's requirements
  22. - **Resume**: Load ONLY the doc requirements row(s) for cached project_type_id(s)
  23. - **Full Rescan**: Same as fresh start (may re-detect project type)
  24. - **Deep Dive**: Load ONLY doc requirements for the part being deep-dived
  25. </action>
  26. <action>Now loading documentation requirements data for fresh start...</action>
  27. <action>Load documentation-requirements.csv from: ../documentation-requirements.csv</action>
  28. <action>Store all 12 rows indexed by project_type_id for project detection and requirements lookup</action>
  29. <action>Display: "Loaded documentation requirements for 12 project types (web, mobile, backend, cli, library, desktop, game, data, extension, infra, embedded)"</action>
  30. <action>Display: "✓ Documentation requirements loaded successfully. Ready to begin project analysis."</action>
  31. </step>
  32. <step n="0.6" goal="Check for existing documentation and determine workflow mode">
  33. <action>Check if {project_knowledge}/index.md exists</action>
  34. <check if="index.md exists">
  35. <action>Read existing index.md to extract metadata (date, project structure, parts count)</action>
  36. <action>Store as {{existing_doc_date}}, {{existing_structure}}</action>
  37. <ask>I found existing documentation generated on {{existing_doc_date}}.
  38. What would you like to do?
  39. 1. **Re-scan entire project** - Update all documentation with latest changes
  40. 2. **Deep-dive into specific area** - Generate detailed documentation for a particular feature/module/folder
  41. 3. **Cancel** - Keep existing documentation as-is
  42. Your choice [1/2/3]:
  43. </ask>
  44. <check if="user selects 1">
  45. <action>Set workflow_mode = "full_rescan"</action>
  46. <action>Continue to scan level selection below</action>
  47. </check>
  48. <check if="user selects 2">
  49. <action>Set workflow_mode = "deep_dive"</action>
  50. <action>Set scan_level = "exhaustive"</action>
  51. <action>Initialize state file with mode=deep_dive, scan_level=exhaustive</action>
  52. <action>Jump to Step 13</action>
  53. </check>
  54. <check if="user selects 3">
  55. <action>Display message: "Keeping existing documentation. Exiting workflow."</action>
  56. <action>Exit workflow</action>
  57. </check>
  58. </check>
  59. <check if="index.md does not exist">
  60. <action>Set workflow_mode = "initial_scan"</action>
  61. <action>Continue to scan level selection below</action>
  62. </check>
  63. <action if="workflow_mode != deep_dive">Select Scan Level</action>
  64. <check if="workflow_mode == initial_scan OR workflow_mode == full_rescan">
  65. <ask>Choose your scan depth level:
  66. **1. Quick Scan** (2-5 minutes) [DEFAULT]
  67. - Pattern-based analysis without reading source files
  68. - Scans: Config files, package manifests, directory structure
  69. - Best for: Quick project overview, initial understanding
  70. - File reading: Minimal (configs, README, package.json, etc.)
  71. **2. Deep Scan** (10-30 minutes)
  72. - Reads files in critical directories based on project type
  73. - Scans: All critical paths from documentation requirements
  74. - Best for: Comprehensive documentation for brownfield PRD
  75. - File reading: Selective (key files in critical directories)
  76. **3. Exhaustive Scan** (30-120 minutes)
  77. - Reads ALL source files in project
  78. - Scans: Every source file (excludes node_modules, dist, build)
  79. - Best for: Complete analysis, migration planning, detailed audit
  80. - File reading: Complete (all source files)
  81. Your choice [1/2/3] (default: 1):
  82. </ask>
  83. <action if="user selects 1 OR user presses enter">
  84. <action>Set scan_level = "quick"</action>
  85. <action>Display: "Using Quick Scan (pattern-based, no source file reading)"</action>
  86. </action>
  87. <action if="user selects 2">
  88. <action>Set scan_level = "deep"</action>
  89. <action>Display: "Using Deep Scan (reading critical files per project type)"</action>
  90. </action>
  91. <action if="user selects 3">
  92. <action>Set scan_level = "exhaustive"</action>
  93. <action>Display: "Using Exhaustive Scan (reading all source files)"</action>
  94. </action>
  95. <action>Initialize state file: {project_knowledge}/project-scan-report.json</action>
  96. <critical>Every time you touch the state file, record: step id, human-readable summary (what you actually did), precise timestamp, and any outputs written. Vague phrases are unacceptable.</critical>
  97. <action>Write initial state:
  98. {
  99. "workflow_version": "1.2.0",
  100. "timestamps": {"started": "{{current_timestamp}}", "last_updated": "{{current_timestamp}}"},
  101. "mode": "{{workflow_mode}}",
  102. "scan_level": "{{scan_level}}",
  103. "project_root": "{{project_root_path}}",
  104. "project_knowledge": "{{project_knowledge}}",
  105. "completed_steps": [],
  106. "current_step": "step_1",
  107. "findings": {},
  108. "outputs_generated": ["project-scan-report.json"],
  109. "resume_instructions": "Starting from step 1"
  110. }
  111. </action>
  112. <action>Continue with standard workflow from Step 1</action>
  113. </check>
  114. </step>
  115. <step n="1" goal="Detect project structure and classify project type" if="workflow_mode != deep_dive">
  116. <action>Ask user: "What is the root directory of the project to document?" (default: current working directory)</action>
  117. <action>Store as {{project_root_path}}</action>
  118. <action>Scan {{project_root_path}} for key indicators:
  119. - Directory structure (presence of client/, server/, api/, src/, app/, etc.)
  120. - Key files (package.json, go.mod, requirements.txt, etc.)
  121. - Technology markers matching detection_keywords from project-types.csv
  122. </action>
  123. <action>Detect if project is:
  124. - **Monolith**: Single cohesive codebase
  125. - **Monorepo**: Multiple parts in one repository
  126. - **Multi-part**: Separate client/server or similar architecture
  127. </action>
  128. <check if="multiple distinct parts detected (e.g., client/ and server/ folders)">
  129. <action>List detected parts with their paths</action>
  130. <ask>I detected multiple parts in this project:
  131. {{detected_parts_list}}
  132. Is this correct? Should I document each part separately? [y/n]
  133. </ask>
  134. <action if="user confirms">Set repository_type = "monorepo" or "multi-part"</action>
  135. <action if="user confirms">For each detected part: - Identify root path - Run project type detection using key_file_patterns from documentation-requirements.csv - Store as part in project_parts array
  136. </action>
  137. <action if="user denies or corrects">Ask user to specify correct parts and their paths</action>
  138. </check>
  139. <check if="single cohesive project detected">
  140. <action>Set repository_type = "monolith"</action>
  141. <action>Create single part in project_parts array with root_path = {{project_root_path}}</action>
  142. <action>Run project type detection using key_file_patterns from documentation-requirements.csv</action>
  143. </check>
  144. <action>For each part, match detected technologies and file patterns against key_file_patterns column in documentation-requirements.csv</action>
  145. <action>Assign project_type_id to each part</action>
  146. <action>Load corresponding documentation_requirements row for each part</action>
  147. <ask>I've classified this project:
  148. {{project_classification_summary}}
  149. Does this look correct? [y/n/edit]
  150. </ask>
  151. <template-output>project_structure</template-output>
  152. <template-output>project_parts_metadata</template-output>
  153. <action>IMMEDIATELY update state file with step completion:
  154. - Add to completed_steps: {"step": "step_1", "status": "completed", "timestamp": "{{now}}", "summary": "Classified as {{repository_type}} with {{parts_count}} parts"}
  155. - Update current_step = "step_2"
  156. - Update findings.project_classification with high-level summary only
  157. - **CACHE project_type_id(s)**: Add project_types array: [{"part_id": "{{part_id}}", "project_type_id": "{{project_type_id}}", "display_name": "{{display_name}}"}]
  158. - This cached data prevents reloading all CSV files on resume - we can load just the needed documentation_requirements row(s)
  159. - Update last_updated timestamp
  160. - Write state file
  161. </action>
  162. <action>PURGE detailed scan results from memory, keep only summary: "{{repository_type}}, {{parts_count}} parts, {{primary_tech}}"</action>
  163. </step>
  164. <step n="2" goal="Discover existing documentation and gather user context" if="workflow_mode != deep_dive">
  165. <action>For each part, scan for existing documentation using patterns:
  166. - README.md, README.rst, README.txt
  167. - CONTRIBUTING.md, CONTRIBUTING.rst
  168. - ARCHITECTURE.md, ARCHITECTURE.txt, docs/architecture/
  169. - DEPLOYMENT.md, DEPLOY.md, docs/deployment/
  170. - API.md, docs/api/
  171. - Any files in docs/, documentation/, .github/ folders
  172. </action>
  173. <action>Create inventory of existing_docs with:
  174. - File path
  175. - File type (readme, architecture, api, etc.)
  176. - Which part it belongs to (if multi-part)
  177. </action>
  178. <ask>I found these existing documentation files:
  179. {{existing_docs_list}}
  180. Are there any other important documents or key areas I should focus on while analyzing this project? [Provide paths or guidance, or type 'none']
  181. </ask>
  182. <action>Store user guidance as {{user_context}}</action>
  183. <template-output>existing_documentation_inventory</template-output>
  184. <template-output>user_provided_context</template-output>
  185. <action>Update state file:
  186. - Add to completed_steps: {"step": "step_2", "status": "completed", "timestamp": "{{now}}", "summary": "Found {{existing_docs_count}} existing docs"}
  187. - Update current_step = "step_3"
  188. - Update last_updated timestamp
  189. </action>
  190. <action>PURGE detailed doc contents from memory, keep only: "{{existing_docs_count}} docs found"</action>
  191. </step>
  192. <step n="3" goal="Analyze technology stack for each part" if="workflow_mode != deep_dive">
  193. <action>For each part in project_parts:
  194. - Load key_file_patterns from documentation_requirements
  195. - Scan part root for these patterns
  196. - Parse technology manifest files (package.json, go.mod, requirements.txt, etc.)
  197. - Extract: framework, language, version, database, dependencies
  198. - Build technology_table with columns: Category, Technology, Version, Justification
  199. </action>
  200. <action>Determine architecture pattern based on detected tech stack:
  201. - Use project_type_id as primary indicator (e.g., "web" → layered/component-based, "backend" → service/API-centric)
  202. - Consider framework patterns (e.g., React → component hierarchy, Express → middleware pipeline)
  203. - Note architectural style in technology table
  204. - Store as {{architecture_pattern}} for each part
  205. </action>
  206. <template-output>technology_stack</template-output>
  207. <template-output>architecture_patterns</template-output>
  208. <action>Update state file:
  209. - Add to completed_steps: {"step": "step_3", "status": "completed", "timestamp": "{{now}}", "summary": "Tech stack: {{primary_framework}}"}
  210. - Update current_step = "step_4"
  211. - Update findings.technology_stack with summary per part
  212. - Update last_updated timestamp
  213. </action>
  214. <action>PURGE detailed tech analysis from memory, keep only: "{{framework}} on {{language}}"</action>
  215. </step>
  216. <step n="4" goal="Perform conditional analysis based on project type requirements" if="workflow_mode != deep_dive">
  217. <critical>BATCHING STRATEGY FOR DEEP/EXHAUSTIVE SCANS</critical>
  218. <check if="scan_level == deep OR scan_level == exhaustive">
  219. <action>This step requires file reading. Apply batching strategy:</action>
  220. <action>Identify subfolders to process based on: - scan_level == "deep": Use critical_directories from documentation_requirements - scan_level == "exhaustive": Get ALL subfolders recursively (excluding node_modules, .git, dist, build, coverage)
  221. </action>
  222. <action>For each subfolder to scan: 1. Read all files in subfolder (consider file size - use judgment for files >5000 LOC) 2. Extract required information based on conditional flags below 3. IMMEDIATELY write findings to appropriate output file 4. Validate written document (section-level validation) 5. Update state file with batch completion 6. PURGE detailed findings from context, keep only 1-2 sentence summary 7. Move to next subfolder
  223. </action>
  224. <action>Track batches in state file:
  225. findings.batches_completed: [
  226. {"path": "{{subfolder_path}}", "files_scanned": {{count}}, "summary": "{{brief_summary}}"}
  227. ]
  228. </action>
  229. </check>
  230. <check if="scan_level == quick">
  231. <action>Use pattern matching only - do NOT read source files</action>
  232. <action>Use glob/grep to identify file locations and patterns</action>
  233. <action>Extract information from filenames, directory structure, and config files only</action>
  234. </check>
  235. <action>For each part, check documentation_requirements boolean flags and execute corresponding scans:</action>
  236. <check if="requires_api_scan == true">
  237. <action>Scan for API routes and endpoints using integration_scan_patterns</action>
  238. <action>Look for: controllers/, routes/, api/, handlers/, endpoints/</action>
  239. <check if="scan_level == quick">
  240. <action>Use glob to find route files, extract patterns from filenames and folder structure</action>
  241. </check>
  242. <check if="scan_level == deep OR scan_level == exhaustive">
  243. <action>Read files in batches (one subfolder at a time)</action>
  244. <action>Extract: HTTP methods, paths, request/response types from actual code</action>
  245. </check>
  246. <action>Build API contracts catalog</action>
  247. <action>IMMEDIATELY write to: {project_knowledge}/api-contracts-{part_id}.md</action>
  248. <action>Validate document has all required sections</action>
  249. <action>Update state file with output generated</action>
  250. <action>PURGE detailed API data, keep only: "{{api_count}} endpoints documented"</action>
  251. <template-output>api_contracts\*{part_id}</template-output>
  252. </check>
  253. <check if="requires_data_models == true">
  254. <action>Scan for data models using schema_migration_patterns</action>
  255. <action>Look for: models/, schemas/, entities/, migrations/, prisma/, ORM configs</action>
  256. <check if="scan_level == quick">
  257. <action>Identify schema files via glob, parse migration file names for table discovery</action>
  258. </check>
  259. <check if="scan_level == deep OR scan_level == exhaustive">
  260. <action>Read model files in batches (one subfolder at a time)</action>
  261. <action>Extract: table names, fields, relationships, constraints from actual code</action>
  262. </check>
  263. <action>Build database schema documentation</action>
  264. <action>IMMEDIATELY write to: {project_knowledge}/data-models-{part_id}.md</action>
  265. <action>Validate document completeness</action>
  266. <action>Update state file with output generated</action>
  267. <action>PURGE detailed schema data, keep only: "{{table_count}} tables documented"</action>
  268. <template-output>data_models\*{part_id}</template-output>
  269. </check>
  270. <check if="requires_state_management == true">
  271. <action>Analyze state management patterns</action>
  272. <action>Look for: Redux, Context API, MobX, Vuex, Pinia, Provider patterns</action>
  273. <action>Identify: stores, reducers, actions, state structure</action>
  274. <template-output>state_management_patterns_{part_id}</template-output>
  275. </check>
  276. <check if="requires_ui_components == true">
  277. <action>Inventory UI component library</action>
  278. <action>Scan: components/, ui/, widgets/, views/ folders</action>
  279. <action>Categorize: Layout, Form, Display, Navigation, etc.</action>
  280. <action>Identify: Design system, component patterns, reusable elements</action>
  281. <template-output>ui_component_inventory_{part_id}</template-output>
  282. </check>
  283. <check if="requires_hardware_docs == true">
  284. <action>Look for hardware schematics using hardware_interface_patterns</action>
  285. <ask>This appears to be an embedded/hardware project. Do you have:
  286. - Pinout diagrams
  287. - Hardware schematics
  288. - PCB layouts
  289. - Hardware documentation
  290. If yes, please provide paths or links. [Provide paths or type 'none']
  291. </ask>
  292. <action>Store hardware docs references</action>
  293. <template-output>hardware*documentation*{part_id}</template-output>
  294. </check>
  295. <check if="requires_asset_inventory == true">
  296. <action>Scan and catalog assets using asset_patterns</action>
  297. <action>Categorize by: Images, Audio, 3D Models, Sprites, Textures, etc.</action>
  298. <action>Calculate: Total size, file counts, formats used</action>
  299. <template-output>asset_inventory_{part_id}</template-output>
  300. </check>
  301. <action>Scan for additional patterns based on doc requirements:
  302. - config_patterns → Configuration management
  303. - auth_security_patterns → Authentication/authorization approach
  304. - entry_point_patterns → Application entry points and bootstrap
  305. - shared_code_patterns → Shared libraries and utilities
  306. - async_event_patterns → Event-driven architecture
  307. - ci_cd_patterns → CI/CD pipeline details
  308. - localization_patterns → i18n/l10n support
  309. </action>
  310. <action>Apply scan_level strategy to each pattern scan (quick=glob only, deep/exhaustive=read files)</action>
  311. <template-output>comprehensive*analysis*{part_id}</template-output>
  312. <action>Update state file:
  313. - Add to completed_steps: {"step": "step_4", "status": "completed", "timestamp": "{{now}}", "summary": "Conditional analysis complete, {{files_generated}} files written"}
  314. - Update current_step = "step_5"
  315. - Update last_updated timestamp
  316. - List all outputs_generated
  317. </action>
  318. <action>PURGE all detailed scan results from context. Keep only summaries:
  319. - "APIs: {{api_count}} endpoints"
  320. - "Data: {{table_count}} tables"
  321. - "Components: {{component_count}} components"
  322. </action>
  323. </step>
  324. <step n="5" goal="Generate source tree analysis with annotations" if="workflow_mode != deep_dive">
  325. <action>For each part, generate complete directory tree using critical_directories from doc requirements</action>
  326. <action>Annotate the tree with:
  327. - Purpose of each critical directory
  328. - Entry points marked
  329. - Key file locations highlighted
  330. - Integration points noted (for multi-part projects)
  331. </action>
  332. <action if="multi-part project">Show how parts are organized and where they interface</action>
  333. <action>Create formatted source tree with descriptions:
  334. ```
  335. project-root/
  336. ├── client/ # React frontend (Part: client)
  337. │ ├── src/
  338. │ │ ├── components/ # Reusable UI components
  339. │ │ ├── pages/ # Route-based pages
  340. │ │ └── api/ # API client layer → Calls server/
  341. ├── server/ # Express API backend (Part: api)
  342. │ ├── src/
  343. │ │ ├── routes/ # REST API endpoints
  344. │ │ ├── models/ # Database models
  345. │ │ └── services/ # Business logic
  346. ```
  347. </action>
  348. <template-output>source_tree_analysis</template-output>
  349. <template-output>critical_folders_summary</template-output>
  350. <action>IMMEDIATELY write source-tree-analysis.md to disk</action>
  351. <action>Validate document structure</action>
  352. <action>Update state file:
  353. - Add to completed_steps: {"step": "step_5", "status": "completed", "timestamp": "{{now}}", "summary": "Source tree documented"}
  354. - Update current_step = "step_6"
  355. - Add output: "source-tree-analysis.md"
  356. </action>
  357. <action>PURGE detailed tree from context, keep only: "Source tree with {{folder_count}} critical folders"</action>
  358. </step>
  359. <step n="6" goal="Extract development and operational information" if="workflow_mode != deep_dive">
  360. <action>Scan for development setup using key_file_patterns and existing docs:
  361. - Prerequisites (Node version, Python version, etc.)
  362. - Installation steps (npm install, etc.)
  363. - Environment setup (.env files, config)
  364. - Build commands (npm run build, make, etc.)
  365. - Run commands (npm start, go run, etc.)
  366. - Test commands using test_file_patterns
  367. </action>
  368. <action>Look for deployment configuration using ci_cd_patterns:
  369. - Dockerfile, docker-compose.yml
  370. - Kubernetes configs (k8s/, helm/)
  371. - CI/CD pipelines (.github/workflows/, .gitlab-ci.yml)
  372. - Deployment scripts
  373. - Infrastructure as Code (terraform/, pulumi/)
  374. </action>
  375. <action if="CONTRIBUTING.md or similar found">
  376. <action>Extract contribution guidelines:
  377. - Code style rules
  378. - PR process
  379. - Commit conventions
  380. - Testing requirements
  381. </action>
  382. </action>
  383. <template-output>development_instructions</template-output>
  384. <template-output>deployment_configuration</template-output>
  385. <template-output>contribution_guidelines</template-output>
  386. <action>Update state file:
  387. - Add to completed_steps: {"step": "step_6", "status": "completed", "timestamp": "{{now}}", "summary": "Dev/deployment guides written"}
  388. - Update current_step = "step_7"
  389. - Add generated outputs to list
  390. </action>
  391. <action>PURGE detailed instructions, keep only: "Dev setup and deployment documented"</action>
  392. </step>
  393. <step n="7" goal="Detect multi-part integration architecture" if="workflow_mode != deep_dive and project has multiple parts">
  394. <action>Analyze how parts communicate:
  395. - Scan integration_scan_patterns across parts
  396. - Identify: REST calls, GraphQL queries, gRPC, message queues, shared databases
  397. - Document: API contracts between parts, data flow, authentication flow
  398. </action>
  399. <action>Create integration_points array with:
  400. - from: source part
  401. - to: target part
  402. - type: REST API, GraphQL, gRPC, Event Bus, etc.
  403. - details: Endpoints, protocols, data formats
  404. </action>
  405. <action>IMMEDIATELY write integration-architecture.md to disk</action>
  406. <action>Validate document completeness</action>
  407. <template-output>integration_architecture</template-output>
  408. <action>Update state file:
  409. - Add to completed_steps: {"step": "step_7", "status": "completed", "timestamp": "{{now}}", "summary": "Integration architecture documented"}
  410. - Update current_step = "step_8"
  411. </action>
  412. <action>PURGE integration details, keep only: "{{integration_count}} integration points"</action>
  413. </step>
  414. <step n="8" goal="Generate architecture documentation for each part" if="workflow_mode != deep_dive">
  415. <action>For each part in project_parts:
  416. - Use matched architecture template from Step 3 as base structure
  417. - Fill in all sections with discovered information:
  418. * Executive Summary
  419. * Technology Stack (from Step 3)
  420. * Architecture Pattern (from registry match)
  421. * Data Architecture (from Step 4 data models scan)
  422. * API Design (from Step 4 API scan if applicable)
  423. * Component Overview (from Step 4 component scan if applicable)
  424. * Source Tree (from Step 5)
  425. * Development Workflow (from Step 6)
  426. * Deployment Architecture (from Step 6)
  427. * Testing Strategy (from test patterns)
  428. </action>
  429. <action if="single part project">
  430. - Generate: architecture.md (no part suffix)
  431. </action>
  432. <action if="multi-part project">
  433. - Generate: architecture-{part_id}.md for each part
  434. </action>
  435. <action>For each architecture file generated:
  436. - IMMEDIATELY write architecture file to disk
  437. - Validate against architecture template schema
  438. - Update state file with output
  439. - PURGE detailed architecture from context, keep only: "Architecture for {{part_id}} written"
  440. </action>
  441. <template-output>architecture_document</template-output>
  442. <action>Update state file:
  443. - Add to completed_steps: {"step": "step_8", "status": "completed", "timestamp": "{{now}}", "summary": "Architecture docs written for {{parts_count}} parts"}
  444. - Update current_step = "step_9"
  445. </action>
  446. </step>
  447. <step n="9" goal="Generate supporting documentation files" if="workflow_mode != deep_dive">
  448. <action>Generate project-overview.md with:
  449. - Project name and purpose (from README or user input)
  450. - Executive summary
  451. - Tech stack summary table
  452. - Architecture type classification
  453. - Repository structure (monolith/monorepo/multi-part)
  454. - Links to detailed docs
  455. </action>
  456. <action>Generate source-tree-analysis.md with:
  457. - Full annotated directory tree from Step 5
  458. - Critical folders explained
  459. - Entry points documented
  460. - Multi-part structure (if applicable)
  461. </action>
  462. <action>IMMEDIATELY write project-overview.md to disk</action>
  463. <action>Validate document sections</action>
  464. <action>Generate source-tree-analysis.md (if not already written in Step 5)</action>
  465. <action>IMMEDIATELY write to disk and validate</action>
  466. <action>Generate component-inventory.md (or per-part versions) with:
  467. - All discovered components from Step 4
  468. - Categorized by type
  469. - Reusable vs specific components
  470. - Design system elements (if found)
  471. </action>
  472. <action>IMMEDIATELY write each component inventory to disk and validate</action>
  473. <action>Generate development-guide.md (or per-part versions) with:
  474. - Prerequisites and dependencies
  475. - Environment setup instructions
  476. - Local development commands
  477. - Build process
  478. - Testing approach and commands
  479. - Common development tasks
  480. </action>
  481. <action>IMMEDIATELY write each development guide to disk and validate</action>
  482. <action if="deployment configuration found">
  483. <action>Generate deployment-guide.md with:
  484. - Infrastructure requirements
  485. - Deployment process
  486. - Environment configuration
  487. - CI/CD pipeline details
  488. </action>
  489. <action>IMMEDIATELY write to disk and validate</action>
  490. </action>
  491. <action if="contribution guidelines found">
  492. <action>Generate contribution-guide.md with:
  493. - Code style and conventions
  494. - PR process
  495. - Testing requirements
  496. - Documentation standards
  497. </action>
  498. <action>IMMEDIATELY write to disk and validate</action>
  499. </action>
  500. <action if="API contracts documented">
  501. <action>Generate api-contracts.md (or per-part) with:
  502. - All API endpoints
  503. - Request/response schemas
  504. - Authentication requirements
  505. - Example requests
  506. </action>
  507. <action>IMMEDIATELY write to disk and validate</action>
  508. </action>
  509. <action if="Data models documented">
  510. <action>Generate data-models.md (or per-part) with:
  511. - Database schema
  512. - Table relationships
  513. - Data models and entities
  514. - Migration strategy
  515. </action>
  516. <action>IMMEDIATELY write to disk and validate</action>
  517. </action>
  518. <action if="multi-part project">
  519. <action>Generate integration-architecture.md with:
  520. - How parts communicate
  521. - Integration points diagram/description
  522. - Data flow between parts
  523. - Shared dependencies
  524. </action>
  525. <action>IMMEDIATELY write to disk and validate</action>
  526. <action>Generate project-parts.json metadata file:
  527. `json
  528. {
  529. "repository_type": "monorepo",
  530. "parts": [ ... ],
  531. "integration_points": [ ... ]
  532. }
  533. `
  534. </action>
  535. <action>IMMEDIATELY write to disk</action>
  536. </action>
  537. <template-output>supporting_documentation</template-output>
  538. <action>Update state file:
  539. - Add to completed_steps: {"step": "step_9", "status": "completed", "timestamp": "{{now}}", "summary": "All supporting docs written"}
  540. - Update current_step = "step_10"
  541. - List all newly generated outputs
  542. </action>
  543. <action>PURGE all document contents from context, keep only list of files generated</action>
  544. </step>
  545. <step n="10" goal="Generate master index as primary AI retrieval source" if="workflow_mode != deep_dive">
  546. <critical>INCOMPLETE DOCUMENTATION MARKER CONVENTION:
  547. When a document SHOULD be generated but wasn't (due to quick scan, missing data, conditional requirements not met):
  548. - Use EXACTLY this marker: _(To be generated)_
  549. - Place it at the end of the markdown link line
  550. - Example: - [API Contracts - Server](./api-contracts-server.md) _(To be generated)_
  551. - This allows Step 11 to detect and offer to complete these items
  552. - ALWAYS use this exact format for consistency and automated detection
  553. </critical>
  554. <action>Create index.md with intelligent navigation based on project structure</action>
  555. <action if="single part project">
  556. <action>Generate simple index with:
  557. - Project name and type
  558. - Quick reference (tech stack, architecture type)
  559. - Links to all generated docs
  560. - Links to discovered existing docs
  561. - Getting started section
  562. </action>
  563. </action>
  564. <action if="multi-part project">
  565. <action>Generate comprehensive index with:
  566. - Project overview and structure summary
  567. - Part-based navigation section
  568. - Quick reference by part
  569. - Cross-part integration links
  570. - Links to all generated and existing docs
  571. - Getting started per part
  572. </action>
  573. </action>
  574. <action>Include in index.md:
  575. ## Project Documentation Index
  576. ### Project Overview
  577. - **Type:** {{repository_type}} {{#if multi-part}}with {{parts.length}} parts{{/if}}
  578. - **Primary Language:** {{primary_language}}
  579. - **Architecture:** {{architecture_type}}
  580. ### Quick Reference
  581. {{#if single_part}}
  582. - **Tech Stack:** {{tech_stack_summary}}
  583. - **Entry Point:** {{entry_point}}
  584. - **Architecture Pattern:** {{architecture_pattern}}
  585. {{else}}
  586. {{#each parts}}
  587. #### {{part_name}} ({{part_id}})
  588. - **Type:** {{project_type}}
  589. - **Tech Stack:** {{tech_stack}}
  590. - **Root:** {{root_path}}
  591. {{/each}}
  592. {{/if}}
  593. ### Generated Documentation
  594. - [Project Overview](./project-overview.md)
  595. - [Architecture](./architecture{{#if multi-part}}-{part\*id}{{/if}}.md){{#unless architecture_file_exists}} (To be generated) {{/unless}}
  596. - [Source Tree Analysis](./source-tree-analysis.md)
  597. - [Component Inventory](./component-inventory{{#if multi-part}}-{part\*id}{{/if}}.md){{#unless component_inventory_exists}} (To be generated) {{/unless}}
  598. - [Development Guide](./development-guide{{#if multi-part}}-{part\*id}{{/if}}.md){{#unless dev_guide_exists}} (To be generated) {{/unless}}
  599. {{#if deployment_found}}- [Deployment Guide](./deployment-guide.md){{#unless deployment_guide_exists}} (To be generated) {{/unless}}{{/if}}
  600. {{#if contribution_found}}- [Contribution Guide](./contribution-guide.md){{/if}}
  601. {{#if api_documented}}- [API Contracts](./api-contracts{{#if multi-part}}-{part_id}{{/if}}.md){{#unless api_contracts_exists}} (To be generated) {{/unless}}{{/if}}
  602. {{#if data_models_documented}}- [Data Models](./data-models{{#if multi-part}}-{part_id}{{/if}}.md){{#unless data_models_exists}} (To be generated) {{/unless}}{{/if}}
  603. {{#if multi-part}}- [Integration Architecture](./integration-architecture.md){{#unless integration_arch_exists}} (To be generated) {{/unless}}{{/if}}
  604. ### Existing Documentation
  605. {{#each existing_docs}}
  606. - [{{title}}]({{relative_path}}) - {{description}}
  607. {{/each}}
  608. ### Getting Started
  609. {{getting_started_instructions}}
  610. </action>
  611. <action>Before writing index.md, check which expected files actually exist:
  612. - For each document that should have been generated, check if file exists on disk
  613. - Set existence flags: architecture_file_exists, component_inventory_exists, dev_guide_exists, etc.
  614. - These flags determine whether to add the _(To be generated)_ marker
  615. - Track which files are missing in {{missing_docs_list}} for reporting
  616. </action>
  617. <action>IMMEDIATELY write index.md to disk with appropriate _(To be generated)_ markers for missing files</action>
  618. <action>Validate index has all required sections and links are valid</action>
  619. <template-output>index</template-output>
  620. <action>Update state file:
  621. - Add to completed_steps: {"step": "step_10", "status": "completed", "timestamp": "{{now}}", "summary": "Master index generated"}
  622. - Update current_step = "step_11"
  623. - Add output: "index.md"
  624. </action>
  625. <action>PURGE index content from context</action>
  626. </step>
  627. <step n="11" goal="Validate and review generated documentation" if="workflow_mode != deep_dive">
  628. <action>Show summary of all generated files:
  629. Generated in {{project_knowledge}}/:
  630. {{file_list_with_sizes}}
  631. </action>
  632. <action>Run validation checklist from ../checklist.md</action>
  633. <critical>INCOMPLETE DOCUMENTATION DETECTION:
  634. 1. PRIMARY SCAN: Look for exact marker: _(To be generated)_
  635. 2. FALLBACK SCAN: Look for fuzzy patterns (in case agent was lazy):
  636. - _(TBD)_
  637. - _(TODO)_
  638. - _(Coming soon)_
  639. - _(Not yet generated)_
  640. - _(Pending)_
  641. 3. Extract document metadata from each match for user selection
  642. </critical>
  643. <action>Read {project_knowledge}/index.md</action>
  644. <action>Scan for incomplete documentation markers:
  645. Step 1: Search for exact pattern "_(To be generated)_" (case-sensitive)
  646. Step 2: For each match found, extract the entire line
  647. Step 3: Parse line to extract:
  648. - Document title (text within [brackets] or **bold**)
  649. - File path (from markdown link or inferable from title)
  650. - Document type (infer from filename: architecture, api-contracts, data-models, component-inventory, development-guide, deployment-guide, integration-architecture)
  651. - Part ID if applicable (extract from filename like "architecture-server.md" → part_id: "server")
  652. Step 4: Add to {{incomplete_docs_strict}} array
  653. </action>
  654. <action>Fallback fuzzy scan for alternate markers:
  655. Search for patterns: _(TBD)_, _(TODO)_, _(Coming soon)_, _(Not yet generated)_, _(Pending)_
  656. For each fuzzy match:
  657. - Extract same metadata as strict scan
  658. - Add to {{incomplete_docs_fuzzy}} array with fuzzy_match flag
  659. </action>
  660. <action>Combine results:
  661. Set {{incomplete_docs_list}} = {{incomplete_docs_strict}} + {{incomplete_docs_fuzzy}}
  662. For each item store structure:
  663. {
  664. "title": "Architecture – Server",
  665. "file\*path": "./architecture-server.md",
  666. "doc_type": "architecture",
  667. "part_id": "server",
  668. "line_text": "- [Architecture – Server](./architecture-server.md) (To be generated)",
  669. "fuzzy_match": false
  670. }
  671. </action>
  672. <ask>Documentation generation complete!
  673. Summary:
  674. - Project Type: {{project_type_summary}}
  675. - Parts Documented: {{parts_count}}
  676. - Files Generated: {{files_count}}
  677. - Total Lines: {{total_lines}}
  678. {{#if incomplete_docs_list.length > 0}}
  679. ⚠️ **Incomplete Documentation Detected:**
  680. I found {{incomplete_docs_list.length}} item(s) marked as incomplete:
  681. {{#each incomplete_docs_list}}
  682. {{@index + 1}}. **{{title}}** ({{doc_type}}{{#if part_id}} for {{part_id}}{{/if}}){{#if fuzzy_match}} ⚠️ [non-standard marker]{{/if}}
  683. {{/each}}
  684. {{/if}}
  685. Would you like to:
  686. {{#if incomplete_docs_list.length > 0}}
  687. 1. **Generate incomplete documentation** - Complete any of the {{incomplete_docs_list.length}} items above
  688. 2. Review any specific section [type section name]
  689. 3. Add more detail to any area [type area name]
  690. 4. Generate additional custom documentation [describe what]
  691. 5. Finalize and complete [type 'done']
  692. {{else}}
  693. 6. Review any specific section [type section name]
  694. 7. Add more detail to any area [type area name]
  695. 8. Generate additional documentation [describe what]
  696. 9. Finalize and complete [type 'done']
  697. {{/if}}
  698. Your choice:
  699. </ask>
  700. <check if="user selects option 1 (generate incomplete)">
  701. <ask>Which incomplete items would you like to generate?
  702. {{#each incomplete_docs_list}}
  703. {{@index + 1}}. {{title}} ({{doc_type}}{{#if part_id}} - {{part_id}}{{/if}})
  704. {{/each}}
  705. {{incomplete_docs_list.length + 1}}. All of them
  706. Enter number(s) separated by commas (e.g., "1,3,5"), or type 'all':
  707. </ask>
  708. <action>Parse user selection:
  709. - If "all", set {{selected_items}} = all items in {{incomplete_docs_list}}
  710. - If comma-separated numbers, extract selected items by index
  711. - Store result in {{selected_items}} array
  712. </action>
  713. <action>Display: "Generating {{selected_items.length}} document(s)..."</action>
  714. <action>For each item in {{selected_items}}:
  715. 1. **Identify the part and requirements:**
  716. - Extract part_id from item (if exists)
  717. - Look up part data in project_parts array from state file
  718. - Load documentation_requirements for that part's project_type_id
  719. 2. **Route to appropriate generation substep based on doc_type:**
  720. **If doc_type == "architecture":**
  721. - Display: "Generating architecture documentation for {{part_id}}..."
  722. - Load architecture_match for this part from state file (Step 3 cache)
  723. - Re-run Step 8 architecture generation logic ONLY for this specific part
  724. - Use matched template and fill with cached data from state file
  725. - Write architecture-{{part_id}}.md to disk
  726. - Validate completeness
  727. **If doc_type == "api-contracts":**
  728. - Display: "Generating API contracts for {{part_id}}..."
  729. - Load part data and documentation_requirements
  730. - Re-run Step 4 API scan substep targeting ONLY this part
  731. - Use scan_level from state file (quick/deep/exhaustive)
  732. - Generate api-contracts-{{part_id}}.md
  733. - Validate document structure
  734. **If doc_type == "data-models":**
  735. - Display: "Generating data models documentation for {{part_id}}..."
  736. - Re-run Step 4 data models scan substep targeting ONLY this part
  737. - Use schema_migration_patterns from documentation_requirements
  738. - Generate data-models-{{part_id}}.md
  739. - Validate completeness
  740. **If doc_type == "component-inventory":**
  741. - Display: "Generating component inventory for {{part_id}}..."
  742. - Re-run Step 9 component inventory generation for this specific part
  743. - Scan components/, ui/, widgets/ folders
  744. - Generate component-inventory-{{part_id}}.md
  745. - Validate structure
  746. **If doc_type == "development-guide":**
  747. - Display: "Generating development guide for {{part_id}}..."
  748. - Re-run Step 9 development guide generation for this specific part
  749. - Use key_file_patterns and test_file_patterns from documentation_requirements
  750. - Generate development-guide-{{part_id}}.md
  751. - Validate completeness
  752. **If doc_type == "deployment-guide":**
  753. - Display: "Generating deployment guide..."
  754. - Re-run Step 6 deployment configuration scan
  755. - Re-run Step 9 deployment guide generation
  756. - Generate deployment-guide.md
  757. - Validate structure
  758. **If doc_type == "integration-architecture":**
  759. - Display: "Generating integration architecture..."
  760. - Re-run Step 7 integration analysis for all parts
  761. - Generate integration-architecture.md
  762. - Validate completeness
  763. 3. **Post-generation actions:**
  764. - Confirm file was written successfully
  765. - Update state file with newly generated output
  766. - Add to {{newly_generated_docs}} tracking list
  767. - Display: "✓ Generated: {{file_path}}"
  768. 4. **Handle errors:**
  769. - If generation fails, log error and continue with next item
  770. - Track failed items in {{failed_generations}} list
  771. </action>
  772. <action>After all selected items are processed:
  773. **Update index.md to remove markers:**
  774. 1. Read current index.md content
  775. 2. For each item in {{newly_generated_docs}}:
  776. - Find the line containing the file link and marker
  777. - Remove the _(To be generated)_ or fuzzy marker text
  778. - Leave the markdown link intact
  779. 3. Write updated index.md back to disk
  780. 4. Update state file to record index.md modification
  781. </action>
  782. <action>Display generation summary:
  783. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  784. ✓ **Documentation Generation Complete!**
  785. **Successfully Generated:**
  786. {{#each newly_generated_docs}}
  787. - {{title}} → {{file_path}}
  788. {{/each}}
  789. {{#if failed_generations.length > 0}}
  790. **Failed to Generate:**
  791. {{#each failed_generations}}
  792. - {{title}} ({{error_message}})
  793. {{/each}}
  794. {{/if}}
  795. **Updated:** index.md (removed incomplete markers)
  796. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  797. </action>
  798. <action>Update state file with all generation activities</action>
  799. <action>Return to Step 11 menu (loop back to check for any remaining incomplete items)</action>
  800. </check>
  801. <action if="user requests other changes (options 2-3)">Make requested modifications and regenerate affected files</action>
  802. <action if="user selects finalize (option 4 or 5)">Proceed to Step 12 completion</action>
  803. <check if="not finalizing">
  804. <action>Update state file:
  805. - Add to completed_steps: {"step": "step_11_iteration", "status": "completed", "timestamp": "{{now}}", "summary": "Review iteration complete"}
  806. - Keep current_step = "step_11" (for loop back)
  807. - Update last_updated timestamp
  808. </action>
  809. <action>Loop back to beginning of Step 11 (re-scan for remaining incomplete docs)</action>
  810. </check>
  811. <check if="finalizing">
  812. <action>Update state file:
  813. - Add to completed_steps: {"step": "step_11", "status": "completed", "timestamp": "{{now}}", "summary": "Validation and review complete"}
  814. - Update current_step = "step_12"
  815. </action>
  816. <action>Proceed to Step 12</action>
  817. </check>
  818. </step>
  819. <step n="12" goal="Finalize and provide next steps" if="workflow_mode != deep_dive">
  820. <action>Create final summary report</action>
  821. <action>Compile verification recap variables:
  822. - Set {{verification_summary}} to the concrete tests, validations, or scripts you executed (or "none run").
  823. - Set {{open_risks}} to any remaining risks or TODO follow-ups (or "none").
  824. - Set {{next_checks}} to recommended actions before merging/deploying (or "none").
  825. </action>
  826. <action>Display completion message:
  827. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  828. ## Project Documentation Complete! ✓
  829. **Location:** {{project_knowledge}}/
  830. **Master Index:** {{project_knowledge}}/index.md
  831. 👆 This is your primary entry point for AI-assisted development
  832. **Generated Documentation:**
  833. {{generated_files_list}}
  834. **Next Steps:**
  835. 1. Review the index.md to familiarize yourself with the documentation structure
  836. 2. When creating a brownfield PRD, point the PRD workflow to: {{project_knowledge}}/index.md
  837. 3. For UI-only features: Reference {{project_knowledge}}/architecture-{{ui_part_id}}.md
  838. 4. For API-only features: Reference {{project_knowledge}}/architecture-{{api_part_id}}.md
  839. 5. For full-stack features: Reference both part architectures + integration-architecture.md
  840. **Verification Recap:**
  841. - Tests/extractions executed: {{verification_summary}}
  842. - Outstanding risks or follow-ups: {{open_risks}}
  843. - Recommended next checks before PR: {{next_checks}}
  844. **Brownfield PRD Command:**
  845. When ready to plan new features, run the PRD workflow and provide this index as input.
  846. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  847. </action>
  848. <action>FINALIZE state file:
  849. - Add to completed_steps: {"step": "step_12", "status": "completed", "timestamp": "{{now}}", "summary": "Workflow complete"}
  850. - Update timestamps.completed = "{{now}}"
  851. - Update current_step = "completed"
  852. - Write final state file
  853. </action>
  854. <action>Display: "State file saved: {{project_knowledge}}/project-scan-report.json"</action>
  855. <action>Run: `python3 {project-root}/_bmad/scripts/resolve_customization.py --skill {skill-root} --key workflow.on_complete` — if the resolved value is non-empty, follow it as the final terminal instruction before exiting.</action>
  856. </workflow>