# `Mojentic.LLM.Tools.EphemeralTaskManager.TaskList`
[🔗](https://github.com/svetzal/mojentic-ex/blob/v1.2.0/lib/mojentic/llm/tools/ephemeral_task_manager/task_list.ex#L1)

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"

# `t`

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

# `append_task`

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`

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`

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`

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`

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`

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`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
