Extractors Reference

Copy Markdown

Extractors auto-generate TLX spec skeletons from existing code. Each extractor targets a specific module type and produces a result map that feeds into OTP patterns or TLX.Importer.Codegen.

Extraction Tiers (ADR-0012)

TierMethodExtractors
1Elixir source ASTgen_statem, GenServer, LiveView, Broadway
2BEAM abstract_codeErlang gen_server, gen_fsm
3Runtime introspectionAsh.StateMachine, Reactor

Confidence Levels

Extractors annotate each transition with a confidence level:

LevelMeaningGenerated output
:highLiteral value extracted from pattern match or return tupleClean action, no comments
:mediumValue from branched code (if/case/cond)Action with confidence comment
:lowComputed value, variable, or no changes detectedAction with TODO comment

When all transitions are :high confidence, the mix task generates a pattern module. Otherwise it falls back to codegen (defspec) format.

Extractor Output Formats

State machine extractors

gen_statem, Erlang gen_fsm, Ash.StateMachine produce:

%{
  behavior: :gen_statem | :gen_fsm | :ash_state_machine,
  states: [:idle, :running, ...],
  initial: :idle,
  transitions: [
    %{event: :start, from: :idle, to: :running, guard: nil, confidence: :high}
  ],
  warnings: []
}

Multi-field extractors

GenServer, LiveView produce:

%{
  behavior: :gen_server | :live_view,
  fields: [status: :idle, count: 0],
  calls: [%{name: :check, next: [status: :in_sync], guard: [], confidence: :high}],
  casts: [...],
  infos: [...],
  warnings: []
}

LiveView uses events (from handle_event/3) instead of calls.

Workflow extractors

Reactor produces:

%{
  behavior: :reactor,
  inputs: [:url],
  steps: [%{name: :fetch, depends_on: [{:input, :url}], async: true, max_retries: :infinity}],
  return: :fetch,
  graph: %{fetch: []},
  warnings: []
}

Broadway produces:

%{
  behavior: :broadway,
  producers: [%{module: Broadway.DummyProducer, concurrency: 1, rate_limiting: false}],
  processors: [%{name: :default, concurrency: 2}],
  batchers: [%{name: :sqs, concurrency: 1, batch_size: 10, batch_timeout: 1000}],
  callbacks: %{handle_message: 1, handle_batch: 2},
  warnings: []
}

Limitations

ExtractorLimitations
gen_statemOnly handle_event_function and state_functions modes. Catch-all clauses skipped.
GenServerOnly detects %{state | key: val} map updates. Helper function calls produce :low confidence.
LiveViewupdate/3 functional updates produce :unknown values. Runtime-constructed assigns missed.
ErlangRequires debug_info compilation. Erlang map syntax only (#{} maps, not records).
Ash.StateMachineRequires ash_state_machine dependency. Runtime-only (module must be compiled).
ReactorRequires reactor dependency. Runtime-only. Step implementations are opaque.
BroadwayOnly detects literal Broadway.start_link(__MODULE__, opts) calls. Dynamic config missed.