Class: Agent::Sessions::Location

Inherits:
Data
  • Object
show all
Defined in:
lib/agent/sessions/location.rb

Overview

One resolved layer of an agent's store.

A location is one of three shapes, and files answers each differently:

glob         a directory plus a pattern       -> the pattern's matches
single_file  one file (a `path:` store)       -> itself, if it is there
directory    a directory with no known shape  -> nothing, and enumerable? is false

The third shape is a store whose internal layout this gem has not learned yet (opencode's pre-1.2.0 storage/ tree, Cursor's acp-sessions/). It returns [] so a caller sweeping every layer does not blow up, and answers enumerable? false so that caller can tell "nothing here to enumerate" apart from "enumerated, found none".

single_file comes from the adapter's store DSL: path: means one file, dir: means a directory. Resolution used to discard that distinction, which made a Layer 2 enumerator written as layers.flat_map(&:files) silently skip history.jsonl, session_index.jsonl and secrets.json — a missing-session bug, not a visible error.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, path:, format:, glob: nil, single_file: false) ⇒ Location

Returns a new instance of Location.



23
24
25
# File 'lib/agent/sessions/location.rb', line 23

def initialize(kind:, path:, format:, glob: nil, single_file: false)
  super
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format

Returns:

  • (Object)

    the current value of format



22
23
24
# File 'lib/agent/sessions/location.rb', line 22

def format
  @format
end

#globObject (readonly)

Returns the value of attribute glob

Returns:

  • (Object)

    the current value of glob



22
23
24
# File 'lib/agent/sessions/location.rb', line 22

def glob
  @glob
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



22
23
24
# File 'lib/agent/sessions/location.rb', line 22

def kind
  @kind
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



22
23
24
# File 'lib/agent/sessions/location.rb', line 22

def path
  @path
end

#single_fileObject (readonly)

Returns the value of attribute single_file

Returns:

  • (Object)

    the current value of single_file



22
23
24
# File 'lib/agent/sessions/location.rb', line 22

def single_file
  @single_file
end

Instance Method Details

#enumerable?Boolean

Returns:

  • (Boolean)


29
# File 'lib/agent/sessions/location.rb', line 29

def enumerable? = single_file || !glob.nil?

#exists?Boolean

Returns:

  • (Boolean)


27
# File 'lib/agent/sessions/location.rb', line 27

def exists? = File.exist?(path)

#filesObject



31
32
33
34
35
36
37
38
# File 'lib/agent/sessions/location.rb', line 31

def files
  return exists? ? [path] : [] if single_file
  return [] unless glob

  Dir.glob(File.join(escaped_path, glob))
rescue Errno::ENOENT, Errno::EACCES, Errno::ELOOP
  []
end