Class: PromptObjects::CLI::REPL
- Inherits:
-
Object
- Object
- PromptObjects::CLI::REPL
- Defined in:
- lib/prompt_objects/cli/repl_command.rb
Overview
Simple REPL for interacting with a Prompt Object
Instance Method Summary collapse
-
#initialize(prompt_object, env, sandbox: nil) ⇒ REPL
constructor
A new instance of REPL.
- #run ⇒ Object
Constructor Details
#initialize(prompt_object, env, sandbox: nil) ⇒ REPL
Returns a new instance of REPL.
92 93 94 95 96 97 98 99 100 |
# File 'lib/prompt_objects/cli/repl_command.rb', line 92 def initialize(prompt_object, env, sandbox: nil) @po = prompt_object @env = env @context = env.context @show_log = true # Show message log by default @sandbox = sandbox @runtime_thread_id = nil @last_run_id = nil end |
Instance Method Details
#run ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/prompt_objects/cli/repl_command.rb', line 102 def run puts header if @sandbox puts "SANDBOX MODE - changes isolated from main project" puts end puts "Loaded: #{@po.name}" puts @po.description puts puts "Capabilities: #{format_capabilities}" puts "-" * 60 puts "Commands: 'exit', 'history', 'log', 'log on/off', 'sandbox' (if in sandbox mode)" puts loop do print "You: " input = $stdin.gets&.chomp break if input.nil? next if input.empty? case input.downcase when "exit", "quit" handle_exit break when "history" show_history next when "log" next when "log on" @show_log = true puts "Message log display: ON" next when "log off" @show_log = false puts "Message log display: OFF" next when "sandbox" show_sandbox_status next end # Clear log before each interaction to show only relevant messages log_start = @env.bus.log.length begin run, response = @env.( target_po: @po.name, content: input, from_source: "api:repl", thread_id: @runtime_thread_id, client_request_id: SecureRandom.uuid, tui_mode: true ) @runtime_thread_id = run.thread_id @last_run_id = run.id # Show the message log for this interaction if @show_log puts show_interaction_log(log_start) end puts puts "#{@po.name}: #{response}" puts rescue StandardError => e puts "\nError: #{e.}" puts e.backtrace.first(5).join("\n") if ENV["DEBUG"] puts end end end |