Class: SwarmSDK::V3::Tools::ReadTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/v3/tools/read_tracker.rb

Overview

Tracks which files have been read by each agent

Shared across Read, Write, and Edit tool instances for the same agent. Enforces read-before-write/edit rules to prevent accidental overwrites.

Examples:

tracker = ReadTracker.new
tracker.register_read(:backend, "/path/to/file.rb")
tracker.file_read?(:backend, "/path/to/file.rb")  #=> true

Instance Method Summary collapse

Constructor Details

#initializeReadTracker

Returns a new instance of ReadTracker.



16
17
18
# File 'lib/swarm_sdk/v3/tools/read_tracker.rb', line 16

def initialize
  @reads = Hash.new { |h, k| h[k] = Set.new }
end

Instance Method Details

#file_read?(agent_name, path) ⇒ Boolean

Check if an agent has read a file

Parameters:

  • agent_name (Symbol)

    Agent identifier

  • path (String)

    Absolute file path

Returns:

  • (Boolean)


34
35
36
# File 'lib/swarm_sdk/v3/tools/read_tracker.rb', line 34

def file_read?(agent_name, path)
  @reads[agent_name].include?(path)
end

#register_read(agent_name, path) ⇒ void

This method returns an undefined value.

Register that an agent has read a file

Parameters:

  • agent_name (Symbol)

    Agent identifier

  • path (String)

    Absolute file path



25
26
27
# File 'lib/swarm_sdk/v3/tools/read_tracker.rb', line 25

def register_read(agent_name, path)
  @reads[agent_name].add(path)
end