# PMAT Implementation Roadmap
# Extreme TDD with Zero Tolerance Quality Gates

meta:
  project: PMAT - Pragmatic AI Labs Multi-language Agent Toolkit
  approach: Extreme Test-Driven Development
  quality_gates:
    max_complexity: 10
    max_cognitive: 7
    min_coverage: 0.95
    min_mutation_score: 0.90
    satd_tolerance: 0
  execution:
    ticket_workflow: RED-GREEN-REFACTOR
    commit_strategy: atomic_per_ticket
    build_verification: mandatory_clean

# COMPLETED SPRINTS (v2.167.0 - v2.180.1)
completed_sprints:
  - id: sprint-66
    name: "TDG Enforcement System"
    status: "✅ COMPLETE"
    version: "v2.180.0"
    date: "October 29, 2025"
    deliverables:
      - "TDG baseline tracking with Blake3 content-hash"
      - "Quality gates (RegressionGate, MinimumGradeGate, NewFileGate)"
      - "Git hook integration (pre-commit, post-commit)"
      - "CI/CD templates (GitHub Actions, GitLab CI, Jenkins)"
      - "3,129 lines of production code"
      - "1,886 lines of tests (64 RED tests)"
      - "3,339 lines of documentation"

  - id: sprint-67
    name: "TDG Dogfooding"
    status: "✅ COMPLETE"
    version: "v2.180.1"
    date: "October 29, 2025"
    deliverables:
      - "Dogfooded TDG enforcement on PMAT codebase"
      - "851 files analyzed, 93.0 avg score (A grade)"
      - "Critical bugfix: hardcoded sled backend → libsql"
      - "< 4 hour turnaround from bug discovery to hotfix"
      - "Validated TDG system works at scale"

  - id: sprint-69
    name: "pmat-book TDG Chapter & Integration Reports"
    status: "✅ COMPLETE"
    date: "October 29, 2025"
    deliverables:
      - "Chapter 4.2: TDG Enforcement System (824 lines)"
      - "Published to https://paiml.github.io/pmat-book/"
      - "TDG integration reports: ruchy, bashrs, ruchyruchy (1,159 lines)"
      - "GitHub issues filed for all 3 PAIML projects"
      - "Mutation testing enhancement specification (952 lines)"

  - id: sprint-71
    name: "Known Defects v2.1: Zero Tolerance Production Defects"
    status: "✅ COMPLETE"
    version: "v2.199.0"
    date: "November 21, 2025"
    deliverables:
      - "TDG Auto-Fail: Files with critical defects get Score: 0.0, Grade: F"
      - "pmat analyze defects: Multi-format CLI (text/json/junit)"
      - "RustDefectDetector: RUST-UNWRAP-001 pattern with Cloudflare evidence"
      - "Test code exclusion: tests/, benches/, #[cfg(test)]"
      - "Exit code semantics: 1 for critical defects (CI/CD integration)"
      - "pmat-book updates: Chapter 4.1 (TDG), Chapter 5 (Analyze Suite)"
      - "Cross-references: TDG ↔ analyze defects ↔ rust-project-score"
    evidence:
      - "Cloudflare outage 2025-11-18 (3+ hours global disruption from .unwrap())"
      - "server/src/services/defect_detector.rs (207 lines)"
      - "server/src/cli/handlers/analyze_defects_handler.rs (261 lines)"
      - "TdgScore fields: critical_defects_count, has_critical_defects"
    testing:
      - "All library tests passing (4841 tests)"
      - "Test path exclusion verified (tests/integration_test.rs)"
      - "TdgScore struct fields added to all test initializations"

