feat: add complexity-based routing and pipeline optimizations (v1.3.0)

Phase 1 & 2 improvements to reduce token waste and improve robustness:

1. Complexity scoring in batch-super-dev (step 2.6)
   - Score stories as micro/standard/complex based on task count + risk keywords
   - Micro (≤3 tasks, low risk): lightweight path
   - Standard: full pipeline
   - Complex (≥16 tasks or high-risk): enhanced validation

2. Lightweight path for micro stories
   - Skip pre-gap analysis (step 2) for micro complexity
   - Skip code review (step 5) for micro complexity
   - Estimated 50-70% token savings on simple stories

3. Smart batching clarification
   - Fixed contradictory instructions in step-03-implement.md
   - Default: one task at a time
   - Exception: batch low-risk patterns (package installs, imports)

4. Gap analysis optimization
   - dev-story skips step 1.5 if recent gap analysis exists (<24h)
   - Added skip_gap_analysis flag for pre-validated stories

5. Early bailout pre-flight check (step 4.5)
   - Bail early if story already complete (all tasks checked)
   - Bail if no tasks found (malformed story)
   - Bail if missing required sections
   - Saves tokens on stories that don't need processing

6. Multi-agent review integration (step 5)
   - For complex stories: recommend /multi-agent-review
   - Provides architecture, security, and performance review
   - Dynamic agent selection based on changed files
This commit is contained in:
Jonah Schulte 2026-01-07 16:20:34 -05:00
parent 7c1051b017
commit e5ede9ec3f
9 changed files with 329 additions and 23 deletions

View File

@ -138,6 +138,28 @@
<critical>🔍 MANDATORY GAP ANALYSIS - Validate draft tasks against actual codebase reality!</critical>
<note>This step ensures tasks reflect current codebase state, preventing duplicate implementations and missed dependencies.</note>
<!-- OPTIMIZATION: Skip if gap analysis was recently performed (NEW v1.3.0) -->
<check if="story file has 'Gap Analysis' section with ✅/❌ markers">
<action>Extract timestamp from Gap Analysis section</action>
<check if="gap analysis timestamp is less than 24 hours old">
<output>⚡ **Gap Analysis Already Complete** ({{gap_analysis_timestamp}})
Story was recently validated against codebase. Skipping re-analysis.
- What Exists: {{existing_summary}}
- What's Missing: {{missing_summary}}
Proceeding to implementation...
</output>
<goto step="2" />
</check>
</check>
<!-- CHECK FOR SKIP FLAG - Used when invoked from batch-super-dev after validation -->
<check if="{{skip_gap_analysis}} == true">
<output>⚡ **Skipping Gap Analysis** (story pre-validated by batch-super-dev)</output>
<goto step="2" />
</check>
<!-- Extract story context for gap analysis -->
<action>Extract story requirements, acceptance criteria, and draft tasks from story file</action>
<action>Identify technical areas mentioned in tasks (files, classes, functions, services, components)</action>

View File

