Class: Ask::Terminal::Repl
- Inherits:
-
Object
- Object
- Ask::Terminal::Repl
- Defined in:
- lib/ask/terminal/repl.rb
Overview
The interactive terminal coding agent: a thin client of the session protocol. Owns one session with the host and drives it entirely through canonical requests and events:
prompt → session/send → stream events → turn ends → prompt again
Human-in-the-loop events are handled inline: approvals ask y/n, plan proposals ask approve/reject, and both resolve through the canonical interaction/plan methods — the same requests any other client (web console, bot) would make.
Instance Method Summary collapse
-
#initialize(client:, input: $stdin, output: $stdout, workspace: Dir.pwd, model: nil, approval: "on_request") ⇒ Repl
constructor
A new instance of Repl.
-
#run ⇒ Object
Connect to the host, create a session, and run the interactive loop.
Constructor Details
#initialize(client:, input: $stdin, output: $stdout, workspace: Dir.pwd, model: nil, approval: "on_request") ⇒ Repl
Returns a new instance of Repl.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ask/terminal/repl.rb', line 22 def initialize(client:, input: $stdin, output: $stdout, workspace: Dir.pwd, model: nil, approval: "on_request") @client = client @input = input @output = output @workspace = workspace @model = model @approval = approval @session_id = nil @turn_active = false end |
Instance Method Details
#run ⇒ Object
Connect to the host, create a session, and run the interactive loop. Returns when the user exits (/exit or EOF).
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ask/terminal/repl.rb', line 36 def run handshake = @client.initialize! @server_info = handshake["server"] || {} created = @client.create_session( workspace_path: @workspace, mode: @approval, model: @model ) @session_id = created.dig("session", "sessionId") @client.subscribe(@session_id, after_seq: 0) main_loop rescue Client::ConnectionClosed @output.puts "\n#{Renderer::RED}host closed the connection#{Renderer::RESET}" end |