Helpers for running CLI-based LLM providers via Port.
This is used to support true HALT semantics by allowing the executor to interrupt in-flight CLI operations (SIGINT/SIGTERM/SIGKILL).
Summary
Functions
Runs a CLI executable with the given args and returns collected output.
Spawns a CLI executable as an interactive port without waiting for completion.
Starts a CLI executable and returns a lazy stream of output lines.
Types
@type exec_result() :: {:ok, iodata(), non_neg_integer()} | {:error, :timeout} | {:error, term()}
Functions
@spec run(String.t(), [String.t()], timeout(), String.t() | nil) :: exec_result()
Runs a CLI executable with the given args and returns collected output.
Opens a port with </dev/null to close stdin, collects all stdout/stderr
data, and returns {:ok, output, exit_code} or {:error, reason}.
Spawns a CLI executable as an interactive port without waiting for completion.
Returns {:ok, port} for the caller to interact with directly.
@spec stream(String.t(), [String.t()], timeout(), String.t() | nil) :: {:ok, Enumerable.t()} | {:error, term()}
Starts a CLI executable and returns a lazy stream of output lines.
The stream yields line-by-line output. The port is automatically closed when the stream is consumed or on timeout.