Class: Ask::Agent::TodoWrite

Inherits:
Tool
  • Object
show all
Defined in:
lib/ask/agent/todo_write.rb

Overview

Tool that maintains the session's task list (TodoList). The model writes and updates todos as it works; every result returns the full list, so one call both mutates and shows state. A TodoUpdated event fires on every change for live rendering.

Injected into the session by Session.new(todos: true).

Instance Method Summary collapse

Constructor Details

#initialize(todo_list:) ⇒ TodoWrite

Returns a new instance of TodoWrite.

Parameters:



25
26
27
28
# File 'lib/ask/agent/todo_write.rb', line 25

def initialize(todo_list:)
  @todo_list = todo_list
  super()
end

Instance Method Details

#execute(action:, title: nil, id: nil, status: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ask/agent/todo_write.rb', line 30

def execute(action:, title: nil, id: nil, status: nil)
  case action
  when "add"
    @todo_list.add(title, status: status)
  when "update"
    @todo_list.update(id, status: status, title: title)
  when "list"
    # no-op — the result carries the full list
  when "clear"
    @todo_list.clear
  else
    return Ask::Result.error(message: "Unknown action #{action.inspect}; valid: add, update, list, clear")
  end

  Ask::Result.ok(data: format_list)
rescue ArgumentError => e
  Ask::Result.error(message: e.message)
end