Class: RubynCode::Tools::ReadInbox

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

Overview

Tool for reading unread messages from a teammate’s inbox.

Constant Summary collapse

TOOL_NAME =
'read_inbox'
DESCRIPTION =
"Reads all unread messages from the agent's inbox and marks them as read."
PARAMETERS =
{
  name: { type: :string, required: true, description: 'The agent name whose inbox to read' }
}.freeze
RISK_LEVEL =
:read
REQUIRES_CONFIRMATION =
false

Instance Attribute Summary

Attributes inherited from Base

#project_root

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(project_root:, mailbox:) ⇒ ReadInbox

Returns a new instance of ReadInbox.

Parameters:

  • project_root (String)
  • mailbox (Teams::Mailbox)

    the team mailbox instance



20
21
22
23
# File 'lib/rubyn_code/tools/read_inbox.rb', line 20

def initialize(project_root:, mailbox:)
  super(project_root: project_root)
  @mailbox = mailbox
end

Instance Method Details

#execute(name:) ⇒ String

Reads and returns all unread messages for the given agent.

Parameters:

  • name (String)

    the reader’s agent name

Returns:

  • (String)

    formatted messages or a notice if the inbox is empty

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubyn_code/tools/read_inbox.rb', line 29

def execute(name:)
  raise Error, 'Agent name is required' if name.nil? || name.strip.empty?

  messages = @mailbox.read_inbox(name)

  return "No unread messages for '#{name}'." if messages.empty?

  formatted = messages.map.with_index(1) do |msg, idx|
    format_message(idx, msg)
  end

  header = "#{messages.size} message#{'s' if messages.size != 1} for '#{name}':\n"
  header + formatted.join("\n")
end