MingaAdversarial.Watcher (minga_adversarial v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

Returns a specification to start this module under a supervisor.

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

Cycles the session skepticism dial and returns the new value.

Types

skepticism()

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

state()

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

Functions

analyze(server \\ __MODULE__, path, content \\ nil)

@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(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear(server \\ __MODULE__, path)

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

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

cycle_skepticism(server \\ __MODULE__)

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

Cycles the session skepticism dial and returns the new value.

start_link(opts \\ [])

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