Manages a list of tasks for the ephemeral task manager.
This module provides functions for adding, starting, completing, and listing tasks. Tasks follow a state machine that transitions from :pending through :in_progress to :completed.
Examples
iex> task_list = TaskList.new()
iex> {task, task_list} = TaskList.append_task(task_list, "Write tests")
iex> task.description
"Write tests"
Summary
Functions
Appends a new task to the end of the list.
Clears all tasks from the list.
Completes a task by changing its status from :in_progress to :completed.
Inserts a new task after an existing task with the given ID.
Returns all tasks in the list.
Creates a new empty task list.
Prepends a new task to the beginning of the list.
Starts a task by changing its status from :pending to :in_progress.
Types
@type t() :: %Mojentic.LLM.Tools.EphemeralTaskManager.TaskList{ next_id: pos_integer(), tasks: [Mojentic.LLM.Tools.EphemeralTaskManager.Task.t()] }
Functions
Appends a new task to the end of the list.
Returns a tuple of the created task and the updated task list.
Examples
iex> task_list = TaskList.new()
iex> {task, task_list} = TaskList.append_task(task_list, "Write tests")
iex> task.status
:pending
Clears all tasks from the list.
Returns a tuple of the count of cleared tasks and the empty task list.
Examples
iex> task_list = TaskList.new()
iex> {_task, task_list} = TaskList.append_task(task_list, "Task 1")
iex> {count, empty_list} = TaskList.clear_tasks(task_list)
iex> count
1
iex> TaskList.list_tasks(empty_list)
[]
Completes a task by changing its status from :in_progress to :completed.
Returns {:ok, task, updated_list} on success or {:error, reason} if the
task is not found or not in :in_progress status.
Examples
iex> task_list = TaskList.new()
iex> {task, task_list} = TaskList.append_task(task_list, "Task 1")
iex> {:ok, _, task_list} = TaskList.start_task(task_list, task.id)
iex> {:ok, completed_task, task_list} = TaskList.complete_task(task_list, task.id)
iex> completed_task.status
:completed
Inserts a new task after an existing task with the given ID.
Returns {:ok, task, updated_list} on success or {:error, reason} if the
existing task is not found.
Examples
iex> task_list = TaskList.new()
iex> {_task1, task_list} = TaskList.append_task(task_list, "Task 1")
iex> {:ok, task2, task_list} = TaskList.insert_task_after(task_list, 1, "Task 2")
iex> task2.description
"Task 2"
Returns all tasks in the list.
Examples
iex> task_list = TaskList.new()
iex> {_task, task_list} = TaskList.append_task(task_list, "Task 1")
iex> tasks = TaskList.list_tasks(task_list)
iex> length(tasks)
1
Creates a new empty task list.
Examples
iex> TaskList.new()
%TaskList{tasks: [], next_id: 1}
Prepends a new task to the beginning of the list.
Returns a tuple of the created task and the updated task list.
Examples
iex> task_list = TaskList.new()
iex> {task, task_list} = TaskList.prepend_task(task_list, "Important task")
iex> task.status
:pending
Starts a task by changing its status from :pending to :in_progress.
Returns {:ok, task, updated_list} on success or {:error, reason} if the
task is not found or not in :pending status.
Examples
iex> task_list = TaskList.new()
iex> {task, task_list} = TaskList.append_task(task_list, "Task 1")
iex> {:ok, started_task, task_list} = TaskList.start_task(task_list, task.id)
iex> started_task.status
:in_progress