# `Minga.Session.Swap.Recovery`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga/session/swap/recovery.ex#L1)

Scans the swap directory for orphaned swap files and determines
which ones are recoverable.

A swap file is recoverable when:
- It parses correctly (valid MINGA_SWAP_V1 header)
- The OS PID that wrote it is no longer alive (`kill -0` check)
- The original file still exists on disk

Swap files written by a still-running Minga instance are left alone.
Corrupt swap files are cleaned up automatically.

# `entry`

```elixir
@type entry() :: %{path: String.t(), swap_path: String.t(), swap_mtime: integer()}
```

A recoverable swap file entry.

# `option`

```elixir
@type option() :: {:swap_dir, String.t()} | {:pid_alive?, (integer() -&gt; boolean())}
```

Options for scan and recovery operations.

# `discard`

```elixir
@spec discard(String.t()) :: :ok
```

Deletes a swap file (user declined recovery).

# `recover`

```elixir
@spec recover(String.t()) :: {:ok, String.t(), binary()} | {:error, term()}
```

Recovers content from a swap file.

Returns `{:ok, file_path, content}` where content is the unsaved
buffer text. The caller is responsible for opening a buffer with
this content and marking it as dirty. The swap file is deleted
after successful recovery.

# `scan`

```elixir
@spec scan([option()]) :: [entry()]
```

Scans the swap directory and returns a list of recoverable entries.

Each entry contains the original file path, the swap file path,
and the swap file's mtime. The caller decides what to do with them
(show a recovery prompt, auto-recover, etc.).

## Options

- `:swap_dir` - override the default swap directory (for testing)
- `:pid_alive?` - override the PID liveness check (for testing)

---

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