|
@@ -14,6 +14,14 @@ class Task:
|
|
|
subtasks: List["Task"]
|
|
subtasks: List["Task"]
|
|
|
|
|
|
|
|
def __init__(self, parent: "Task | None", goal: str, state: str=OPEN_STATE, subtasks: List = []):
|
|
def __init__(self, parent: "Task | None", goal: str, state: str=OPEN_STATE, subtasks: List = []):
|
|
|
|
|
+ """Initializes a new instance of the Task class.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ parent: The parent task, or None if it is the root task.
|
|
|
|
|
+ goal: The goal of the task.
|
|
|
|
|
+ state: The initial state of the task.
|
|
|
|
|
+ subtasks: A list of subtasks associated with this task.
|
|
|
|
|
+ """
|
|
|
if parent is None:
|
|
if parent is None:
|
|
|
self.id = '0'
|
|
self.id = '0'
|
|
|
else:
|
|
else:
|
|
@@ -33,6 +41,14 @@ class Task:
|
|
|
self.state = OPEN_STATE
|
|
self.state = OPEN_STATE
|
|
|
|
|
|
|
|
def to_string(self, indent=""):
|
|
def to_string(self, indent=""):
|
|
|
|
|
+ """Returns a string representation of the task and its subtasks.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ indent: The indentation string for formatting the output.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ A string representation of the task and its subtasks.
|
|
|
|
|
+ """
|
|
|
emoji = ''
|
|
emoji = ''
|
|
|
if self.state == VERIFIED_STATE:
|
|
if self.state == VERIFIED_STATE:
|
|
|
emoji = '✅'
|
|
emoji = '✅'
|
|
@@ -50,6 +66,11 @@ class Task:
|
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
def to_dict(self):
|
|
def to_dict(self):
|
|
|
|
|
+ """Returns a dictionary representation of the task.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ A dictionary containing the task's attributes.
|
|
|
|
|
+ """
|
|
|
return {
|
|
return {
|
|
|
'id': self.id,
|
|
'id': self.id,
|
|
|
'goal': self.goal,
|
|
'goal': self.goal,
|
|
@@ -58,6 +79,13 @@ class Task:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
def set_state(self, state):
|
|
def set_state(self, state):
|
|
|
|
|
+ """Sets the state of the task and its subtasks.
|
|
|
|
|
+
|
|
|
|
|
+ Args: state: The new state of the task.
|
|
|
|
|
+
|
|
|
|
|
+ Raises:
|
|
|
|
|
+ ValueError: If the provided state is invalid.
|
|
|
|
|
+ """
|
|
|
if state not in STATES:
|
|
if state not in STATES:
|
|
|
raise ValueError('Invalid state:' + state)
|
|
raise ValueError('Invalid state:' + state)
|
|
|
self.state = state
|
|
self.state = state
|
|
@@ -70,6 +98,11 @@ class Task:
|
|
|
self.parent.set_state(state)
|
|
self.parent.set_state(state)
|
|
|
|
|
|
|
|
def get_current_task(self) -> "Task | None":
|
|
def get_current_task(self) -> "Task | None":
|
|
|
|
|
+ """Retrieves the current task in progress.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ The current task in progress, or None if no task is in progress.
|
|
|
|
|
+ """
|
|
|
for subtask in self.subtasks:
|
|
for subtask in self.subtasks:
|
|
|
if subtask.state == IN_PROGRESS_STATE:
|
|
if subtask.state == IN_PROGRESS_STATE:
|
|
|
return subtask.get_current_task()
|
|
return subtask.get_current_task()
|
|
@@ -78,17 +111,44 @@ class Task:
|
|
|
return None
|
|
return None
|
|
|
|
|
|
|
|
class Plan:
|
|
class Plan:
|
|
|
|
|
+ """Represents a plan consisting of tasks.
|
|
|
|
|
+
|
|
|
|
|
+ Attributes:
|
|
|
|
|
+ main_goal: The main goal of the plan.
|
|
|
|
|
+ task: The root task of the plan.
|
|
|
|
|
+ """
|
|
|
main_goal: str
|
|
main_goal: str
|
|
|
task: Task
|
|
task: Task
|
|
|
|
|
|
|
|
def __init__(self, task: str):
|
|
def __init__(self, task: str):
|
|
|
|
|
+ """Initializes a new instance of the Plan class.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ task: The main goal of the plan.
|
|
|
|
|
+ """
|
|
|
self.main_goal = task
|
|
self.main_goal = task
|
|
|
self.task = Task(parent=None, goal=task, subtasks=[])
|
|
self.task = Task(parent=None, goal=task, subtasks=[])
|
|
|
|
|
|
|
|
def __str__(self):
|
|
def __str__(self):
|
|
|
|
|
+ """Returns a string representation of the plan.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ A string representation of the plan.
|
|
|
|
|
+ """
|
|
|
return self.task.to_string()
|
|
return self.task.to_string()
|
|
|
|
|
|
|
|
def get_task_by_id(self, id: str) -> Task:
|
|
def get_task_by_id(self, id: str) -> Task:
|
|
|
|
|
+ """Retrieves a task by its ID.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ id: The ID of the task.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ The task with the specified ID.
|
|
|
|
|
+
|
|
|
|
|
+ Raises:
|
|
|
|
|
+ ValueError: If the provided task ID is invalid or does not exist.
|
|
|
|
|
+ """
|
|
|
try:
|
|
try:
|
|
|
parts = [int(p) for p in id.split('.')]
|
|
parts = [int(p) for p in id.split('.')]
|
|
|
except ValueError:
|
|
except ValueError:
|
|
@@ -104,14 +164,32 @@ class Plan:
|
|
|
return task
|
|
return task
|
|
|
|
|
|
|
|
def add_subtask(self, parent_id: str, goal: str, subtasks: List = []):
|
|
def add_subtask(self, parent_id: str, goal: str, subtasks: List = []):
|
|
|
|
|
+ """Adds a subtask to a parent task.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ parent_id: The ID of the parent task.
|
|
|
|
|
+ goal: The goal of the subtask.
|
|
|
|
|
+ subtasks: A list of subtasks associated with the new subtask.
|
|
|
|
|
+ """
|
|
|
parent = self.get_task_by_id(parent_id)
|
|
parent = self.get_task_by_id(parent_id)
|
|
|
child = Task(parent=parent, goal=goal, subtasks=subtasks)
|
|
child = Task(parent=parent, goal=goal, subtasks=subtasks)
|
|
|
parent.subtasks.append(child)
|
|
parent.subtasks.append(child)
|
|
|
|
|
|
|
|
def set_subtask_state(self, id: str, state: str):
|
|
def set_subtask_state(self, id: str, state: str):
|
|
|
|
|
+ """Sets the state of a subtask.
|
|
|
|
|
+
|
|
|
|
|
+ Args:
|
|
|
|
|
+ id: The ID of the subtask.
|
|
|
|
|
+ state: The new state of the subtask.
|
|
|
|
|
+ """
|
|
|
task = self.get_task_by_id(id)
|
|
task = self.get_task_by_id(id)
|
|
|
task.set_state(state)
|
|
task.set_state(state)
|
|
|
|
|
|
|
|
def get_current_task(self):
|
|
def get_current_task(self):
|
|
|
|
|
+ """Retrieves the current task in progress.
|
|
|
|
|
+
|
|
|
|
|
+ Returns:
|
|
|
|
|
+ The current task in progress, or None if no task is in progress.
|
|
|
|
|
+ """
|
|
|
return self.task.get_current_task()
|
|
return self.task.get_current_task()
|
|
|
|
|
|