Class: ActiveHarness::Memory::JsonFile
- Inherits:
-
ActiveHarness::Memory
- Object
- ActiveHarness::Memory
- ActiveHarness::Memory::JsonFile
- Defined in:
- lib/active_harness/memory/json_file.rb
Overview
File-backed memory with a path-safe file_name interface.
Differences from the base Memory class:
- file_name: replaces session_id — may contain slashes to create
subdirectories under storage_path, e.g. "users/42/chat"
Final file is always <storage_path>/<file_name>.json
- storage_path: replaces the adapter-level path: option
- adapter: always :file — no other adapter can be passed
Path traversal is rejected: segments equal to “.” or “..” or containing null bytes raise ArgumentError before any file I/O happens. Missing directories are created automatically on the first write.
Constant Summary collapse
- DEFAULT_STORAGE_PATH =
"storage/ai/memory"
Constants inherited from ActiveHarness::Memory
Instance Attribute Summary
Attributes inherited from ActiveHarness::Memory
Instance Method Summary collapse
-
#initialize(file_name:, storage_path: DEFAULT_STORAGE_PATH, **opts) ⇒ JsonFile
constructor
A new instance of JsonFile.
Methods inherited from ActiveHarness::Memory
#clear, #close, #delete, #load, #record, #size, #to_messages, #turns
Constructor Details
#initialize(file_name:, storage_path: DEFAULT_STORAGE_PATH, **opts) ⇒ JsonFile
Returns a new instance of JsonFile.
18 19 20 21 22 23 24 25 |
# File 'lib/active_harness/memory/json_file.rb', line 18 def initialize(file_name:, storage_path: DEFAULT_STORAGE_PATH, **opts) super( session_id: sanitize!(file_name), adapter: :file, path: storage_path, **opts ) end |