LlmCore.LLM.CLIPort (llm_core v0.3.0)

Copy Markdown View Source

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

exec_result()

@type exec_result() ::
  {:ok, iodata(), non_neg_integer()} | {:error, :timeout} | {:error, term()}

Functions

run(executable, args, timeout, execution_id \\ nil)

@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}.

spawn(executable, args, execution_id \\ nil)

@spec spawn(String.t(), [String.t()], String.t() | nil) ::
  {:ok, port()} | {:error, term()}

Spawns a CLI executable as an interactive port without waiting for completion.

Returns {:ok, port} for the caller to interact with directly.

stream(executable, args, timeout, execution_id \\ nil)

@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.