diff --git a/src/modules/bmm/agents/sm.agent.yaml b/src/modules/bmm/agents/sm.agent.yaml index 2fb883e5..7b1000ef 100644 --- a/src/modules/bmm/agents/sm.agent.yaml +++ b/src/modules/bmm/agents/sm.agent.yaml @@ -57,3 +57,7 @@ agent: - trigger: RVE or fuzzy match on revalidate-epic workflow: "{project-root}/_bmad/bmm/workflows/4-implementation/revalidate-epic/workflow.yaml" description: "[RVE] Revalidate Epic - batch revalidation of all stories with semaphore pattern" + + - trigger: GFD or fuzzy match on ghost-features + workflow: "{project-root}/_bmad/bmm/workflows/4-implementation/detect-ghost-features/workflow.yaml" + description: "[GFD] Ghost Feature Detector - find orphaned code with no stories (reverse gap analysis)" diff --git a/src/modules/bmm/workflows/4-implementation/detect-ghost-features/instructions.md b/src/modules/bmm/workflows/4-implementation/detect-ghost-features/instructions.md new file mode 100644 index 00000000..dc113271 --- /dev/null +++ b/src/modules/bmm/workflows/4-implementation/detect-ghost-features/instructions.md @@ -0,0 +1,625 @@ +# Detect Ghost Features - Reverse Gap Analysis (Who You Gonna Call?) + +The workflow execution engine is governed by: {project-root}/_bmad/core/tasks/workflow.xml +You MUST have already loaded and processed: {installed_path}/workflow.yaml + + + + + Determine scan scope based on parameters: + + + Read {sprint_status} + Filter stories starting with "{{epic_number}}-" + Store as: stories_in_scope + 🔍 Scanning Epic {{epic_number}} stories for documented features... + + + + Read {sprint_status} + Get ALL story keys (exclude epics and retrospectives) + Store as: stories_in_scope + 🔍 Scanning entire sprint for documented features... + + + + Set stories_in_scope = ALL stories found in {sprint_artifacts} + 🔍 Scanning entire codebase for documented features... + + + For each story in stories_in_scope: + Read story file + Extract documented artifacts: + - File List (all paths mentioned) + - Tasks (all file/component/service names mentioned) + - ACs (all features/functionality mentioned) + Store in: documented_artifacts[story_key] = {files, components, services, apis, features} + + +✅ Loaded {{stories_in_scope.length}} stories +📋 Documented artifacts extracted from {{total_sections}} sections + + + + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +👻 SCANNING FOR GHOST FEATURES +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Looking for: Components, APIs, Services, DB Tables, Models +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + + Use Glob to find component files: + - **/*.component.{tsx,jsx,ts,js,vue} (Angular/Vue pattern) + - **/components/**/*.{tsx,jsx} (React pattern) + - **/src/**/*{Component,View,Screen,Page}.{tsx,jsx} (Named pattern) + + For each found component file: + Extract component name from filename or export + Check file size (ignore <50 lines as trivial) + Read file to determine if it's a significant feature + + Store as: codebase_components = [{name, path, size, purpose}] + + 📦 Found {{codebase_components.length}} components + + + + + + Use Glob to find API files: + - **/api/**/*.{ts,js} (Next.js/Express pattern) + - **/*.controller.{ts,js} (NestJS pattern) + - **/routes/**/*.{ts,js} (Generic routes) + + Use Grep to find endpoint definitions: + - @Get|@Post|@Put|@Delete decorators (NestJS) + - export async function GET|POST|PUT|DELETE (Next.js App Router) + - router.get|post|put|delete (Express) + - app.route (Flask/FastAPI if Python) + + For each endpoint found: + Extract: HTTP method, path, handler name + Read file to understand functionality + + Store as: codebase_apis = [{method, path, handler, file}] + + 🌐 Found {{codebase_apis.length}} API endpoints + + + + + + Use Glob to find schema files: + - **/prisma/schema.prisma (Prisma) + - **/*.entity.{ts,js} (TypeORM) + - **/models/**/*.{ts,js} (Mongoose/Sequelize) + - **/*-table.ts (Custom) + + Use Grep to find table definitions: + - model (Prisma) + - @Entity (TypeORM) + - createTable (Migrations) + + For each table found: + Extract: table name, columns, relationships + + Store as: codebase_tables = [{name, file, columns}] + + 🗄️ Found {{codebase_tables.length}} database tables + + + + + + Use Glob to find service files: + - **/*.service.{ts,js} + - **/services/**/*.{ts,js} + - **/*Service.{ts,js} + + For each service found: + Extract: service name, key methods, dependencies + Ignore trivial services (<100 lines) + + Store as: codebase_services = [{name, file, methods}] + + ⚙️ Found {{codebase_services.length}} services + + + + + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +🔍 CROSS-REFERENCING CODEBASE ↔ STORIES +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + Initialize: orphaned_features = [] + + + For each component in codebase_components: + + Search all stories for mentions of: + - Component name in File Lists + - Component name in Task descriptions + - Component file path in File Lists + - Feature described by component in ACs + + + Add to orphaned_features: + + type: "component" + name: {{component.name}} + path: {{component.path}} + size: {{component.size}} lines + purpose: {{inferred_purpose_from_code}} + severity: "HIGH" # Significant orphan + + 👻 ORPHAN: {{component.name}} ({{component.path}}) + + + + ✅ Documented: {{component.name}} → {{story_keys}} + + + + + For each API in codebase_apis: + + Search all stories for mentions of: + - Endpoint path (e.g., "/api/users") + - HTTP method + resource (e.g., "POST users") + - Handler file in File Lists + - API functionality in ACs (e.g., "Users can create account") + + + Add to orphaned_features: + + type: "api" + method: {{api.method}} + path: {{api.path}} + handler: {{api.handler}} + file: {{api.file}} + severity: "CRITICAL" # APIs are critical functionality + + 👻 ORPHAN: {{api.method}} {{api.path}} ({{api.file}}) + + + + + For each table in codebase_tables: + + Search all stories for mentions of: + - Table name + - Migration file in File Lists + - Data model in Tasks + + + Add to orphaned_features: + + type: "database" + name: {{table.name}} + file: {{table.file}} + columns: {{table.columns.length}} + severity: "HIGH" # Database changes are significant + + 👻 ORPHAN: Table {{table.name}} ({{table.file}}) + + + + + For each service in codebase_services: + + Search all stories for mentions of: + - Service name or class name + - Service file in File Lists + - Service functionality in Tasks/ACs + + + Add to orphaned_features: + + type: "service" + name: {{service.name}} + file: {{service.file}} + methods: {{service.methods.length}} + severity: "MEDIUM" # Services are business logic + + 👻 ORPHAN: {{service.name}} ({{service.file}}) + + + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +Cross-Reference Complete +👻 Orphaned Features: {{orphaned_features.length}} +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + + Group orphans by type and severity: + + - critical_orphans (APIs, auth, payment) + - high_orphans (Components, DB tables, services) + - medium_orphans (Utilities, helpers) + - low_orphans (Config files, constants) + + + Estimate complexity for each orphan: + Based on file size, dependencies, test coverage + + Suggest epic assignment based on functionality: + - Auth components → Epic focusing on authentication + - UI components → Epic focusing on frontend + - API endpoints → Epic for that resource type + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +👻 GHOST FEATURES DETECTED +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +**Total Orphans:** {{orphaned_features.length}} + +**By Severity:** +- 🔴 CRITICAL: {{critical_orphans.length}} (APIs, security-critical) +- 🟠 HIGH: {{high_orphans.length}} (Components, DB, services) +- 🟡 MEDIUM: {{medium_orphans.length}} (Utilities, helpers) +- 🟢 LOW: {{low_orphans.length}} (Config, constants) + +**By Type:** +- Components: {{component_orphans.length}} +- API Endpoints: {{api_orphans.length}} +- Database Tables: {{db_orphans.length}} +- Services: {{service_orphans.length}} +- Other: {{other_orphans.length}} + +--- + +**CRITICAL Orphans (Immediate Action Required):** +{{#each critical_orphans}} +{{@index + 1}}. **{{type | uppercase}}**: {{name}} + File: {{file}} + Purpose: {{inferred_purpose}} + Risk: {{why_critical}} + Suggested Epic: {{suggested_epic}} +{{/each}} + +--- + +**HIGH Priority Orphans:** +{{#each high_orphans}} +{{@index + 1}}. **{{type | uppercase}}**: {{name}} + File: {{file}} + Size: {{size}} lines / {{complexity}} complexity + Suggested Epic: {{suggested_epic}} +{{/each}} + +--- + +**Detection Confidence:** +- Artifacts scanned: {{total_artifacts_scanned}} +- Stories cross-referenced: {{stories_in_scope.length}} +- Documentation coverage: {{documented_pct}}% +- Orphan rate: {{orphan_rate}}% + +{{#if orphan_rate > 20}} +⚠️ **HIGH ORPHAN RATE** - Over 20% of codebase is undocumented! +Recommend: Comprehensive backfill story creation session +{{/if}} + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + + + +Backfill story creation disabled. To create stories for orphans, run: +/detect-ghost-features create_backfill_stories=true + + Jump to Step 7 (Generate Report) + + + + ✅ No orphans found - all code is documented in stories! + Jump to Step 7 + + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +📝 PROPOSING BACKFILL STORIES ({{orphaned_features.length}}) +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + For each orphaned feature (prioritized by severity): + + + Analyze orphan to understand functionality: + - Read implementation code + - Identify dependencies and related files + - Determine what it does (infer from code) + - Find tests (if any) to understand use cases + + Generate story draft: + +Story Title: "Document existing {{name}} {{type}}" + +Story Description: +This is a BACKFILL STORY documenting existing functionality found in the codebase +that was not tracked in any story (likely vibe-coded or manually added). + +Business Context: +{{inferred_business_purpose_from_code}} + +Current State: +✅ **Implementation EXISTS:** {{file}} +- {{description_of_what_it_does}} +- {{key_features_or_methods}} +{{#if has_tests}}✅ Tests exist: {{test_files}}{{else}}❌ No tests found{{/if}} + +Acceptance Criteria: +{{#each inferred_acs_from_code}} +- [ ] {{this}} +{{/each}} + +Tasks: +- [x] {{name}} implementation (ALREADY EXISTS - {{file}}) +{{#if missing_tests}}- [ ] Add tests for {{name}}{{/if}} +{{#if missing_docs}}- [ ] Add documentation for {{name}}{{/if}} +- [ ] Verify functionality works as expected +- [ ] Add to relevant epic or create new epic for backfills + +Definition of Done: +- [x] Implementation exists and works +{{#if has_tests}}- [x] Tests exist{{else}}- [ ] Tests added{{/if}} +- [ ] Documented in story (this story) +- [ ] Assigned to appropriate epic + +Story Type: BACKFILL (documenting existing code) + + + +📄 Generated backfill story draft for: {{name}} + +{{story_draft_preview}} + +--- + + + + + + Create backfill story automatically + ✅ Auto-created: {{story_filename}} + + + + +Create backfill story for {{name}}? + +**Type:** {{type}} +**File:** {{file}} +**Suggested Epic:** {{suggested_epic}} +**Complexity:** {{complexity_estimate}} + +[Y] Yes - Create this backfill story +[A] Auto - Create this and all remaining backfill stories +[E] Edit - Let me adjust the story draft first +[S] Skip - Don't create story for this orphan +[H] Halt - Stop backfill story creation + +Your choice: + + + + Create backfill story file: {sprint_artifacts}/backfill-{{type}}-{{name}}.md + Add to backfill_stories_created list + ✅ Created: {{story_filename}} + + + + Set auto_create = true + Create this story and auto-create remaining + + + + Provide your adjusted story content or instructions for modifications: + Apply user's edits to story draft + Create modified backfill story + + + + Add to skipped_backfills list + ⏭️ Skipped + + + + Exit backfill story creation loop + Jump to Step 6 + + + + + + Load {sprint_status} file + + For each created backfill story: + Add entry: {{backfill_story_key}}: backlog # BACKFILL - documents existing {{name}} + + Save sprint-status.yaml + + ✅ Added {{backfill_stories_created.length}} backfill stories to sprint-status.yaml + + + + + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +📊 BACKFILL STORY ORGANIZATION +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + Group backfill stories by suggested epic: + + For each suggested_epic: + +**{{suggested_epic}}:** +{{#each backfill_stories_for_epic}} + - {{story_key}}: {{name}} ({{type}}) +{{/each}} + + + +--- + +**Recommendations:** + +1. **Option A: Create "Epic-Backfill" for all orphans** + - Single epic containing all backfill stories + - Easy to track undocumented code + - Clear separation from feature work + +2. **Option B: Distribute to existing epics** + - Add each backfill story to its logical epic + - Better thematic grouping + - May inflate epic story counts + +3. **Option C: Leave in backlog** + - Don't assign to epics yet + - Review and assign during next planning + +**Your choice:** +[A] Create Epic-Backfill (recommended) +[B] Distribute to existing epics +[C] Leave in backlog for manual assignment +[S] Skip epic assignment + + + How should backfill stories be organized? + + + Create epic-backfill.md in epics directory + Update sprint-status.yaml with epic-backfill entry + Assign all backfill stories to epic-backfill + + + + For each backfill story: + Assign to suggested_epic in sprint-status.yaml + Update story_key to match epic (e.g., 2-11-backfill-userprofile) + + + + Leave stories in backlog + + + + + + + Write report to: {sprint_artifacts}/ghost-features-report-{{timestamp}}.md + + Report structure: + +# Ghost Features Report (Reverse Gap Analysis) + +**Generated:** {{timestamp}} +**Scope:** {{scan_scope}} {{#if epic_number}}(Epic {{epic_number}}){{/if}} + +## Executive Summary + +**Codebase Artifacts Scanned:** {{total_artifacts_scanned}} +**Stories Cross-Referenced:** {{stories_in_scope.length}} +**Orphaned Features Found:** {{orphaned_features.length}} +**Documentation Coverage:** {{documented_pct}}% +**Backfill Stories Created:** {{backfill_stories_created.length}} + +## Orphaned Features Detail + +### CRITICAL Orphans ({{critical_orphans.length}}) +[Full list with files, purposes, risks] + +### HIGH Priority Orphans ({{high_orphans.length}}) +[Full list] + +### MEDIUM Priority Orphans ({{medium_orphans.length}}) +[Full list] + +## Backfill Stories Created + +{{#each backfill_stories_created}} +- {{story_key}}: {{story_file}} +{{/each}} + +## Recommendations + +[Epic assignment suggestions, next steps] + +## Appendix: Scan Methodology + +[How detection worked, patterns used, confidence levels] + + + 📄 Full report: {{report_path}} + + + + + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +✅ GHOST FEATURE DETECTION COMPLETE +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ +**Scan Scope:** {{scan_scope}} {{#if epic_number}}(Epic {{epic_number}}){{/if}} + +**Results:** +- 👻 Orphaned Features: {{orphaned_features.length}} +- 📝 Backfill Stories Created: {{backfill_stories_created.length}} +- ⏭️ Skipped: {{skipped_backfills.length}} +- 📊 Documentation Coverage: {{documented_pct}}% + +{{#if orphaned_features.length == 0}} +✅ **EXCELLENT!** All code is documented in stories. +Your codebase and story backlog are in perfect sync. +{{/if}} + +{{#if orphaned_features.length > 0 AND backfill_stories_created.length == 0}} +**Action Required:** +Run with create_backfill_stories=true to generate stories for orphans +{{/if}} + +{{#if backfill_stories_created.length > 0}} +**Next Steps:** + +1. **Review backfill stories** - Check generated stories for accuracy +2. **Assign to epics** - Organize backfills (or create Epic-Backfill) +3. **Update sprint-status.yaml** - Already updated with {{backfill_stories_created.length}} new entries +4. **Prioritize** - Decide when to implement tests/docs for orphans +5. **Run revalidation** - Verify orphans work as expected + +**Quick Commands:** +```bash +# Revalidate a backfill story to verify functionality +/revalidate-story story_file={{backfill_stories_created[0].file}} + +# Process backfill stories (add tests/docs) +/batch-super-dev filter_by_epic=backfill +``` +{{/if}} + +{{#if create_report}} +**Detailed Report:** {{report_path}} +{{/if}} + +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + +💡 **Pro Tip:** Run this periodically (e.g., end of each sprint) to catch +vibe-coded features before they become maintenance nightmares. +━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + + + + diff --git a/src/modules/bmm/workflows/4-implementation/detect-ghost-features/workflow.yaml b/src/modules/bmm/workflows/4-implementation/detect-ghost-features/workflow.yaml new file mode 100644 index 00000000..e5c9f6cb --- /dev/null +++ b/src/modules/bmm/workflows/4-implementation/detect-ghost-features/workflow.yaml @@ -0,0 +1,56 @@ +name: detect-ghost-features +description: "Reverse gap analysis: Find functionality in codebase that has no corresponding story (vibe-coded or undocumented features). Propose backfill stories." +author: "BMad" +version: "1.0.0" # Who you gonna call? GHOST-FEATURE-BUSTERS! 👻 + +# Critical variables from config +config_source: "{project-root}/_bmad/bmm/config.yaml" +output_folder: "{config_source}:output_folder" +sprint_artifacts: "{output_folder}/sprint-artifacts" +sprint_status: "{output_folder}/sprint-status.yaml" + +# Input parameters +epic_number: "{epic_number}" # Optional: Limit to specific epic (e.g., "2") +scan_scope: "sprint" # "sprint" | "epic" | "codebase" +create_backfill_stories: true # Propose backfill stories for orphans + +# Detection settings +detection: + scan_for: + components: true # React/Vue/Angular components + api_endpoints: true # Routes, controllers, handlers + database_tables: true # Migrations, schema + services: true # Services, modules, utilities + models: true # Data models, entities + ui_pages: true # Pages, screens, views + + ignore_patterns: + - "**/node_modules/**" + - "**/dist/**" + - "**/build/**" + - "**/*.test.*" + - "**/*.spec.*" + - "**/migrations/**" # Migrations are referenced collectively, not per-story + + # What counts as "documented"? + documented_if: + mentioned_in_file_list: true # Story File List mentions it + mentioned_in_tasks: true # Task description mentions it + mentioned_in_acs: true # AC mentions the feature + file_committed_in_story_commit: true # Git history shows it in story commit + +# Backfill story settings +backfill: + auto_create: false # Require confirmation before creating each + add_to_sprint_status: true # Add to sprint as "backlog" + mark_as_backfill: true # Add note: "Backfill story documenting existing code" + run_gap_analysis: false # Don't run gap (we know it exists) + estimate_effort: true # Estimate how complex the feature is + +# Output settings +output: + create_report: true # Generate orphaned-features-report.md + group_by_category: true # Group by component/api/db/etc + suggest_epic_assignment: true # Suggest which epic orphans belong to + +standalone: true