# `CliSubprocessCore.Channel`
[🔗](https://github.com/nshkrdotcom/cli_subprocess_core/blob/v0.1.0/lib/cli_subprocess_core/channel.ex#L1)

Generic long-lived CLI IO channel above the raw session layer.

Channels own the subprocess session lifecycle and expose mailbox delivery for
framed stdout, stderr, exit, and transport-error events without tying callers
to raw transport refs.

# `extracted_event`

```elixir
@type extracted_event() ::
  {:message, binary()}
  | {:data, binary()}
  | {:stderr, binary()}
  | {:exit, ExternalRuntimeTransport.ProcessExit.t()}
  | {:error, term()}
```

# `info_t`

```elixir
@type info_t() :: %{
  delivery: CliSubprocessCore.Channel.Delivery.t(),
  invocation: CliSubprocessCore.Command.t(),
  subscribers: non_neg_integer(),
  raw_session: CliSubprocessCore.RawSession.info_t(),
  transport: term()
}
```

# `subscriber_info`

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

# `t`

```elixir
@type t() :: pid()
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `close`

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

Stops the channel and closes the underlying raw session.

# `close_input`

```elixir
@spec close_input(pid()) :: :ok | {:error, term()}
```

Alias for `end_input/1`.

# `delivery_info`

```elixir
@spec delivery_info(pid()) :: CliSubprocessCore.Channel.Delivery.t() | nil
```

Returns stable mailbox-delivery metadata for tagged subscribers.

# `end_input`

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

Closes stdin for EOF-driven sessions.

# `extract_event`

```elixir
@spec extract_event(term()) :: {:ok, extracted_event()} | :error
```

Extracts a normalized channel event from a legacy mailbox message.

# `extract_event`

```elixir
@spec extract_event(term(), reference()) :: {:ok, extracted_event()} | :error
```

Extracts a normalized channel event for a tagged subscriber reference.

# `force_close`

```elixir
@spec force_close(pid()) :: :ok | {:error, term()}
```

Forces the channel down immediately.

# `info`

```elixir
@spec info(pid()) :: info_t() | %{}
```

Returns channel runtime information.

# `interrupt`

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

Interrupts the underlying session.

# `send`

```elixir
@spec send(pid(), iodata()) :: :ok | {:error, term()}
```

Sends input bytes to the underlying session.

# `send_input`

```elixir
@spec send_input(pid(), iodata()) :: :ok | {:error, term()}
```

Alias for `send/2`.

# `start`

```elixir
@spec start(keyword()) :: {:ok, t()} | {:error, term()}
```

Starts an unlinked channel from normalized options.

# `start`

```elixir
@spec start(
  CliSubprocessCore.Command.t(),
  keyword()
) :: {:ok, t()} | {:error, term()}
```

Starts an unlinked channel from an invocation.

# `start`

```elixir
@spec start(String.t(), [String.t()], keyword()) :: {:ok, t()} | {:error, term()}
```

Starts an unlinked channel from an executable plus argv.

# `start_channel`

```elixir
@spec start_channel(keyword()) :: {:ok, pid(), info_t()} | {:error, term()}
```

Starts an unlinked channel and returns its initial info snapshot.

# `start_link`

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

Starts a linked channel from normalized options.

# `start_link`

```elixir
@spec start_link(
  CliSubprocessCore.Command.t(),
  keyword()
) :: GenServer.on_start()
```

Starts a linked channel from an invocation.

# `start_link`

```elixir
@spec start_link(String.t(), [String.t()], keyword()) :: GenServer.on_start()
```

Starts a linked channel from an executable plus argv.

# `start_link_channel`

```elixir
@spec start_link_channel(keyword()) :: {:ok, pid(), info_t()} | {:error, term()}
```

Starts a linked channel and returns its initial info snapshot.

# `status`

```elixir
@spec status(pid()) :: :connected | :disconnected | :error
```

Returns the channel status.

# `stderr`

```elixir
@spec stderr(pid()) :: binary()
```

Returns the latest stderr tail retained by the transport.

# `stop`

```elixir
@spec stop(pid()) :: :ok
```

Alias for `close/1`.

# `subscribe`

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

Subscribes a process in legacy mode.

# `subscribe`

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

Subscribes a process with an explicit tag.

# `unsubscribe`

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

Removes a subscriber.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