# ACTIVE SPRINTS
sprints:
  # SPRINT 70: cargo-mutants Wrapper (CURRENT)
  - id: sprint-70
    name: "cargo-mutants Wrapper"
    goal: "Replace defective generic mutation operators with cargo-mutants wrapper"
    status: "🚀 STARTING"
    priority: "HIGH (fix 0% effectiveness defect)"
    duration: "1-2 weeks"
    target_version: "v2.181.0 or v2.182.0"

    problem:
      description: "PMAT mutation testing has 0% kill rate due to generic operators"
      evidence:
        - "178 mutants generated across bashrs codebase"
        - "0 mutants killed by tests (100% survival rate)"
        - "Generic operators (AOR, ROR, COR, UOR) produce invalid/irrelevant mutations"
        - "cargo-mutants has proven ≥90% kill rate"

    solution:
      approach: "Wrap cargo-mutants (subprocess wrapper) instead of re-implementing"
      benefits:
        - "Achieve ≥90% kill rate (match cargo-mutants effectiveness)"
        - "Zero maintenance burden (community maintains cargo-mutants)"
        - "Maintain PMAT interface (seamless user experience)"
        - "1-2 weeks vs 3-4 weeks for re-implementation"

    implementation_phases:
      week_1:
        name: "Core Wrapper"
        days: "Days 1-5"
        tasks:
          day_1_2:
            goal: "Infrastructure"
            deliverables:
              - "Create server/src/mutation/cargo_mutants_wrapper.rs"
              - "Add which dependency to Cargo.toml"
              - "Implement CargoMutantsWrapper::new()"
              - "Handle cargo-mutants not installed gracefully"
            success_criteria:
              - "Can detect cargo-mutants in PATH"
              - "Can execute cargo-mutants --version"
              - "Graceful error if not installed"
              - "Unit tests passing"

          day_3_4:
            goal: "JSON Parsing"
            deliverables:
              - "Define CargoMutantsReport struct"
              - "Implement JSON parsing with serde"
              - "Implement to_pmat_report() conversion"
              - "Handle edge cases (no mutants, timeouts, unviable)"
            success_criteria:
              - "Can parse all cargo-mutants JSON formats"
              - "Handles all mutant outcomes (killed, survived, timeout, unviable)"
              - "Converts to PMAT MutationReport correctly"
              - "Edge case handling tested"

          day_5:
            goal: "CLI Integration"
            deliverables:
              - "Update handle_mutate_command() to use wrapper"
              - "Pass through cargo-mutants arguments"
              - "Add --cargo-mutants-args for advanced users"
              - "Display PMAT-formatted output"
            success_criteria:
              - "pmat mutate calls cargo-mutants successfully"
              - "Arguments passed through correctly"
              - "PMAT-formatted output displayed"
              - "Help text updated"

      week_2:
        name: "Testing & Release"
        days: "Days 6-10"
        tasks:
          day_6_7:
            goal: "Comprehensive Testing"
            deliverables:
              - "Unit tests for JSON parsing (all edge cases)"
              - "Integration tests with cargo-mutants"
              - "Error handling tests"
              - "Dogfood on PMAT codebase (target: ≥90% kill rate)"
            success_criteria:
              - "All unit tests passing"
              - "Integration tests working"
              - "≥90% kill rate on PMAT modules"
              - "Results match raw cargo-mutants"

          day_8:
            goal: "Documentation"
            deliverables:
              - "Update docs/guides/mutation-testing.md"
              - "Document cargo-mutants requirement"
              - "Add installation instructions"
              - "Create migration guide"
            success_criteria:
              - "Complete installation guide"
              - "Usage examples with expected output"
              - "Troubleshooting section"
              - "Migration guide from v2.180.1"

          day_9:
            goal: "Validation"
            deliverables:
              - "Run on multiple PMAT modules"
              - "Verify ≥90% kill rate achieved"
              - "Performance benchmarks"
              - "Compare vs generic operators (0% → ≥90%)"
            success_criteria:
              - "≥90% kill rate on PMAT codebase"
              - "Performance acceptable (~30s/mutant)"
              - "All quality gates passing"
              - "pmat-book validation passing"

          day_10:
            goal: "Release Preparation"
            deliverables:
              - "Update CHANGELOG"
              - "Version bump: v2.181.0 or v2.182.0"
              - "Create GitHub release"
              - "Update crates.io"
            success_criteria:
              - "Version bumped correctly"
              - "CHANGELOG complete"
              - "GitHub release published"
              - "crates.io updated"

    success_criteria:
      functional:
        - "cargo-mutants wrapper working"
        - "≥90% kill rate on PMAT codebase (vs 0% with generic operators)"
        - "JSON parsing handles all cargo-mutants output"
        - "PMAT CLI interface maintained"

      quality:
        - "All modules: Cyclomatic complexity <10"
        - "All modules: TDG score ≥90 (A grade)"
        - "All tests passing (unit, integration, dogfooding)"
        - "Zero security issues"

      performance:
        - "30-60s per mutant (match cargo-mutants)"
        - "No significant overhead from wrapper"
        - "Memory usage reasonable"

      documentation:
        - "Installation guide complete"
        - "Migration guide from generic operators"
        - "Troubleshooting section"
        - "pmat-book validation passing"

    files_to_create:
      - path: "server/src/mutation/cargo_mutants_wrapper.rs"
        lines: "~300"
      - path: "server/tests/mutation/cargo_mutants_integration.rs"
        lines: "~200"
      - path: "docs/guides/mutation-testing-cargo-mutants.md"
        lines: "~400"

    files_to_modify:
      - path: "server/src/mutation/mod.rs"
        change: "export wrapper"
      - path: "server/src/cli/handlers/mutate.rs"
        change: "use wrapper"
      - path: "Cargo.toml"
        change: "add which dependency"
      - path: "docs/guides/mutation-testing.md"
        change: "update for wrapper"
      - path: "README.md"
        change: "mention cargo-mutants requirement"
      - path: "CHANGELOG.md"
        change: "document changes"

    dependencies:
      cargo:
        - name: "which"
          version: "6.0"
          purpose: "Find cargo-mutants in PATH"

      external_tools:
        - name: "cargo-mutants"
          version: "v24.7.0+"
          installation: "cargo install cargo-mutants"
          purpose: "Language-specific Rust mutation testing"

  # FUTURE SPRINTS (Agent System Architecture)
  # SPRINT 1: Modular Monolith Foundation (Week 1-2)
  # SPRINT 1: Modular Monolith Foundation (Week 1-2)
  - id: sprint-1
    name: "Modular Monolith Foundation"
    goal: "Extract modules with compiler-enforced boundaries"
    duration: 2_weeks
    tickets:
      - id: PMAT-001
        title: "Setup quality gate infrastructure"
        priority: critical
        requirements:
          - "Quality gate runner with AST analysis"
          - "Complexity analyzer (McCabe/Cognitive)"
          - "SATD detector with zero tolerance"
          - "Pre-commit hook integration"
        tests:
          - "test_quality_gate_detects_complexity_violations"
          - "test_satd_zero_tolerance_enforcement"
          - "test_pre_commit_blocks_violations"
          - "proptest_complexity_calculation_correctness"
        acceptance:
          - "100% test coverage"
          - "All quality metrics < thresholds"
          - "Clean cargo build --release"

      - id: PMAT-002
        title: "Create module abstraction layer"
        priority: high
        requirements:
          - "Trait-based module interfaces"
          - "Dependency injection framework"
          - "Module registry with lifecycle management"
        tests:
          - "test_module_trait_implementation"
          - "test_dependency_injection_resolution"
          - "test_module_lifecycle_events"
          - "proptest_module_registry_consistency"
        acceptance:
          - "Zero circular dependencies"
          - "All modules behind traits"
          - "Benchmark: module lookup O(1)"

      - id: PMAT-003
        title: "Extract analyzer module"
        priority: high
        requirements:
          - "AnalyzerModule trait definition"
          - "Language-agnostic analysis interface"
          - "Metrics collection abstraction"
        tests:
          - "test_analyzer_trait_contract"
          - "test_rust_analyzer_implementation"
          - "test_metrics_aggregation"
          - "proptest_analysis_determinism"
        acceptance:
          - "Module compiles independently"
          - "All tests passing"
          - "Performance: <100ms per file"

      - id: PMAT-004
        title: "Extract transformer module"
        priority: high
        requirements:
          - "TransformerModule trait"
          - "AST manipulation abstraction"
          - "Transactional refactoring support"
        tests:
          - "test_transformer_trait_contract"
          - "test_refactoring_transactions"
          - "test_rollback_capability"
          - "proptest_transform_reversibility"
        acceptance:
          - "All transforms reversible"
          - "Zero AST corruption"
          - "Mutation testing score >90%"

      - id: PMAT-005
        title: "Architecture enforcement tests"
        priority: critical
        requirements:
          - "Dependency rule tests"
          - "Layer boundary tests"
          - "Acyclic dependency verification"
        tests:
          - "test_no_circular_dependencies"
          - "test_module_boundary_violations"
          - "test_layer_access_restrictions"
          - "proptest_dependency_graph_properties"
        acceptance:
          - "All architecture tests green"
          - "CI/CD integration complete"
          - "Documentation generated"

  # SPRINT 2: Quality Gates Engine (Week 3-4)
  - id: sprint-2
    name: "Quality Gates Engine"
    goal: "Implement zero-tolerance quality enforcement"
    duration: 2_weeks
    tickets:
      - id: PMAT-006
        title: "Implement complexity analyzer"
        priority: critical
        requirements:
          - "McCabe cyclomatic complexity"
          - "Cognitive complexity (Sonar)"
          - "Nesting depth analysis"
          - "Control flow graph generation"
        tests:
          - "test_mccabe_complexity_calculation"
          - "test_cognitive_complexity_rules"
          - "test_cfg_construction"
          - "proptest_complexity_monotonicity"
        acceptance:
          - "Matches SonarQube results ±5%"
          - "Performance: O(n) analysis"
          - "100% branch coverage"

      - id: PMAT-007
        title: "Build SATD detector"
        priority: critical
        requirements:
          - "Pattern-based SATD detection"
          - "Multi-language support"
          - "Configurable forbidden patterns"
        tests:
          - "test_satd_pattern_detection"
          - "test_multi_language_satd"
          - "test_custom_pattern_config"
          - "proptest_satd_detection_consistency"
        acceptance:
          - "Zero false negatives"
          - "Configurable patterns"
          - "Sub-second file scanning"

      - id: PMAT-008
        title: "Efficiency analyzer"
        priority: high
        requirements:
          - "Big-O complexity detection"
          - "Space complexity analysis"
          - "Symbolic execution engine"
        tests:
          - "test_loop_complexity_detection"
          - "test_recursive_complexity"
          - "test_space_complexity_bounds"
          - "proptest_complexity_bounds_correct"
        acceptance:
          - "Detects O(n²) and higher"
          - "Handles recursion correctly"
          - "Property tests passing"

      - id: PMAT-009
        title: "Shannon entropy calculator"
        priority: medium
        requirements:
          - "Code diversity metrics"
          - "Duplication detection"
          - "Entropy threshold enforcement"
        tests:
          - "test_shannon_entropy_calculation"
          - "test_duplication_detection"
          - "test_entropy_thresholds"
          - "proptest_entropy_properties"
        acceptance:
          - "Entropy calculation accurate"
          - "Duplication <2% enforced"
          - "Integration with quality gate"

      - id: PMAT-010
        title: "Git hook integration"
        priority: critical
        requirements:
          - "Pre-commit quality checks"
          - "Staged file analysis"
          - "Incremental checking"
        tests:
          - "test_pre_commit_hook_blocks_violations"
          - "test_staged_files_analysis"
          - "test_incremental_check_performance"
          - "integration_test_git_workflow"
        acceptance:
          - "Hooks installed automatically"
          - "Sub-second for small commits"
          - "Clear violation reporting"

  # SPRINT 3: In-Process Actor System (Week 5-6)
  - id: sprint-3
    name: "In-Process Actor System"
    goal: "Implement Actix-based agent architecture"
    duration: 2_weeks
    tickets:
      - id: PMAT-011
        title: "Setup Actix actor system"
        priority: critical
        requirements:
          - "Actix integration"
          - "Actor supervision tree"
          - "Message routing infrastructure"
        tests:
          - "test_actor_spawn_and_lifecycle"
          - "test_supervision_restart_strategy"
          - "test_message_routing"
          - "proptest_actor_message_ordering"
        acceptance:
          - "Actors spawn <50ms P99"
          - "Supervision tree stable"
          - "10K msg/s throughput"

      - id: PMAT-012
        title: "Implement AnalyzerActor"
        priority: high
        requirements:
          - "Async complexity analysis"
          - "Result caching"
          - "Bounded mailbox"
        tests:
          - "test_analyzer_actor_messages"
          - "test_cache_hit_performance"
          - "test_mailbox_backpressure"
          - "proptest_analysis_determinism"
        acceptance:
          - "Cache hit ratio >80%"
          - "No mailbox overflow"
          - "Concurrent analysis works"

      - id: PMAT-013
        title: "Implement TransformerActor"
        priority: high
        requirements:
          - "AST transformation actor"
          - "Transaction support"
          - "Rollback capability"
        tests:
          - "test_transformer_actor_operations"
          - "test_transaction_atomicity"
          - "test_rollback_correctness"
          - "proptest_transform_idempotence"
        acceptance:
          - "All transforms atomic"
          - "Rollback 100% reliable"
          - "No AST corruption"

      - id: PMAT-014
        title: "Implement ValidatorActor"
        priority: high
        requirements:
          - "Quality validation actor"
          - "Threshold checking"
          - "Parallel validation"
        tests:
          - "test_validator_actor_rules"
          - "test_threshold_enforcement"
          - "test_parallel_validation"
          - "proptest_validation_consistency"
        acceptance:
          - "All rules enforced"
          - "Parallel speedup >3x"
          - "Zero false negatives"

      - id: PMAT-015
        title: "Actor orchestration supervisor"
        priority: critical
        requirements:
          - "QualityGateSupervisor actor"
          - "Workflow coordination"
          - "Error aggregation"
        tests:
          - "test_supervisor_coordination"
          - "test_workflow_execution"
          - "test_error_handling"
          - "proptest_workflow_determinism"
        acceptance:
          - "Workflows complete reliably"
          - "Errors properly aggregated"
          - "Supervisor auto-restarts"

  # SPRINT 4: Agent Message Protocol (Week 7-8)
  - id: sprint-4
    name: "Agent Message Protocol"
    goal: "Implement inter-agent communication"
    duration: 2_weeks
    tickets:
      - id: PMAT-016
        title: "Define message format"
        priority: critical
        requirements:
          - "Zero-copy message structure"
          - "Header with metadata"
          - "Priority queue support"
        tests:
          - "test_message_serialization"
          - "test_zero_copy_performance"
          - "test_priority_ordering"
          - "proptest_message_round_trip"
        acceptance:
          - "Serialization <1ms"
          - "Zero allocations in hot path"
          - "Priority queue working"

      - id: PMAT-017
        title: "Request-response pattern"
        priority: high
        requirements:
          - "Correlation ID tracking"
          - "Timeout handling"
          - "Response routing"
        tests:
          - "test_request_response_flow"
          - "test_timeout_behavior"
          - "test_correlation_tracking"
          - "proptest_response_matching"
        acceptance:
          - "100% response matching"
          - "Timeouts enforced"
          - "No message loss"

      - id: PMAT-018
        title: "Publish-subscribe broker"
        priority: high
        requirements:
          - "Topic-based routing"
          - "Parallel broadcast"
          - "Subscription management"
        tests:
          - "test_pubsub_broadcast"
          - "test_topic_filtering"
          - "test_subscription_lifecycle"
          - "proptest_broadcast_delivery"
        acceptance:
          - "Broadcast <5ms for 100 subs"
          - "No message duplication"
          - "Dynamic subscriptions work"

      - id: PMAT-019
        title: "Circuit breaker pattern"
        priority: critical
        requirements:
          - "Failure detection"
          - "State transitions"
          - "Fallback handling"
        tests:
          - "test_circuit_breaker_states"
          - "test_failure_threshold"
          - "test_fallback_execution"
          - "proptest_breaker_consistency"
        acceptance:
          - "Breaker opens on threshold"
          - "Fallback always available"
          - "Recovery works correctly"

      - id: PMAT-020
        title: "Backpressure control"
        priority: high
        requirements:
          - "Token bucket rate limiting"
          - "Flow control mechanisms"
          - "Queue depth monitoring"
        tests:
          - "test_rate_limiting"
          - "test_backpressure_application"
          - "test_queue_monitoring"
          - "proptest_rate_limit_bounds"
        acceptance:
          - "Rate limits enforced ±5%"
          - "No queue overflow"
          - "Graceful degradation"

  # SPRINT 5: State Management (Week 9-10)
  - id: sprint-5
    name: "State Management"
    goal: "Hybrid event sourcing with snapshots"
    duration: 2_weeks
    tickets:
      - id: PMAT-021
        title: "Event store implementation"
        priority: critical
        requirements:
          - "Append-only event log"
          - "Event ordering guarantees"
          - "Persistence layer"
        tests:
          - "test_event_append_ordering"
          - "test_persistence_durability"
          - "test_concurrent_writes"
          - "proptest_event_log_consistency"
        acceptance:
          - "Events never lost"
          - "Ordering preserved"
          - "10K events/sec write"

      - id: PMAT-022
        title: "Snapshot store"
        priority: critical
        requirements:
          - "Zero-copy serialization"
          - "Compression (zstd)"
          - "Atomic writes"
        tests:
          - "test_snapshot_creation"
          - "test_compression_ratio"
          - "test_atomic_writes"
          - "proptest_snapshot_recovery"
        acceptance:
          - "Compression ratio >3:1"
          - "Snapshot <100ms for 10MB"
          - "100% recovery success"

      - id: PMAT-023
        title: "Adaptive snapshot scheduler"
        priority: high
        requirements:
          - "Multiple strategies"
          - "Recovery time targeting"
          - "Performance metrics"
        tests:
          - "test_snapshot_strategies"
          - "test_adaptive_scheduling"
          - "test_recovery_time_bounds"
          - "proptest_scheduler_decisions"
        acceptance:
          - "Recovery <1s target met"
          - "Adaptive strategy works"
          - "Metrics collected accurately"

      - id: PMAT-024
        title: "State recovery system"
        priority: critical
        requirements:
          - "Fast recovery from snapshots"
          - "Event replay engine"
          - "Parallel replay support"
        tests:
          - "test_recovery_from_snapshot"
          - "test_event_replay"
          - "test_parallel_replay"
          - "proptest_recovery_correctness"
        acceptance:
          - "Recovery <1s for 100K events"
          - "State matches exactly"
          - "Parallel speedup >3x"

      - id: PMAT-025
        title: "Raft consensus for critical state"
        priority: high
        requirements:
          - "Raft implementation"
          - "Leader election"
          - "Log replication"
        tests:
          - "test_raft_leader_election"
          - "test_log_replication"
          - "test_split_brain_prevention"
          - "proptest_consensus_properties"
        acceptance:
          - "Consensus in <100ms"
          - "No split brain possible"
          - "Linearizability guaranteed"

  # SPRINT 6: Resource Control (Week 11-12)
  - id: sprint-6
    name: "Resource Control"
    goal: "Cross-platform resource management"
    duration: 2_weeks
    tickets:
      - id: PMAT-026
        title: "Unified resource controller"
        priority: critical
        requirements:
          - "CPU limiting"
          - "Memory control"
          - "I/O throttling"
        tests:
          - "test_cpu_limiting"
          - "test_memory_enforcement"
          - "test_io_throttling"
          - "proptest_resource_bounds"
        acceptance:
          - "Limits enforced ±10%"
          - "Cross-platform support"
          - "No resource leaks"

      - id: PMAT-027
        title: "Platform-specific enforcers"
        priority: high
        requirements:
          - "Linux cgroups v2"
          - "macOS QoS classes"
          - "Windows Job Objects"
        tests:
          - "test_linux_cgroups"
          - "test_macos_qos"
          - "test_windows_jobs"
          - "integration_test_enforcement"
        acceptance:
          - "Each platform working"
          - "Graceful fallbacks"
          - "Resource isolation verified"

      - id: PMAT-028
        title: "Resource monitoring"
        priority: high
        requirements:
          - "Real-time metrics"
          - "Historical tracking"
          - "Alert thresholds"
        tests:
          - "test_metrics_collection"
          - "test_historical_storage"
          - "test_alert_triggering"
          - "proptest_metrics_accuracy"
        acceptance:
          - "Metrics accurate ±5%"
          - "Sub-second updates"
          - "Alerts fire correctly"

      - id: PMAT-029
        title: "Bulkhead isolation"
        priority: critical
        requirements:
          - "Thread pool isolation"
          - "Resource partitioning"
          - "Failure containment"
        tests:
          - "test_thread_pool_isolation"
          - "test_resource_partitions"
          - "test_failure_containment"
          - "chaos_test_cascading_failures"
        acceptance:
          - "No cascade failures"
          - "Pools isolated completely"
          - "Performance maintained"

      - id: PMAT-030
        title: "Adaptive throttling"
        priority: medium
        requirements:
          - "Dynamic throttle calculation"
          - "Sleep injection"
          - "Memory pressure response"
        tests:
          - "test_throttle_calculation"
          - "test_sleep_injection"
          - "test_memory_pressure"
          - "proptest_throttling_fairness"
        acceptance:
          - "Throttling effective"
          - "Fair resource sharing"
          - "System remains responsive"

  # SPRINT 7: MCP Integration (Week 13-14)
  - id: sprint-7
    name: "MCP Integration"
    goal: "Full MCP protocol support"
    duration: 2_weeks
    tickets:
      - id: PMAT-031
        title: "Agent-aware tool registration"
        priority: critical
        requirements:
          - "Extended tool descriptors"
          - "Agent metadata"
          - "Capability declaration"
        tests:
          - "test_tool_registration"
          - "test_agent_metadata"
          - "test_capability_matching"
          - "proptest_tool_discovery"
        acceptance:
          - "All tools registered"
          - "Claude Code compatible"
          - "Discovery working"

      - id: PMAT-032
        title: "MCP server implementation"
        priority: critical
        requirements:
          - "Tool call handling"
          - "Agent routing"
          - "Response formatting"
        tests:
          - "test_mcp_tool_calls"
          - "test_agent_routing"
          - "test_response_format"
          - "integration_test_claude_code"
        acceptance:
          - "MCP compliance 100%"
          - "Claude Code works"
          - "All tools accessible"

      - id: PMAT-033
        title: "Agent discovery protocol"
        priority: high
        requirements:
          - "Agent manifest format"
          - "Capability advertisement"
          - "Health endpoints"
        tests:
          - "test_manifest_format"
          - "test_capability_advertisement"
          - "test_health_checks"
          - "proptest_discovery_consistency"
        acceptance:
          - "Discovery reliable"
          - "Manifests valid"
          - "Health checks accurate"

      - id: PMAT-034
        title: "Service registry"
        priority: high
        requirements:
          - "Static configuration"
          - "Hot reload support"
          - "Optional etcd backend"
        tests:
          - "test_static_config"
          - "test_hot_reload"
          - "test_etcd_integration"
          - "proptest_registry_consistency"
        acceptance:
          - "Config reload works"
          - "No downtime on reload"
          - "etcd optional but working"

      - id: PMAT-035
        title: "Legacy CLI adapter"
        priority: critical
        requirements:
          - "Backward compatibility"
          - "Command routing"
          - "Output formatting"
        tests:
          - "test_legacy_commands"
          - "test_command_routing"
          - "test_output_compatibility"
          - "integration_test_existing_scripts"
        acceptance:
          - "All commands working"
          - "No breaking changes"
          - "Scripts still run"

  # SPRINT 8: Workflow Orchestration (Week 15-16)
  - id: sprint-8
    name: "Workflow Orchestration"
    goal: "DAG-based workflow execution"
    duration: 2_weeks
    tickets:
      - id: PMAT-036
        title: "DAG workflow engine"
        priority: critical
        requirements:
          - "DAG construction"
          - "Topological sorting"
          - "Execution planning"
        tests:
          - "test_dag_construction"
          - "test_topological_sort"
          - "test_execution_plan"
          - "proptest_dag_properties"
        acceptance:
          - "DAGs validated correctly"
          - "Optimal execution order"
          - "Parallelism exploited"

      - id: PMAT-037
        title: "Workflow executor"
        priority: critical
        requirements:
          - "Stage-based execution"
          - "Parallel node execution"
          - "Error aggregation"
        tests:
          - "test_stage_execution"
          - "test_parallel_nodes"
          - "test_error_handling"
          - "proptest_execution_determinism"
        acceptance:
          - "Workflows complete"
          - "Parallelism working"
          - "Errors handled gracefully"

      - id: PMAT-038
        title: "Saga coordinator"
        priority: high
        requirements:
          - "Saga pattern implementation"
          - "Compensation tracking"
          - "Distributed transactions"
        tests:
          - "test_saga_execution"
          - "test_compensation_rollback"
          - "test_transaction_semantics"
          - "proptest_saga_consistency"
        acceptance:
          - "Sagas atomic"
          - "Compensations work"
          - "No partial states"

      - id: PMAT-039
        title: "Event-driven choreography"
        priority: medium
        requirements:
          - "Event bus implementation"
          - "Subscription management"
          - "Event ordering"
        tests:
          - "test_event_bus"
          - "test_subscriptions"
          - "test_event_ordering"
          - "proptest_event_delivery"
        acceptance:
          - "Events delivered once"
          - "Ordering preserved"
          - "No event loss"

      - id: PMAT-040
        title: "Retry and compensation"
        priority: high
        requirements:
          - "Retry policies"
          - "Exponential backoff"
          - "Compensation logic"
        tests:
          - "test_retry_policies"
          - "test_backoff_calculation"
          - "test_compensation_execution"
          - "proptest_retry_bounds"
        acceptance:
          - "Retries bounded"
          - "Backoff working"
          - "Compensations reliable"

