Class: Agent::Sessions::Location
- Inherits:
-
Data
- Object
- Data
- Agent::Sessions::Location
- 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
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#glob ⇒ Object
readonly
Returns the value of attribute glob.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#single_file ⇒ Object
readonly
Returns the value of attribute single_file.
Instance Method Summary collapse
- #enumerable? ⇒ Boolean
- #exists? ⇒ Boolean
- #files ⇒ Object
-
#initialize(kind:, path:, format:, glob: nil, single_file: false) ⇒ Location
constructor
A new instance of Location.
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
#format ⇒ Object (readonly)
Returns the value of attribute format
22 23 24 |
# File 'lib/agent/sessions/location.rb', line 22 def format @format end |
#glob ⇒ Object (readonly)
Returns the value of attribute glob
22 23 24 |
# File 'lib/agent/sessions/location.rb', line 22 def glob @glob end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
22 23 24 |
# File 'lib/agent/sessions/location.rb', line 22 def kind @kind end |
#path ⇒ Object (readonly)
Returns the value of attribute path
22 23 24 |
# File 'lib/agent/sessions/location.rb', line 22 def path @path end |
#single_file ⇒ Object (readonly)
Returns the value of attribute single_file
22 23 24 |
# File 'lib/agent/sessions/location.rb', line 22 def single_file @single_file end |
Instance Method Details
#enumerable? ⇒ Boolean
29 |
# File 'lib/agent/sessions/location.rb', line 29 def enumerable? = single_file || !glob.nil? |
#exists? ⇒ Boolean
27 |
# File 'lib/agent/sessions/location.rb', line 27 def exists? = File.exist?(path) |
#files ⇒ Object
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 |