Class: OllamaAgent::RuntimeCommandSystem::GhostTextRenderer

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

Overview

Computes visual-only inline completions without mutating the edit buffer.

Instance Method Summary collapse

Constructor Details

#initialize(suggestion_engine) ⇒ GhostTextRenderer

Returns a new instance of GhostTextRenderer.



9
10
11
# File 'lib/ollama_agent/runtime_command_system/ghost_text.rb', line 9

def initialize(suggestion_engine)
  @suggestion_engine = suggestion_engine
end

Instance Method Details

#ghost_text(input:, cursor_pos: nil, session: {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ollama_agent/runtime_command_system/ghost_text.rb', line 13

def ghost_text(input:, cursor_pos: nil, session: {})
  text = input.to_s
  suggestions = @suggestion_engine.complete(input: text, cursor_pos: cursor_pos || text.length, session: session)
  suggestion = suggestions.first
  return nil unless suggestion

  start = suggestion.replacement_start
  typed = text[start..] || ""
  return nil unless suggestion.text.start_with?(typed)

  suffix = suggestion.text[typed.length..]
  return nil if suffix.nil? || suffix.empty?

  GhostText.new(
    suffix: suffix,
    full_completion: "#{text[0...start]}#{suggestion.text}",
    suggestion: suggestion
  )
end