Class: RubynCode::Tools::TodoWrite

Inherits:
Base
  • Object
show all
Defined in:
lib/rubyn_code/tools/todo_write.rb

Overview

Update the in-turn task checklist. The model uses this to keep the user informed of progress while it works. The store is shared between the Agent::Loop (which exposes it for the renderer) and this tool.

Constant Summary collapse

TOOL_NAME =
'TodoWrite'
DESCRIPTION =
'Update the in-turn task checklist. ' \
'Use this to keep the user informed of what you plan to do, ' \
'what you are currently working on, and what you have finished.'
PARAMETERS =
{
  todos: { type: :array, required: true,
           description: 'The full set of tasks currently on the checklist. ' \
                        'Replace the existing list with this. Each task is ' \
                        '{ "content": "...", "status": "pending|in_progress|completed", ' \
                        '"active_form": "..." }.' }
}.freeze
RISK_LEVEL =
:read
REQUIRES_CONFIRMATION =
false
VALID_STATUS =
%w[pending in_progress completed].freeze

Instance Attribute Summary

Attributes inherited from Base

#project_root

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

description, parameters, requires_confirmation?, risk_level, #safe_path, to_schema, tool_name, #truncate

Constructor Details

#initialize(project_root:, store: nil) ⇒ TodoWrite

Returns a new instance of TodoWrite.



28
29
30
31
# File 'lib/rubyn_code/tools/todo_write.rb', line 28

def initialize(project_root:, store: nil)
  super(project_root: project_root)
  @store = store
end

Class Method Details

.summarize(_output, args) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/rubyn_code/tools/todo_write.rb', line 60

def self.summarize(_output, args)
  count = Array(args[:todos] || args['todos']).size
  if count.zero?
    'cleared checklist'
  else
    "checklist: #{count} item#{'s' unless count == 1}"
  end
end

Instance Method Details

#execute(todos:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rubyn_code/tools/todo_write.rb', line 33

def execute(todos:)
  items = Array(todos)
  validated = []

  items.each_with_index do |item, i|
    return "TodoWrite: item #{i} is not a hash — got #{item.class}" unless item.is_a?(Hash)

    content = item[:content] || item['content']
    status  = (item[:status] || item['status']).to_s
    active_form = item[:active_form] || item['active_form']

    return "TodoWrite: item #{i} missing 'content'" if content.to_s.empty?
    unless VALID_STATUS.include?(status)
      return "TodoWrite: item #{i} status must be one of #{VALID_STATUS.join('/')} (got #{status.inspect})"
    end

    validated << {
      'content' => content.to_s,
      'status' => status,
      'active_form' => active_form.to_s.empty? ? content.to_s : active_form.to_s
    }
  end

  @store&.replace(validated)
  format(validated)
end