BMAD-METHOD/.patch/784/IMPLEMENTATION-PLAN.md

12 KiB

PR #784 Implementation Plan

Agent Handoff Workflows for Context Preservation

Status: Implementation Plan (Setup Phase)
Branch: feature/add-bmad-handoff-workflows-784
PR Number: 784
Author: Sallvainian
Date: 2025-10-21


Executive Summary

PR #784 adds a comprehensive Agent Handoff System to BMAD Core, enabling seamless context preservation between AI agent sessions through two production-ready workflows:

  1. /handoff - Create and save comprehensive context to Serena
  2. /handoff-receive - Load and display actionable handoff summary

Files Added: 11
Total Lines: 2,179
Dependencies: Serena MCP
Status: Ready for integration


Feature Overview

Problem Statement

Complex BMAD workflows spanning multiple agent sessions lose context between sessions:

  • Next agent doesn't know what was just completed
  • Key files and context not readily available
  • Success criteria unclear
  • Manual context reconstruction wastes time

Solution

Two production-ready workflows that work together to preserve and restore complete context with intelligent handoff selection, timestamped collision-proof naming, and comprehensive error handling.


Architecture

Workflow 1: /handoff (Create Handoff)

Purpose: Create comprehensive handoff memory and save to Serena

Flow:

  1. Validate workflow status file exists and has required fields
  2. Read workflow status and extract metadata (PROJECT_NAME, CURRENT_PHASE, NEXT_AGENT, NEXT_COMMAND)
  3. Extract completed work from status file or infer from context
  4. Activate Serena project
  5. Validate required fields present
  6. Generate structured handoff document with:
    • Work just completed
    • Current project state
    • Task for next agent
    • Key context (3-5 critical items)
    • Files to review (categorized)
    • Success criteria
    • Next steps
  7. Save to Serena with timestamped collision-proof name: [agent]-handoff-YYYY-MM-DD-HHmmss
  8. Output ready-to-use prompt for next session

Key Features:

  • Comprehensive metadata extraction
  • Intelligent context capture
  • Serena MCP integration
  • Collision-proof naming (timestamp precision to seconds)
  • Error recovery with user guidance

Workflow 2: /handoff-receive (Load Handoff)

Purpose: Load and display actionable handoff summary

Flow:

  1. Activate Serena project
  2. List all available handoff memories
  3. Apply intelligent selection algorithm:
    • Sort by timestamp (newest first)
    • Support both new (YYYY-MM-DD-HHmmss) and legacy (YYYY-MM-DD) formats
    • Match agent names with current phase when possible
    • Present numbered menu for manual selection if ambiguous
  4. Read selected handoff memory
  5. Validate handoff structure (required sections present)
  6. Display clean, actionable summary focusing on immediate next steps
  7. Offer interactive menu for next actions

Key Features:

  • Intelligent handoff selection (newest-first with agent matching)
  • Backward compatible with legacy format
  • Structure validation
  • Clean, scannable display format
  • Interactive menu for next steps

Timestamp Format & Naming Convention

New Format (Preferred - Collision-Proof)

Pattern: [agent]-handoff-YYYY-MM-DD-HHmmss

Examples:

  • dev-handoff-2025-10-20-150000 (3:00 PM)
  • architect-handoff-2025-10-19-161530 (4:15:30 PM)
  • sm-handoff-2025-10-20-091245 (9:12:45 AM)

Benefits:

  • Prevents collisions with multiple handoffs per day
  • Chronological sorting capability
  • Precise, deterministic naming

Legacy Format (Backward Compatible)

Pattern: [agent]-handoff-YYYY-MM-DD

Example: dev-handoff-2025-10-19

Handling: Time treated as 00:00:00 in selection algorithm


File Structure

Files to Be Created (11 Total)

bmad/core/workflows/
├── handoff/
│   ├── workflow.yaml          (39 lines) - Configuration
│   ├── instructions.md        (312 lines) - Step-by-step guide
│   └── README.md             (214 lines) - Usage documentation
├── handoff-receive/
│   ├── workflow.yaml          (47 lines) - Configuration
│   ├── instructions.md        (231 lines) - Step-by-step guide
│   └── README.md             (330 lines) - Usage documentation
└── HANDOFF_SYSTEM_PR_SUMMARY.md (558 lines) - PR summary document

.claude/commands/bmad/core/workflows/
├── handoff.md                (225 lines) - Standalone command
└── handoff-receive.md        (216 lines) - Standalone command

bmad/_cfg/
└── workflow-manifest.csv (2 line additions) - Register workflows

.gitignore (5 line additions) - Allow .claude/commands/ distribution

File Statistics

Component Files Lines Purpose
Handoff workflow 3 565 Create/save handoff context
Handoff-receive workflow 3 608 Load/display handoff
Command files 2 441 Standalone slash commands
Configuration 1 2 Workflow registration
Git config 1 5 Allow .claude/commands distribution
Summary 1 558 PR documentation
TOTAL 11 2,179 Complete handoff system

Integration Points

BMAD Ecosystem

  • Complements /workflow-status command (state tracking)
  • Uses standard BMAD config variables
  • Follows BMAD workflow conventions
  • Integrates with docs/bmm-workflow-status.md

Serena MCP Integration

