single task

This commit is contained in:
Dmitry 2025-11-21 01:49:07 +03:00
parent 63e01643e7
commit 0f8109ec00

View file

@ -1,6 +1,6 @@
"""
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 subprocess
@ -33,12 +33,12 @@ class AgentOrchestrator:
def run(self) -> int:
"""
Main execution loop.
Execute a single task from the task list.
Returns: 0 on success, 1 on error
"""
print(f"🚀 Starting AI Agent for component: {self.config.component}")
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
if self.task_manager.is_agent_running():
@ -47,76 +47,71 @@ class AgentOrchestrator:
return 0
try:
# Main development loop
while True:
state = self.task_manager.load_state()
# Check iteration limit
if state.iteration_count >= self.config.max_iterations:
print(f"\n⏹️ Reached maximum iterations ({self.config.max_iterations})")
break
# Get next task
next_task = self.task_manager.get_next_task()
if not next_task:
print("\n✅ All tasks completed!")
self.task_manager.reset_state()
break
print(f"\n{'='*80}")
print(f"📋 Task {state.iteration_count + 1}/{self.config.max_iterations}: {next_task.id}")
print(f"📝 {next_task.title}")
print(f"⏱️ Estimated: {next_task.estimated_hours}h")
print(f"{'='*80}\n")
# Start task
self.task_manager.start_task(next_task)
# Check if task needs global lock (modifies common package)
needs_global_lock = self._needs_global_lock(next_task)
if needs_global_lock:
if not self._acquire_global_lock():
print("⚠️ Cannot acquire global lock, skipping task")
self.task_manager.mark_task_skipped(
next_task.id,
"Global lock not available"
)
continue
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,
f"Failed after {retry_count} retries"
)
# Create GitHub issue
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)
state = self.task_manager.load_state()
print("\n🎉 Agent execution completed")
# Check iteration limit
if state.iteration_count >= self.config.max_iterations:
print(f"\n⏹️ Reached maximum iterations ({self.config.max_iterations})")
return 0
# Get next task
next_task = self.task_manager.get_next_task()
if not next_task:
print("\n✅ All tasks completed!")
self.task_manager.reset_state()
return 0
print(f"\n{'='*80}")
print(f"📋 Task: {next_task.id}")
print(f"📝 {next_task.title}")
print(f"⏱️ Estimated: {next_task.estimated_hours}h")
print(f"{'='*80}\n")
# Start task
self.task_manager.start_task(next_task)
# Check if task needs global lock (modifies common package)
needs_global_lock = self._needs_global_lock(next_task)
if needs_global_lock:
if not self._acquire_global_lock():
print("⚠️ Cannot acquire global lock, skipping task")
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,
f"Failed after {retry_count} retries"
)
# Create GitHub issue
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)
print("\n🎉 Agent execution completed (one task)")
return 0
except KeyboardInterrupt: