Eai.Sandbox.PTYPool (eai v0.1.15)

Copy Markdown

GenServer pool managing per-session PTY processes and task dispatching.

Summary

Functions

Returns a specification to start this module under a supervisor.

Clear a completed task from PTY session state.

Execute command asynchronously in a PTY session.

Force reset a PTY session (kill processes, clear state).

Callback implementation for GenServer.init/1.

Set interrupt flag for a PTY session (injects Ctrl+C on next poll).

List all active PTY sessions.

Send raw input to PTY (for interactive prompts, Ctrl+C, etc.).

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

clear_task(pty_session_id, task_id)

Clear a completed task from PTY session state.

Internal use (cache cleanup).

Options

  • pty_session_id (string) — Session.
  • task_id (string) — Task to clear.

Returns

`:ok` or `{:error, reason}`

exec_async(pty_session_id, cmd, task_id \\ nil)

Execute command asynchronously in a PTY session.

Submits command to PTY, returns task_id immediately. Results collected via ResultCollector.get/1.

Options

  • pty_session_id (string) — PTY session for isolation. Default: "default"
  • cmd (string) — Shell command or script (may contain sentinels).
  • task_id (string, optional) — Custom task ID. Auto-generated if omitted.

Returns

`{:ok, task_id}` or `{:error, reason}`

Example

iex> Eai.Sandbox.PTYPool.exec_async("default", "ls -la")
{:ok, "task_1234567890"}

force_reset(pty_session_id)

Force reset a PTY session (kill processes, clear state).

Use after hang or corruption. PTY recreated on next command.

Options

  • pty_session_id (string) — Session to reset.

Returns

`:ok` or `{:error, reason}`

init(_)

Callback implementation for GenServer.init/1.

interrupt_task(pty_session_id)

Set interrupt flag for a PTY session (injects Ctrl+C on next poll).

Internal use (called by Chat.interrupt!).

Options

  • pty_session_id (string) — Session to interrupt.

Returns

`:ok` or `{:error, reason}`

list_sessions()

List all active PTY sessions.

Returns

List of session IDs: `["default", "task_1", ...]`

start_link(opts)

write_raw(pty_session_id, input)

Send raw input to PTY (for interactive prompts, Ctrl+C, etc.).

Options

  • pty_session_id (string) — Target session.
  • input (string) — Raw input to send. Supports escape sequences:
    • \n = newline, \r = carriage return, \t = tab
    • \x03 = Ctrl+C, \x04 = Ctrl+D, \x1a = Ctrl+Z

Example

iex> Eai.Sandbox.PTYPool.write_raw("default", "\x03")  # Send Ctrl+C
:ok