Mojentic.LLM.Tools.EphemeralTaskManager.TaskList (Mojentic v1.2.0)

Copy Markdown View Source

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

t()

@type t() :: %Mojentic.LLM.Tools.EphemeralTaskManager.TaskList{
  next_id: pos_integer(),
  tasks: [Mojentic.LLM.Tools.EphemeralTaskManager.Task.t()]
}

Functions

append_task(list, description)

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

clear_tasks(task_list)

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)
[]

complete_task(list, task_id)

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

insert_task_after(list, existing_task_id, description)

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"

list_tasks(task_list)

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

new()

Creates a new empty task list.

Examples

iex> TaskList.new()
%TaskList{tasks: [], next_id: 1}

prepend_task(list, description)

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

start_task(list, task_id)

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