Class: LLM::Repl::Status Private

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/repl/status.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The LLM::Repl::Status class stores the small status line shown at the top of the REPL.

The status text can be a plain String, a single LLM::Repl::Node (text plus curses attributes), or an Array of either. Attributes on nodes are applied when the window draws the status line.

Instance Method Summary collapse

Constructor Details

#initialize(repl) ⇒ LLM::Repl::Status

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



17
18
19
20
21
22
# File 'lib/llm/repl/status.rb', line 17

def initialize(repl)
  @repl = repl
  @agent = repl.agent
  @provider = @agent.llm.name
  @nodes = [Node.new("idle")]
end

Instance Method Details

#context_barString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


26
27
28
29
30
31
32
33
34
# File 'lib/llm/repl/status.rb', line 26

def context_bar
  LLM::Repl::Bar.new(
    ##
    # After compaction the used context is unknown until the next
    # response, so the bar renders an unknown state instead of a
    # stale percentage.
    fraction: @agent.compacted? ? nil : @agent.context_usage
  ).to_s
end

#costString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


38
39
40
# File 'lib/llm/repl/status.rb', line 38

def cost
  "$#{@agent.cost} "
end

#cwdLLM::Repl::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current working directory.

Returns:



52
53
54
# File 'lib/llm/repl/status.rb', line 52

def cwd
  Node.new Dir.pwd.sub(Dir.home, "~"), Curses::A_BOLD
end

#modelLLM::Repl::Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current model in use.

Returns:



45
46
47
# File 'lib/llm/repl/status.rb', line 45

def model
  Node.new @repl.model.to_s, Curses::A_BOLD
end

#nodesArray<LLM::Repl::Node>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The nodes making up the status line.

Returns:



82
83
84
85
86
87
88
# File 'lib/llm/repl/status.rb', line 82

def nodes
  if @agent.compacted?
    [Node.new("Context compacted")]
  else
    @nodes
  end
end

#textString Also known as: to_s

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


71
72
73
# File 'lib/llm/repl/status.rb', line 71

def text
  @nodes.map(&:text).join
end

#text=(value) ⇒ Array<LLM::Repl::Node>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Sets the status text.

Parameters:

Returns:



60
61
62
63
64
65
66
67
# File 'lib/llm/repl/status.rb', line 60

def text=(value)
  @nodes =
    case value
    when Node then [value]
    when Array then value.map { |node| Node === node ? node : Node.new(node) }
    else [Node.new(value)]
    end
end