Class: OllamaAgent::UserPrompt

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/user_prompt.rb

Overview

Injectable stdin/stdout for patch/write/delegate confirmations (tests use StringIO). rubocop:disable Naming/PredicateMethod – confirm_* are interactive prompts returning bool

Instance Method Summary collapse

Constructor Details

#initialize(stdin: $stdin, stdout: $stdout) ⇒ UserPrompt

Returns a new instance of UserPrompt.



7
8
9
10
# File 'lib/ollama_agent/user_prompt.rb', line 7

def initialize(stdin: $stdin, stdout: $stdout)
  @stdin = stdin
  @stdout = stdout
end

Instance Method Details

#confirm_delegate(agent_id, task) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/ollama_agent/user_prompt.rb', line 26

def confirm_delegate(agent_id, task)
  @stdout.puts Console.patch_title("Delegate to #{agent_id}:")
  @stdout.puts task.to_s[0, 2000]
  @stdout.puts "..." if task.to_s.length > 2000
  @stdout.print Console.apply_prompt("Run external agent? (y/n) ")
  @stdin.gets.to_s.chomp.casecmp("y").zero?
end

#confirm_patch(path, diff) ⇒ Object



12
13
14
15
16
17
# File 'lib/ollama_agent/user_prompt.rb', line 12

def confirm_patch(path, diff)
  @stdout.puts Console.patch_title("Proposed diff for #{path}:")
  @stdout.puts diff
  @stdout.print Console.apply_prompt("Apply? (y/n) ")
  @stdin.gets.to_s.chomp.casecmp("y").zero?
end

#confirm_write_file(path, content_preview) ⇒ Object



19
20
21
22
23
24
# File 'lib/ollama_agent/user_prompt.rb', line 19

def confirm_write_file(path, content_preview)
  @stdout.puts Console.patch_title("Proposed write_file for #{path}:")
  @stdout.puts content_preview
  @stdout.print Console.apply_prompt("Write file? (y/n) ")
  @stdin.gets.to_s.chomp.casecmp("y").zero?
end