validation:
  continuous_integration:
    - cargo build --release
    - cargo test --all-features
    - cargo clippy -- -D warnings
    - cargo fmt -- --check
    - cargo llvm-cov --lcov --output-path coverage/lcov.info
    - cargo mutants --minimum-score 0.90

  quality_gates:
    - pmat analyze complexity --max 10
    - pmat analyze satd --zero-tolerance
    - pmat analyze efficiency --max "O(n log n)"
    - pmat quality-score --min 9.5

  performance_benchmarks:
    - agent_spawn_latency_p99: 50ms
    - message_throughput: 10000/s
    - state_recovery_time: 1s
    - workflow_parallelism: 16x

execution_protocol:
  ticket_workflow:
    - step: write_failing_tests
      description: "Write comprehensive test suite that fails"
      deliverable: "Red tests committed"

    - step: minimal_implementation
      description: "Implement just enough to pass tests"
      deliverable: "Green tests, no extras"

    - step: refactor_with_quality
      description: "Refactor while maintaining green"
      deliverable: "Clean code, all metrics pass"

    - step: atomic_commit
      description: "Single commit per ticket"
      deliverable: "Git log shows ticket complete"

    - step: clean_build
      description: "Verify build passes all checks"
      deliverable: "CI/CD green"

metrics_tracking:
  per_ticket:
    - test_coverage
    - mutation_score
    - complexity_metrics
    - performance_benchmarks
    - quality_score

  per_sprint:
    - velocity
    - defect_rate
    - technical_debt
    - test_suite_runtime
    - build_time

deployment_strategy:
  phases:
    - phase: development
      features:
        agent_system: true
        distributed_state: false
        resource_isolation: true

    - phase: staging
      features:
        agent_system: true
        distributed_state: true
        resource_isolation: true

    - phase: production
      features:
        agent_system: false  # Start conservative
        distributed_state: false
        resource_isolation: true
      rollout:
        strategy: canary
        percentage: 5
        duration: 1_week