Class: OllamaAgent::CLI::Repl
- Inherits:
-
Object
- Object
- OllamaAgent::CLI::Repl
- Includes:
- ReplShared
- Defined in:
- lib/ollama_agent/cli/repl.rb
Overview
Interactive REPL for the agent.
Features:
- Slash commands (/help, /model, /models, /session, /memory, /status, /clear, /config, /provider, /index)
- Readline history with persistent file
- Multi-line input (end with blank line)
- Session resume inside REPL
- Token budget and loop-detector status display
- Graceful Ctrl-C and Ctrl-D handling
rubocop:disable Metrics/ClassLength – readline wiring + banner + history
Constant Summary collapse
- HISTORY_FILE =
File.join(Dir.home, ".config", "ollama_agent", "repl_history")
- MAX_HISTORY =
500- PROMPT =
"\e[32mollama\e[0m \e[90m›\e[0m "
Constants included from ReplShared
OllamaAgent::CLI::ReplShared::SLASH_COMMANDS
Instance Method Summary collapse
-
#initialize(agent:, memory: nil, budget: nil, stdout: $stdout, stderr: $stderr) ⇒ Repl
constructor
A new instance of Repl.
-
#start ⇒ Object
rubocop:disable Metrics/MethodLength – readline loop + history ensure.
Constructor Details
#initialize(agent:, memory: nil, budget: nil, stdout: $stdout, stderr: $stderr) ⇒ Repl
Returns a new instance of Repl.
27 28 29 30 31 32 33 34 |
# File 'lib/ollama_agent/cli/repl.rb', line 27 def initialize(agent:, memory: nil, budget: nil, stdout: $stdout, stderr: $stderr) @agent = agent @memory = memory @budget = budget @stdout = stdout @stderr = stderr @running = false end |
Instance Method Details
#start ⇒ Object
rubocop:disable Metrics/MethodLength – readline loop + history ensure
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ollama_agent/cli/repl.rb', line 37 def start @running = true setup_readline loop do input = read_line break if input.nil? line = input.chomp.strip next if line.empty? break if %w[/exit exit].include?(line) if line.start_with?("/") handle_slash(line) else run_query(line) end end @stdout.puts "\n\e[90mGoodbye.\e[0m" ensure save_history end |