MCPcopy Create free account
hub / github.com/Ishabdullah/Codey-v2 / Planner

Class Planner

core/planner_v2.py:46–439  ·  view source on GitHub ↗

Internal task planner for Codey-v2. Features: - Task queue with dependencies - Automatic task breakdown - Adaptation on failure - Persistence in SQLite

Source from the content-addressed store, hash-verified

44
45
46class Planner:
47 """
48 Internal task planner for Codey-v2.
49
50 Features:
51 - Task queue with dependencies
52 - Automatic task breakdown
53 - Adaptation on failure
54 - Persistence in SQLite
55 """
56
57 def __init__(self, max_retries: int = 3):
58 self.state = get_state_store()
59 self.max_retries = max_retries
60 self._tasks: Dict[int, Task] = {}
61 self._running: bool = False
62 self._current_task: Optional[Task] = None
63 self._adaptation_callbacks: Dict[str, Callable] = {}
64
65 # Load existing tasks from database
66 self._load_tasks()
67
68 def _load_tasks(self):
69 """Load pending/running tasks from database."""
70 tasks = self.state.get_all_tasks()
71 for t in tasks:
72 if t["status"] in ("pending", "running"):
73 deps = []
74 if t.get("dependencies"):
75 try:
76 deps = json.loads(t["dependencies"])
77 except:
78 deps = []
79
80 self._tasks[t["id"]] = Task(
81 id=t["id"],
82 description=t["description"],
83 status=TaskStatus(t["status"]),
84 dependencies=deps,
85 result=t.get("result"),
86 created_at=t.get("created_at", 0),
87 started_at=t.get("started_at"),
88 completed_at=t.get("completed_at"),
89 retry_count=t.get("retry_count", 0),
90 )
91
92 def add_task(self, description: str, dependencies: List[int] = None) -> int:
93 """
94 Add a new task to the queue.
95
96 Args:
97 description: Task description
98 dependencies: List of task IDs that must complete first
99
100 Returns:
101 Task ID
102 """
103 # Add to database

Callers 1

get_plannerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected