ExternalRuntimeTransport.Transport behaviour
(ExternalRuntimeTransport v0.1.0)
Copy Markdown
View Source
Behaviour for the raw subprocess transport layer.
In addition to the long-lived subscriber-driven transport API, the transport
layer also owns synchronous non-PTY command execution through run/2.
Legacy subscribers receive bare transport tuples:
{:transport_message, line}{:transport_data, chunk}{:transport_error, %ExternalRuntimeTransport.Transport.Error{}}{:transport_stderr, chunk}{:transport_exit, %ExternalRuntimeTransport.ProcessExit{}}
Tagged subscribers receive:
{event_tag, ref, {:message, line}}{event_tag, ref, {:data, chunk}}{event_tag, ref, {:error, %ExternalRuntimeTransport.Transport.Error{}}}{event_tag, ref, {:stderr, chunk}}{event_tag, ref, {:exit, %ExternalRuntimeTransport.ProcessExit{}}}
When :replay_stderr_on_subscribe? is enabled at startup, newly attached
subscribers also receive the retained stderr tail immediately after
subscription. When :buffer_events_until_subscribe? is enabled, stdout,
stderr, and error events emitted before the first subscriber attaches are
replayed in order.
Summary
Types
The tagged event atom prefix.
Normalized transport event payload extracted from a mailbox message.
Transport events delivered to subscribers.
Legacy subscribers use :legacy; tagged subscribers use a reference.
Generic execution-surface placement kind.
Opaque transport reference.
Functions
Stops the transport.
Returns stable mailbox-delivery metadata for the current transport snapshot.
Closes stdin for EOF-driven CLIs.
Extracts a normalized transport event from a legacy mailbox message.
Extracts a normalized transport event for a tagged subscriber reference.
Forces the subprocess down immediately.
Returns the current transport metadata snapshot.
Sends SIGINT to the subprocess.
Runs a one-shot non-PTY command and captures exact stdout, stderr, and exit data.
Sends data to the subprocess stdin.
Starts the default raw transport implementation.
Starts the default raw transport implementation and links it to the caller.
Returns transport connectivity status.
Returns the stderr ring buffer tail.
Subscribes the caller in legacy mode.
Subscribes a process with an explicit tag mode.
Removes a subscriber.
Types
@type event_tag() :: atom()
The tagged event atom prefix.
@type extracted_event() :: {:message, binary()} | {:data, binary()} | {:error, ExternalRuntimeTransport.Transport.Error.t()} | {:stderr, binary()} | {:exit, ExternalRuntimeTransport.ProcessExit.t()}
Normalized transport event payload extracted from a mailbox message.
@type message() :: {:transport_message, binary()} | {:transport_data, binary()} | {:transport_error, ExternalRuntimeTransport.Transport.Error.t()} | {:transport_stderr, binary()} | {:transport_exit, ExternalRuntimeTransport.ProcessExit.t()} | {event_tag(), reference(), {:message, binary()}} | {event_tag(), reference(), {:data, binary()}} | {event_tag(), reference(), {:error, ExternalRuntimeTransport.Transport.Error.t()}} | {event_tag(), reference(), {:stderr, binary()}} | {event_tag(), reference(), {:exit, ExternalRuntimeTransport.ProcessExit.t()}}
Transport events delivered to subscribers.
@type subscription_tag() :: :legacy | reference()
Legacy subscribers use :legacy; tagged subscribers use a reference.
@type surface_kind() :: :local_subprocess | :ssh_exec | :guest_bridge
Generic execution-surface placement kind.
@type t() :: pid()
Opaque transport reference.
Callbacks
@callback close(t()) :: :ok
@callback end_input(t()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback force_close(t()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback info(t()) :: ExternalRuntimeTransport.Transport.Info.t()
@callback interrupt(t()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback run( ExternalRuntimeTransport.Command.t(), keyword() ) :: {:ok, ExternalRuntimeTransport.Transport.RunResult.t()} | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback send(t(), iodata() | map() | list()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback start(keyword()) :: {:ok, t()} | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback start_link(keyword()) :: {:ok, t()} | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback status(t()) :: :connected | :disconnected | :error
@callback subscribe(t(), pid()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
@callback subscribe(t(), pid(), subscription_tag()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Functions
@spec close(t()) :: :ok
Stops the transport.
@spec delivery_info(t()) :: ExternalRuntimeTransport.Transport.Delivery.t()
Returns stable mailbox-delivery metadata for the current transport snapshot.
@spec end_input(t()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Closes stdin for EOF-driven CLIs.
Pipe-backed transports send :eof; PTY-backed transports send the terminal
EOF byte (Ctrl-D).
@spec extract_event(term()) :: {:ok, extracted_event()} | :error
Extracts a normalized transport event from a legacy mailbox message.
Tagged subscribers should use extract_event/2 so their code does not depend
on a specific outer event tag.
@spec extract_event(term(), reference()) :: {:ok, extracted_event()} | :error
Extracts a normalized transport event for a tagged subscriber reference.
This is the stable core-owned way for adapters to consume tagged transport delivery without hard-coding the configured outer event atom.
@spec force_close(t()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Forces the subprocess down immediately.
@spec info(t()) :: ExternalRuntimeTransport.Transport.Info.t()
Returns the current transport metadata snapshot.
@spec interrupt(t()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Sends SIGINT to the subprocess.
@spec run( ExternalRuntimeTransport.Command.t(), keyword() ) :: {:ok, ExternalRuntimeTransport.Transport.RunResult.t()} | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Runs a one-shot non-PTY command and captures exact stdout, stderr, and exit data.
@spec send(t(), iodata() | map() | list()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Sends data to the subprocess stdin.
@spec start(keyword()) :: {:ok, t()} | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Starts the default raw transport implementation.
@spec start_link(keyword()) :: {:ok, t()} | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Starts the default raw transport implementation and links it to the caller.
@spec status(t()) :: :connected | :disconnected | :error
Returns transport connectivity status.
Returns the stderr ring buffer tail.
@spec subscribe(t(), pid()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Subscribes the caller in legacy mode.
@spec subscribe(t(), pid(), subscription_tag()) :: :ok | {:error, {:transport, ExternalRuntimeTransport.Transport.Error.t()}}
Subscribes a process with an explicit tag mode.
Removes a subscriber.