Class: RubynCode::Tools::TodoStore

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/rubyn_code/tools/todo_store.rb

Overview

Shared, thread-safe checklist store. The Agent::Loop owns one instance and exposes it to (a) the renderer so the user sees what's in flight, and (b) the TodoWrite tool so the model can mutate it.

Defined Under Namespace

Classes: Item

Instance Method Summary collapse

Constructor Details

#initializeTodoStore

Returns a new instance of TodoStore.



13
14
15
16
# File 'lib/rubyn_code/tools/todo_store.rb', line 13

def initialize
  super
  @items = []
end

Instance Method Details

#clearObject



34
35
36
# File 'lib/rubyn_code/tools/todo_store.rb', line 34

def clear
  synchronize { @items = [] }
end

#currentObject



30
31
32
# File 'lib/rubyn_code/tools/todo_store.rb', line 30

def current
  synchronize { @items.map(&:to_h) }
end

#empty?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rubyn_code/tools/todo_store.rb', line 38

def empty?
  current.empty?
end

#renderObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rubyn_code/tools/todo_store.rb', line 42

def render
  current.map do |item|
    mark =
      case item[:status]
      when 'completed' then ''
      when 'in_progress' then '[~]'
      else '[ ]'
      end
    "#{mark} #{item[:content]}"
  end.join("\n")
end

#replace(items) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubyn_code/tools/todo_store.rb', line 18

def replace(items)
  synchronize do
    @items = items.map do |item|
      Item.new(
        content: item['content'] || item[:content],
        status: item['status'] || item[:status],
        active_form: (item['active_form'] || item[:active_form]).to_s
      )
    end
  end
end