CliSubprocessCore.Session (CliSubprocessCore v0.1.0)

Copy Markdown View Source

Common CLI session runtime above the raw transport layer.

Summary

Functions

Returns a specification to start this module under a supervisor.

Stops the session and closes the transport.

Returns stable mailbox-delivery metadata for the current session.

Closes stdin for EOF-driven CLIs.

Extracts a normalized session event from a legacy mailbox message.

Extracts a normalized session event for a tagged subscriber reference.

Returns session runtime and transport information.

Sends an interrupt request to the underlying transport.

Sends provider input through the underlying transport.

Alias for send/2 that preserves the runtime-kit naming.

Starts a linked session process.

Starts a linked session and returns the pid together with its initial info snapshot.

Starts a session and returns the pid together with its initial info snapshot.

Subscribes a process in legacy mode.

Subscribes a process with an explicit tag.

Removes a subscriber.

Types

subscriber_info()

@type subscriber_info() :: %{monitor_ref: reference(), tag: :legacy | reference()}

t()

@type t() :: %CliSubprocessCore.Session{
  invocation: CliSubprocessCore.Command.t(),
  options: CliSubprocessCore.Session.Options.t(),
  parser_state: term(),
  profile: module(),
  provider: atom(),
  runtime: CliSubprocessCore.Runtime.t(),
  subscribers: %{optional(pid()) => subscriber_info()},
  transport_pid: pid(),
  transport_ref: reference()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close(session)

@spec close(pid()) :: :ok

Stops the session and closes the transport.

delivery_info(session)

@spec delivery_info(pid()) :: CliSubprocessCore.Session.Delivery.t() | nil

Returns stable mailbox-delivery metadata for the current session.

end_input(session)

@spec end_input(pid()) :: :ok | {:error, term()}

Closes stdin for EOF-driven CLIs.

extract_event(arg1)

@spec extract_event(term()) :: {:ok, CliSubprocessCore.Event.t()} | :error

Extracts a normalized session event from a legacy mailbox message.

Tagged subscribers should use extract_event/2 so their code does not depend on a specific outer event atom.

extract_event(message, ref)

@spec extract_event(term(), reference()) ::
  {:ok, CliSubprocessCore.Event.t()} | :error

Extracts a normalized session event for a tagged subscriber reference.

This is the stable core-owned way for adapters to consume session delivery without hard-coding the configured outer event atom.

info(session)

@spec info(pid()) :: map()

Returns session runtime and transport information.

interrupt(session)

@spec interrupt(pid()) :: :ok | {:error, term()}

Sends an interrupt request to the underlying transport.

send(session, input)

@spec send(pid(), iodata() | map() | list()) :: :ok | {:error, term()}

Sends provider input through the underlying transport.

send_input(session, input, opts \\ [])

@spec send_input(pid(), iodata() | map() | list(), keyword()) ::
  :ok | {:error, term()}

Alias for send/2 that preserves the runtime-kit naming.

start_link(opts)

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

Starts a linked session process.

start_session(opts)

@spec start_session(keyword()) :: {:ok, pid(), map()} | {:error, term()}

Starts a session and returns the pid together with its initial info snapshot.

subscribe(session, pid)

@spec subscribe(pid(), pid()) :: :ok | {:error, term()}

Subscribes a process in legacy mode.

subscribe(session, pid, tag)

@spec subscribe(pid(), pid(), :legacy | reference()) :: :ok | {:error, term()}

Subscribes a process with an explicit tag.

unsubscribe(session, pid)

@spec unsubscribe(pid(), pid()) :: :ok

Removes a subscriber.