@ -215,6 +215,65 @@ Run `/bmad:bmm:workflows:sprint-status` to see status.
</output>
</step>
<step n="2.6" goal="Score story complexity for pipeline routing (NEW v1.3.0)">
<output>
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📊 SCORING STORY COMPLEXITY
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
</output>
<iterate>For each validated story:</iterate>
<substep n="2.6a" title="Analyze story complexity">
<action>Read story file: {{file_path}}</action>
<action>Count unchecked tasks ([ ]) in Tasks/Subtasks section → task_count</action>
<action>Extract file paths mentioned in tasks → file_count</action>
<action>Scan story title and task descriptions for risk keywords</action>
<action>Calculate complexity score:
- Base score = task_count
- Add 5 for each HIGH risk keyword (auth, security, payment, migration, database, schema)
- Add 2 for each MEDIUM risk keyword (api, integration, external, cache)
- Add 0 for LOW risk keywords (ui, style, config, docs, test)
</action>
<action>Assign complexity level:
- MICRO: task_count ≤ 3 AND complexity_score ≤ 5 AND no HIGH risk keywords
- COMPLEX: task_count ≥ 16 OR complexity_score ≥ 20 OR has HIGH risk keywords
- STANDARD: everything else
</action>
<action>Store complexity_level for story: {{story_key}}.complexity = {level, score, task_count, risk_keywords}</action>
</substep>
<action>Group stories by complexity level</action>
<output>
📊 **Complexity Analysis Complete**
{{#each complexity_groups}}
**{{level}} Stories ({{count}}):**
{{#each stories}}
- {{story_key}}: {{task_count}} tasks, score {{score}}{{#if risk_keywords}}, risk: {{risk_keywords}}{{/if}}
{{/each}}
{{/each}}
---
**Pipeline Routing:**
- 🚀 **MICRO** ({{micro_count}}): Lightweight path - skip gap analysis + code review
- ⚙️ **STANDARD** ({{standard_count}}): Full pipeline with all quality gates
- 🔒 **COMPLEX** ({{complex_count}}): Enhanced validation + consider splitting
{{#if complex_count > 0}}
⚠️ **Warning:** {{complex_count}} complex stories detected. Consider:
- Breaking into smaller stories before processing
- Running these separately with extra attention
{{/if}}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
</output>
</step>
<step n="3" goal="Get user selection">
<ask>
**Select stories to process:**

View File

@ -1,7 +1,7 @@
name: batch-super-dev
description: "Interactive batch selector for super-dev-pipeline - select multiple ready-for-dev stories and process them sequentially with full quality gates. Includes smart story validation and automatic creation/regeneration."
description: "Interactive batch selector for super-dev-pipeline with complexity-based routing. Micro stories get lightweight path, standard stories get full pipeline, complex stories get enhanced validation."
author: "BMad"
version: "1.2.0"
version: "1.3.0"
# Critical variables from config
config_source: "{project-root}/_bmad/bmm/config.yaml"
@ -38,6 +38,29 @@ validation:
require_gap_analysis: true # Current State must have ✅/❌ markers
backup_before_regenerate: true # Create .backup file before regenerating
# Story complexity scoring (NEW in v1.3.0)
# Routes stories to appropriate pipeline based on complexity
complexity:
enabled: true
thresholds:
micro: # Lightweight path: skip gap analysis + code review
max_tasks: 3
max_files: 5
risk_keywords: [] # No high-risk keywords allowed
standard: # Normal path: full pipeline
max_tasks: 15
max_files: 30
risk_keywords: ["api", "service", "component", "feature"]
complex: # Enhanced path: extra validation, consider splitting
min_tasks: 16
risk_keywords: ["auth", "security", "migration", "database", "payment", "encryption"]
# Risk keyword scoring (adds to complexity)
risk_weights:
high: ["auth", "security", "payment", "encryption", "migration", "database", "schema"]
medium: ["api", "integration", "external", "third-party", "cache"]
low: ["ui", "style", "config", "docs", "test"]
# Execution settings
execution:
continue_on_failure: true # Keep processing remaining stories if one fails

View File

@ -138,6 +138,28 @@
<critical>🔍 MANDATORY GAP ANALYSIS - Validate draft tasks against actual codebase reality!</critical>
<note>This step ensures tasks reflect current codebase state, preventing duplicate implementations and missed dependencies.</note>
<!-- OPTIMIZATION: Skip if gap analysis was recently performed (NEW v1.3.0) -->
<check if="story file has 'Gap Analysis' section with ✅/❌ markers">
<action>Extract timestamp from Gap Analysis section</action>
<check if="gap analysis timestamp is less than 24 hours old">
<output>⚡ **Gap Analysis Already Complete** ({{gap_analysis_timestamp}})
Story was recently validated against codebase. Skipping re-analysis.
- What Exists: {{existing_summary}}
- What's Missing: {{missing_summary}}
Proceeding to implementation...
</output>
<goto step="2" />
</check>
</check>
<!-- CHECK FOR SKIP FLAG - Used when invoked from batch-super-dev after validation -->
<check if="{{skip_gap_analysis}} == true">
<output>⚡ **Skipping Gap Analysis** (story pre-validated by batch-super-dev)</output>
<goto step="2" />
</check>
<!-- Extract story context for gap analysis -->
<action>Extract story requirements, acceptance criteria, and draft tasks from story file</action>
<action>Identify technical areas mentioned in tasks (files, classes, functions, services, components)</action>

View File

@ -91,6 +91,52 @@ Count:
- Unchecked tasks: `{unchecked_task_count}`
- Checked tasks: `{checked_task_count}`
### 4.5 Pre-Flight Bailout Check (NEW v1.3.0)
**Check for early bailout conditions before investing more tokens:**
```
If total_task_count == 0:
Display:
⚠️ EARLY BAILOUT: No Tasks Found
Story file exists but has no tasks in Tasks/Subtasks section.
- Story may be incomplete or malformed
- Run create-story or validate-create-story first
HALT - Nothing to implement
If unchecked_task_count == 0:
Display:
✅ EARLY BAILOUT: Story Already Complete
All {checked_task_count} tasks are already marked complete.
- No implementation work required
- Story may need status update to "review" or "done"
{if batch mode: Continue to next story}
{if interactive mode: HALT - Story complete}
If story file missing required sections (Tasks, Acceptance Criteria):
Display:
⚠️ EARLY BAILOUT: Invalid Story Format
Story file is missing required sections:
- Missing: {missing_sections}
Run validate-create-story to fix the story format.
HALT - Cannot proceed with invalid story
```
**If all bailout checks pass:**
```
✅ Pre-flight checks passed
- Story valid: {total_task_count} tasks
- Work remaining: {unchecked_task_count} unchecked
- Ready for implementation
```
### 5. Load Project Context
Read `**/project-context.md`:
@ -101,7 +147,49 @@ Read `**/project-context.md`:
Cache in memory for use across steps.
### 6. Detect Development Mode
### 6. Apply Complexity Routing (NEW v1.2.0)
**Check complexity_level parameter:**
- `micro`: Lightweight path - skip pre-gap analysis (step 2) and code review (step 5)
- `standard`: Full pipeline - all steps
- `complex`: Full pipeline with warnings
**Determine skip_steps based on complexity:**
```
If complexity_level == "micro":
skip_steps = [2, 5]
pipeline_mode = "lightweight"
Display:
🚀 MICRO COMPLEXITY DETECTED
Lightweight path enabled:
- ⏭️ Skipping Pre-Gap Analysis (low risk)
- ⏭️ Skipping Code Review (simple changes)
- Estimated token savings: 50-70%
If complexity_level == "complex":
skip_steps = []
pipeline_mode = "enhanced"
Display:
🔒 COMPLEX STORY DETECTED
Enhanced validation enabled:
- Full pipeline with all quality gates
- Consider splitting if story fails
⚠️ Warning: This story has high-risk elements.
Proceeding with extra attention.
If complexity_level == "standard":
skip_steps = []
pipeline_mode = "standard"
```
Store `skip_steps` and `pipeline_mode` in state file.
### 7. Detect Development Mode
**Check File List section in story:**
@ -140,7 +228,7 @@ done
- `new_count == 0`**brownfield** (all existing files)
- Both > 0 → **hybrid** (mix of new and existing)
### 7. Display Initialization Summary
### 8. Display Initialization Summary
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
@ -150,6 +238,7 @@ done
Story: {story_title}
File: {story_file}
Mode: {mode} (interactive|batch)
Complexity: {complexity_level} → {pipeline_mode} path
Development Type: {greenfield|brownfield|hybrid}
- Existing files: {existing_count}
@ -164,19 +253,23 @@ Tasks:
Pipeline Steps:
1. ✅ Initialize (current)
2. ⏳ Pre-Gap Analysis - Validate tasks
2. {⏭️ SKIP|} Pre-Gap Analysis - Validate tasks {if micro: "(skipped - low risk)"}
3. ⏳ Implement - {TDD|Refactor|Hybrid}
4. ⏳ Post-Validation - Verify completion
5. ⏳ Code Review - Find 3-10 issues
5. {⏭️ SKIP|} Code Review - Find issues {if micro: "(skipped - simple changes)"}
6. ⏳ Complete - Commit + push
7. ⏳ Summary - Audit trail
{if pipeline_mode == "lightweight":
🚀 LIGHTWEIGHT PATH: Steps 2 and 5 will be skipped (50-70% token savings)
}
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠️ ANTI-VIBE-CODING ENFORCEMENT ACTIVE
This workflow uses step-file architecture to ensure:
- ✅ No skipping steps
- ✅ No skipping steps (except complexity-based routing)
- ✅ No optimizing sequences
- ✅ No looking ahead
- ✅ No vibe coding even at 200K tokens
@ -186,7 +279,7 @@ You will follow each step file PRECISELY.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```
### 8. Initialize State File
### 9. Initialize State File
Create state file at `{sprint_artifacts}/super-dev-state-{story_id}.yaml`:
@ -197,9 +290,15 @@ story_file: "{story_file}"
mode: "{mode}"
development_type: "{greenfield|brownfield|hybrid}"
# Complexity routing (NEW v1.2.0)
complexity:
level: "{complexity_level}" # micro | standard | complex
pipeline_mode: "{pipeline_mode}" # lightweight | standard | enhanced
skip_steps: {skip_steps} # e.g., [2, 5] for micro
stepsCompleted: [1]
lastStep: 1
currentStep: 2
currentStep: 2 # Or 3 if step 2 is skipped
status: "in_progress"
started_at: "{timestamp}"
@ -220,24 +319,24 @@ steps:
status: completed
completed_at: "{timestamp}"
step-02-pre-gap-analysis:
status: pending
status: {pending|skipped} # skipped if complexity == micro
step-03-implement:
status: pending
step-04-post-validation:
status: pending
step-05-code-review:
status: pending
status: {pending|skipped} # skipped if complexity == micro
step-06-complete:
status: pending
step-07-summary:
status: pending
```
### 9. Display Menu (Interactive) or Proceed (Batch)
### 10. Display Menu (Interactive) or Proceed (Batch)
**Interactive Mode Menu:**
```
[C] Continue to Pre-Gap Analysis
[C] Continue to {next step name}
[H] Halt pipeline
```
@ -245,8 +344,18 @@ steps:
## CRITICAL STEP COMPLETION
**Determine next step based on complexity routing:**
```
If 2 in skip_steps (micro complexity):
nextStepFile = '{workflow_path}/steps/step-03-implement.md'
Display: "⏭️ Skipping Pre-Gap Analysis (micro complexity) → Proceeding to Implementation"
Else:
nextStepFile = '{workflow_path}/steps/step-02-pre-gap-analysis.md'
```
**ONLY WHEN** initialization is complete,
load and execute `{nextStepFile}` for pre-gap analysis.
load and execute `{nextStepFile}`.
---

View File

@ -32,11 +32,12 @@ Implement all unchecked tasks using appropriate methodology:
### Implementation Principles
- **ONE TASK AT A TIME** - Never batch multiple tasks
- **RUN TESTS FREQUENTLY** - After each significant change
- **DEFAULT: ONE TASK AT A TIME** - Execute tasks individually unless smart batching applies
- **SMART BATCHING EXCEPTION** - Low-risk patterns (package installs, imports) may batch
- **RUN TESTS FREQUENTLY** - After each task or batch completion
- **FOLLOW PROJECT PATTERNS** - Never invent new patterns
- **NO VIBE CODING** - Follow the sequence exactly
- **VERIFY EACH TASK** - Check works before moving to next
- **VERIFY BEFORE PROCEEDING** - Confirm success before next task/batch
### Adaptive Methodology

View File

@ -338,12 +338,14 @@ All work verified. Proceeding to Code Review...
**Interactive Mode Menu (only if no false positives):**
```
[C] Continue to Code Review
[C] Continue to {next step based on complexity: Code Review | Complete}
[V] Run verification again
[T] Run tests again
[H] Halt pipeline
```
{if micro complexity: "⏭️ Code Review will be skipped (lightweight path)"}
**Batch Mode:**
- Auto re-run implementation if false positives
- Auto-continue if all verified
@ -380,13 +382,24 @@ read("{file_path}")
## CRITICAL STEP COMPLETION
**ONLY WHEN** [all tasks verified AND zero false positives],
load and execute `{nextStepFile}` for code review.
**IF** [false positives detected],
load and execute `{prevStepFile}` to complete missing work,
then RE-RUN this step.
**ONLY WHEN** [all tasks verified AND zero false positives]:
**Determine next step based on complexity routing:**
```
If 5 in skip_steps (micro complexity):
nextStepFile = '{workflow_path}/steps/step-06-complete.md'
Display: "⏭️ Skipping Code Review (micro complexity) → Proceeding to Complete"
Else:
nextStepFile = '{workflow_path}/steps/step-05-code-review.md'
```
Load and execute `{nextStepFile}`.
---
## SUCCESS/FAILURE METRICS

View File

@ -36,6 +36,45 @@ Perform adversarial code review:
5. Fix all issues
6. Verify tests still pass
### Multi-Agent Review Enhancement (NEW v1.3.0)
**Check complexity level from state file:**
```
If complexity_level == "complex":
Display:
🔒 COMPLEX STORY - Enhanced Review Recommended
This story involves high-risk changes. Consider using:
/multi-agent-review for multi-perspective code review
Multi-agent review provides:
- Architecture review by architect-reviewer agent
- Security audit by auditor-security agent
- Performance analysis by optimizer-performance agent
- Dynamic agent selection based on changed files
[M] Use multi-agent review (recommended for complex)
[S] Use standard adversarial review
[B] Use both (most thorough)
If complexity_level == "standard" AND mode == "interactive":
Display:
⚙️ STANDARD STORY - Review Options
[S] Standard adversarial review (default)
[M] Multi-agent review (optional enhancement)
```
**If multi-agent review selected:**
- Invoke `/multi-agent-review` slash command
- Capture review findings
- Merge with standard review categories
- Continue with issue fixing
**If standard review selected:**
- Continue with adversarial review below
## MANDATORY EXECUTION RULES
### Adversarial Requirements

View File

@ -1,7 +1,7 @@
name: super-dev-pipeline
description: "Step-file architecture with smart batching - works for both greenfield and brownfield development with disciplined execution and intelligent task grouping"
description: "Step-file architecture with complexity-based routing and smart batching. Micro stories get lightweight path, standard/complex get full quality gates."
author: "BMad"
version: "1.1.0" # Added smart batching feature
version: "1.2.0" # Added complexity-based routing
# Critical variables from config
config_source: "{project-root}/_bmad/bmm/config.yaml"
@ -20,6 +20,24 @@ checklists_path: "{installed_path}/checklists"
state_file: "{sprint_artifacts}/super-dev-state-{{story_id}}.yaml"
audit_trail: "{sprint_artifacts}/audit-super-dev-{{story_id}}-{{date}}.yaml"
# Complexity level (passed from batch-super-dev or set manually)
# Controls which pipeline steps to execute
complexity_level: "standard" # micro | standard | complex
# Complexity-based step skipping (NEW v1.2.0)
complexity_routing:
micro:
skip_steps: [2, 5] # Skip pre-gap analysis and code review
description: "Lightweight path for simple stories (≤3 tasks, low risk)"
standard:
skip_steps: [] # Full pipeline
description: "Normal path with all quality gates"
complex:
skip_steps: [] # Full pipeline + warnings
description: "Enhanced path for high-risk stories"
warn_before_start: true
suggest_split: true
# Workflow modes
modes:
interactive: