Module: Ask::SessionProtocol::Host
- Defined in:
- lib/ask/session_protocol/host.rb
Overview
How the terminal client reaches a session host.
spawn — launch ask-app-server as a subprocess (stdio transport)
with a unix socket for multi-client attach; the
"embedded" mode: one host process owned by this client
connect — attach to an already-running host over its unix socket
(multi-client mode: web console, bots, and this terminal
share the same live sessions)
Defined Under Namespace
Classes: SpawnResult
Class Method Summary collapse
-
.connect(socket_path) ⇒ Client
Attach to an existing host over its unix socket.
-
.spawn(command: nil, args: [], socket: true, env: {}) ⇒ SpawnResult
Spawn ask-app-server as a subprocess and return a Client over its stdio.
Class Method Details
.connect(socket_path) ⇒ Client
Attach to an existing host over its unix socket.
62 63 64 65 66 |
# File 'lib/ask/session_protocol/host.rb', line 62 def self.connect(socket_path) require "socket" socket = UNIXSocket.new(socket_path) Client.new(input: socket, output: socket) end |
.spawn(command: nil, args: [], socket: true, env: {}) ⇒ SpawnResult
Spawn ask-app-server as a subprocess and return a Client over its stdio. By default the host also exposes a unix socket (unique per spawn under ~/.ask-app-server/sockets/) so other clients — the web console, bots, a second terminal — can attach to the same live sessions; the path is available on the result.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ask/session_protocol/host.rb', line 41 def self.spawn(command: nil, args: [], socket: true, env: {}) require "open3" command ||= begin Gem.bin_path("ask-app-server", "ask-app-server") rescue Gem::Exception "ask-app-server" end socket_path = resolve_socket_path(socket) spawn_args = args.dup spawn_args += ["--socket", socket_path] if socket_path stdin, stdout, stderr, wait_thread = Open3.popen3(env, command, *spawn_args) client = Client.new(input: stdout, output: stdin) SpawnResult.new(client: client, stderr: stderr, process: wait_thread, socket_path: socket_path) end |