# `MingaAdversarial.Watcher`
[🔗](https://github.com/jsmestad/minga-adversarial/blob/main/lib/minga_adversarial/watcher.ex#L1)

Owns the adversarial analysis lifecycle.

Subscribes to save/change/close events. Analysis runs on demand (the
`adversarial-analyze` command) and, when the skepticism dial is `:on_save`
or `:paranoid`, on save. Each analysis runs the model off-process and
publishes findings through `Minga.Extension.Diagnostics`.

Only the latest admitted analysis for a path can publish. Its reply
consumes that request's ref, so late or duplicate replies are ignored.
A user edit, explicit clear, or buffer close discards both the pending
request and any published findings.

The model, dispatch, and editor effects are injectable so the lifecycle
can run without an editor process or network call.

# `skepticism`

```elixir
@type skepticism() :: :off | :manual | :on_save | :paranoid
```

# `state`

```elixir
@type state() :: %{
  skepticism_override: skepticism() | nil,
  ai_fun: (list(), pos_integer() -&gt; {:ok, String.t()} | {:error, term()}),
  dispatch: ((-&gt; any()) -&gt; any()),
  editor: editor(),
  pending: %{required(String.t()) =&gt; reference()},
  published: MapSet.t(String.t())
}
```

# `analyze`

```elixir
@spec analyze(GenServer.server(), String.t(), String.t() | nil) :: :ok | :off
```

Analyzes `path` now. Returns `:off` when the dial is off, else `:ok`.

Pass `content` to analyze in-memory buffer text (including unsaved edits);
when `nil`, the file on disk is read instead.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `clear`

```elixir
@spec clear(GenServer.server(), String.t()) :: :ok
```

Clears this extension's findings and invalidates pending analysis for `path`.

# `cycle_skepticism`

```elixir
@spec cycle_skepticism(GenServer.server()) :: skepticism()
```

Cycles the session skepticism dial and returns the new value.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

---

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