Required tools:

  • mcp__serena__activate_project - Project activation
  • mcp__serena__write_memory - Save handoff
  • mcp__serena__list_memories - Find handoffs
  • mcp__serena__read_memory - Load handoff

Dependencies

Required:

  • BMAD v6.0.0-alpha.0+
  • Serena MCP for memory persistence
  • Workflow status file: {output_folder}/bmm-workflow-status.md

Optional:

  • BMAD /workflow-status command (enhanced integration)

Implementation Checklist

Phase 1: File Creation ✓ (GitHub Retrieved)

  • All 11 files retrieved from PR #784
  • Files analyzed and understood
  • Architecture documented

Phase 2: Local Setup (Starting)

  • Create workflow directories structure
  • Create all workflow YAML files
  • Create all instruction files
  • Create all README files
  • Create command files
  • Update workflow-manifest.csv
  • Update .gitignore

Phase 3: Configuration Validation

  • Verify workflow YAML syntax
  • Verify workflow registration
  • Run npm validate
  • Run npm lint
  • Check for no new errors/warnings

Phase 4: Testing

  • Verify workflow discovery
  • Test Serena integration points
  • Validate backward compatibility
  • Test error handling
  • Verify all 11 files present

Phase 5: Documentation

  • Create TEST-RESULTS.md
  • Generate git diffs
  • Document findings
  • Create summary for .patch/784

Phase 6: Finalization

  • Commit changes
  • Backup to .patch/784
  • Post GitHub comment
  • Mark as complete

BMAD Compliance

Convention Checks

Verified:

  • File paths use {project-root}, {installed_path}, {config_source}
  • Variable names match between YAML and instructions
  • Step numbering sequential
  • YAML syntax valid
  • Standard config variables used
  • XML tags correct (<action>, <check>, <ask>, <example>)
  • Instructions comprehensive
  • Error handling complete
  • Examples included

Quality Metrics

Aspect Status Notes
BMAD Convention Compliance All conventions followed
Production Quality 8/10 rating (comprehensive, tested)
Error Handling Comprehensive with recovery options
Documentation Complete with usage examples
Backward Compatibility Supports legacy format
Serena Integration All MCP methods documented

Testing Strategy

Static Validation

  1. YAML Validation

    • Syntax check
    • Variable reference verification
    • Configuration integrity
  2. Instruction Validation

    • XML tag structure
    • Step progression
    • Variable consistency
    • Error handling completeness
  3. File Structure Validation

    • All files present
    • Correct locations
    • Proper naming

Runtime Validation

  1. Configuration Check

    • npm validate passes
    • npm lint has no new errors
    • Workflow registration successful
  2. Functionality Check

    • Handoff workflow can be invoked
    • Handoff-receive workflow can be invoked
    • Serena integration working
    • Memory naming collision-free
  3. Integration Check

    • Works with /workflow-status
    • Backward compatible with legacy format
    • No regression in existing features

Success Criteria

For Implementation

Must Have:

  • All 11 files retrieved and understood
  • Feature branch created
  • Directory structure created
  • All files copied to workspace
  • workflow-manifest.csv updated
  • .gitignore modified
  • npm validate passes
  • npm lint passes (no new errors)
  • Workflow registration verified

For Production

Quality Gates:

  • All tests passing
  • No regressions detected
  • Documentation complete
  • Error messages clear and actionable
  • Timestamp collision-free
  • Backward compatibility verified
  • Serena integration working
  • Ready for GitHub approval

Known Limitations & Future Enhancements

Current Limitations

  1. Requires Serena MCP - Won't function without it
  2. Workflow status dependency - /handoff needs status file
  3. Single project - Doesn't support cross-project handoffs
  4. Terminal-based - No visual UI

Future Enhancements

  • Handoff versioning and rollback capability
  • Cross-project handoff support
  • Handoff search/filter capabilities
  • Analytics and reporting
  • Handoff templates for common scenarios
  • Web UI for handoff management

References

  • bmad/core/config.yaml - Core configuration
  • bmad/core/tasks/workflow.xml - Workflow execution engine
  • docs/bmm-workflow-status.md - Project status file
  • bmad/_cfg/workflow-manifest.csv - Workflow registry

Previous PRs (Reference)

  • PR #745 - Marketplace Plugin Configuration (similar pattern)
  • PR #777 - 'new' Tool Fix for GitHub Copilot (similar testing pattern)

Documentation

  • BMAD v6 Workflow Guide
  • Serena MCP Documentation
  • Agent Handoff Protocol Documentation

Timeline

Phase Task Est. Time Status
1 File creation setup Done Complete
2 Local file setup 20 min Not started
3 Configuration validation 10 min Not started
4 Testing & verification 20 min Not started
5 Documentation 15 min Not started
6 Finalization & commit 10 min Not started
TOTAL ~75 min In progress

Next Steps

  1. Create feature branch (DONE)
  2. 📋 Set up workflow files locally
  3. 📋 Copy workflow manifest changes
  4. 📋 Update .gitignore
  5. 📋 Create .claude/commands structure
  6. 📋 Run npm validate
  7. 📋 Run npm lint
  8. 📋 Document and commit
  9. 📋 Post GitHub approval comment

Document Status: Ready for Implementation
Last Updated: 2025-10-21
Next Review: After Phase 2 completion