single task
This commit is contained in:
parent
63e01643e7
commit
0f8109ec00
1 changed files with 67 additions and 72 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
Main orchestrator for AI agent execution.
|
Main orchestrator for AI agent execution.
|
||||||
Manages the development cycle: read tasks -> execute -> test -> commit -> repeat
|
Executes a single task per run: read task -> execute -> test -> commit
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
@ -33,12 +33,12 @@ class AgentOrchestrator:
|
||||||
|
|
||||||
def run(self) -> int:
|
def run(self) -> int:
|
||||||
"""
|
"""
|
||||||
Main execution loop.
|
Execute a single task from the task list.
|
||||||
Returns: 0 on success, 1 on error
|
Returns: 0 on success, 1 on error
|
||||||
"""
|
"""
|
||||||
print(f"🚀 Starting AI Agent for component: {self.config.component}")
|
print(f"🚀 Starting AI Agent for component: {self.config.component}")
|
||||||
print(f"📁 Project root: {self.config.project_root}")
|
print(f"📁 Project root: {self.config.project_root}")
|
||||||
print(f"🎯 Max iterations: {self.config.max_iterations}")
|
print(f"🎯 Executing one task per run")
|
||||||
|
|
||||||
# Check if another agent is running
|
# Check if another agent is running
|
||||||
if self.task_manager.is_agent_running():
|
if self.task_manager.is_agent_running():
|
||||||
|
|
@ -47,76 +47,71 @@ class AgentOrchestrator:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Main development loop
|
state = self.task_manager.load_state()
|
||||||
while True:
|
|
||||||
state = self.task_manager.load_state()
|
|
||||||
|
|
||||||
# Check iteration limit
|
# Check iteration limit
|
||||||
if state.iteration_count >= self.config.max_iterations:
|
if state.iteration_count >= self.config.max_iterations:
|
||||||
print(f"\n⏹️ Reached maximum iterations ({self.config.max_iterations})")
|
print(f"\n⏹️ Reached maximum iterations ({self.config.max_iterations})")
|
||||||
break
|
return 0
|
||||||
|
|
||||||
# Get next task
|
# Get next task
|
||||||
next_task = self.task_manager.get_next_task()
|
next_task = self.task_manager.get_next_task()
|
||||||
|
|
||||||
if not next_task:
|
if not next_task:
|
||||||
print("\n✅ All tasks completed!")
|
print("\n✅ All tasks completed!")
|
||||||
self.task_manager.reset_state()
|
self.task_manager.reset_state()
|
||||||
break
|
return 0
|
||||||
|
|
||||||
print(f"\n{'='*80}")
|
print(f"\n{'='*80}")
|
||||||
print(f"📋 Task {state.iteration_count + 1}/{self.config.max_iterations}: {next_task.id}")
|
print(f"📋 Task: {next_task.id}")
|
||||||
print(f"📝 {next_task.title}")
|
print(f"📝 {next_task.title}")
|
||||||
print(f"⏱️ Estimated: {next_task.estimated_hours}h")
|
print(f"⏱️ Estimated: {next_task.estimated_hours}h")
|
||||||
print(f"{'='*80}\n")
|
print(f"{'='*80}\n")
|
||||||
|
|
||||||
# Start task
|
# Start task
|
||||||
self.task_manager.start_task(next_task)
|
self.task_manager.start_task(next_task)
|
||||||
|
|
||||||
# Check if task needs global lock (modifies common package)
|
# Check if task needs global lock (modifies common package)
|
||||||
needs_global_lock = self._needs_global_lock(next_task)
|
needs_global_lock = self._needs_global_lock(next_task)
|
||||||
if needs_global_lock:
|
if needs_global_lock:
|
||||||
if not self._acquire_global_lock():
|
if not self._acquire_global_lock():
|
||||||
print("⚠️ Cannot acquire global lock, skipping task")
|
print("⚠️ Cannot acquire global lock, skipping task")
|
||||||
self.task_manager.mark_task_skipped(
|
self.task_manager.mark_task_skipped(
|
||||||
|
next_task.id,
|
||||||
|
"Global lock not available"
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Execute task
|
||||||
|
success = self._execute_task(next_task)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
# Task completed successfully
|
||||||
|
print(f"\n✅ Task {next_task.id} completed successfully")
|
||||||
|
self.task_manager.mark_task_completed(next_task.id)
|
||||||
|
else:
|
||||||
|
# Task failed
|
||||||
|
retry_count = self.task_manager.increment_retry()
|
||||||
|
|
||||||
|
if retry_count >= self.config.max_retries:
|
||||||
|
print(f"\n❌ Task {next_task.id} failed after {retry_count} retries")
|
||||||
|
self.task_manager.mark_task_failed(
|
||||||
next_task.id,
|
next_task.id,
|
||||||
"Global lock not available"
|
f"Failed after {retry_count} retries"
|
||||||
)
|
)
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
# Create GitHub issue
|
||||||
# Execute task
|
self._create_issue_for_failed_task(next_task)
|
||||||
success = self._execute_task(next_task)
|
|
||||||
|
|
||||||
if success:
|
|
||||||
# Task completed successfully
|
|
||||||
print(f"\n✅ Task {next_task.id} completed successfully")
|
|
||||||
self.task_manager.mark_task_completed(next_task.id)
|
|
||||||
else:
|
else:
|
||||||
# Task failed
|
print(f"\n⚠️ Task {next_task.id} failed, will retry ({retry_count}/{self.config.max_retries})")
|
||||||
retry_count = self.task_manager.increment_retry()
|
|
||||||
|
|
||||||
if retry_count >= self.config.max_retries:
|
finally:
|
||||||
print(f"\n❌ Task {next_task.id} failed after {retry_count} retries")
|
# Release global lock if held
|
||||||
self.task_manager.mark_task_failed(
|
if needs_global_lock:
|
||||||
next_task.id,
|
self.global_lock.release(self.config.component)
|
||||||
f"Failed after {retry_count} retries"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create GitHub issue
|
print("\n🎉 Agent execution completed (one task)")
|
||||||
self._create_issue_for_failed_task(next_task)
|
|
||||||
else:
|
|
||||||
print(f"\n⚠️ Task {next_task.id} failed, will retry ({retry_count}/{self.config.max_retries})")
|
|
||||||
|
|
||||||
finally:
|
|
||||||
# Release global lock if held
|
|
||||||
if needs_global_lock:
|
|
||||||
self.global_lock.release(self.config.component)
|
|
||||||
|
|
||||||
# Small delay between tasks
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
print("\n🎉 Agent execution completed")
|
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue