day1_simulation.exs
1 #!/usr/bin/env elixir 2 3 # ECHO Day 1 Simulation Script 4 # 5 # This script executes the feature_development workflow to simulate 6 # a realistic Day 1 organizational scenario with all 9 agents. 7 # 8 # Prerequisites: 9 # 1. PostgreSQL running (localhost:5432) 10 # 2. Redis running (localhost:6379) 11 # 3. Database 'echo_org' created with migrations run 12 # 4. All 9 agent escripts built 13 # 14 # Usage: 15 # cd /Users/pranav/Documents/echo/shared 16 # mix run ../scripts/day1_simulation.exs 17 18 defmodule Day1Simulator do 19 def run() do 20 IO.puts """ 21 ================================================================================ 22 ECHO Day 1 Simulation - Mobile App Dashboard Feature 23 ================================================================================ 24 25 Scenario: Product team wants to build a new mobile dashboard feature. 26 This workflow will coordinate all 9 agents to design, approve, and implement 27 the feature following proper organizational hierarchy and decision patterns. 28 29 """ 30 31 # Load the feature development workflow 32 IO.puts "Loading feature_development workflow..." 33 {workflow, _} = Code.eval_file("../workflows/examples/feature_development.exs") 34 35 IO.puts "✓ Workflow loaded: #{workflow.name}" 36 IO.puts " Participants: #{Enum.join(workflow.participants, ", ")}" 37 IO.puts " Total steps: #{length(workflow.steps)}" 38 IO.puts "" 39 40 # Validate workflow 41 case EchoShared.Workflow.Definition.validate(workflow) do 42 {:ok, _} -> 43 IO.puts "✓ Workflow validation passed" 44 {:error, reason} -> 45 IO.puts "✗ Workflow validation failed: #{inspect(reason)}" 46 System.halt(1) 47 end 48 49 # Execute workflow with context 50 IO.puts "\nStarting workflow execution..." 51 context = %{ 52 feature_name: "Mobile App Dashboard", 53 description: "Real-time dashboard for mobile app with charts and analytics", 54 priority: "high", 55 estimated_budget: 150_000, 56 complexity: "high", 57 target_release: "Q1 2025", 58 expected_users: 50_000 59 } 60 61 case EchoShared.Workflow.Engine.execute_workflow(workflow, context) do 62 {:ok, execution_id} -> 63 IO.puts "✓ Workflow started: #{execution_id}" 64 IO.puts "" 65 66 # Monitor execution 67 IO.puts "Monitoring workflow execution..." 68 IO.puts "(Workflow is running asynchronously in the background)" 69 IO.puts "" 70 71 # Poll for status updates 72 monitor_workflow(execution_id, 30, 1000) 73 74 {:error, reason} -> 75 IO.puts "✗ Failed to start workflow: #{inspect(reason)}" 76 System.halt(1) 77 end 78 end 79 80 defp monitor_workflow(execution_id, max_attempts, interval_ms, attempt \\ 1) do 81 if attempt > max_attempts do 82 IO.puts "\n⚠ Workflow monitoring timeout after #{max_attempts} attempts" 83 IO.puts " Check workflow status manually with:" 84 IO.puts " EchoShared.Workflow.Engine.get_status(\"#{execution_id}\")" 85 System.halt(1) 86 end 87 88 case EchoShared.Workflow.Engine.get_status(execution_id) do 89 {:ok, execution} -> 90 print_status(execution, attempt) 91 92 case execution.status do 93 :completed -> 94 IO.puts "\n" <> String.duplicate("=", 80) 95 IO.puts "✓ Workflow completed successfully!" 96 print_summary(execution) 97 System.halt(0) 98 99 :failed -> 100 IO.puts "\n" <> String.duplicate("=", 80) 101 IO.puts "✗ Workflow failed!" 102 IO.puts " Error: #{inspect(execution.error)}" 103 System.halt(1) 104 105 :paused -> 106 IO.puts "\n" <> String.duplicate("=", 80) 107 IO.puts "⏸ Workflow paused for human approval" 108 IO.puts " Reason: #{execution.pause_reason}" 109 IO.puts "" 110 IO.puts "To resume, run:" 111 IO.puts " EchoShared.Workflow.Engine.resume_workflow(\"#{execution_id}\", %{approved: true})" 112 System.halt(0) 113 114 :running -> 115 # Continue monitoring 116 Process.sleep(interval_ms) 117 monitor_workflow(execution_id, max_attempts, interval_ms, attempt + 1) 118 end 119 120 {:error, :not_found} -> 121 IO.puts "✗ Execution not found: #{execution_id}" 122 System.halt(1) 123 end 124 end 125 126 defp print_status(execution, attempt) do 127 progress = "Step #{execution.current_step}" 128 IO.write "\r[#{String.pad_leading(Integer.to_string(attempt), 2, "0")}] Status: #{execution.status} | Progress: #{progress} " 129 end 130 131 defp print_summary(execution) do 132 duration = if execution.completed_at && execution.started_at do 133 diff = DateTime.diff(execution.completed_at, execution.started_at, :second) 134 "#{diff} seconds" 135 else 136 "unknown" 137 end 138 139 IO.puts " Workflow: #{execution.workflow_name}" 140 IO.puts " Duration: #{duration}" 141 IO.puts " Steps completed: #{execution.current_step}" 142 IO.puts " Context: #{inspect(execution.context, pretty: true)}" 143 IO.puts String.duplicate("=", 80) 144 IO.puts "" 145 IO.puts "Feature Development Complete! 🎉" 146 IO.puts "" 147 IO.puts "Next steps:" 148 IO.puts " 1. Review decision records in PostgreSQL" 149 IO.puts " 2. Check Redis message bus activity logs" 150 IO.puts " 3. Verify all agent communications" 151 IO.puts " 4. Run: psql -h localhost -U postgres echo_org -c 'SELECT * FROM workflow_executions;'" 152 end 153 end 154 155 # Run the simulation 156 Day1Simulator.run()