Class: RubynCode::Tools::MemoryWrite

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

Constant Summary collapse

TOOL_NAME =
'memory_write'
DESCRIPTION =
'Writes a new memory to the project memory store. ' \
'Use this to persist code patterns, user preferences, project conventions, ' \
'error resolutions, or architectural decisions for future reference.'
PARAMETERS =
{
  content: { type: :string, required: true, description: 'The memory content to store' },
  tier: { type: :string, required: false,
          description: 'Memory retention tier: short, medium (default), or long' },
  category: { type: :string, required: false,
              description: 'Category: code_pattern, user_preference, ' \
                           'project_convention, error_resolution, or decision' }
}.freeze
RISK_LEVEL =

Memory is internal — no user approval needed

:read

Constants inherited from Base

Base::REQUIRES_CONFIRMATION

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:, memory_store: nil) ⇒ MemoryWrite

Returns a new instance of MemoryWrite.

Parameters:

  • project_root (String)
  • memory_store (Memory::Store) (defaults to: nil)

    injected store instance



25
26
27
28
# File 'lib/rubyn_code/tools/memory_write.rb', line 25

def initialize(project_root:, memory_store: nil)
  super(project_root: project_root)
  @memory_store = memory_store
end

Instance Method Details

#execute(content:, tier: 'medium', category: nil) ⇒ String

Returns confirmation message.

Parameters:

  • content (String)
  • tier (String) (defaults to: 'medium')

    defaults to “medium”

  • category (String, nil) (defaults to: nil)

Returns:

  • (String)

    confirmation message



34
35
36
37
38
39
40
# File 'lib/rubyn_code/tools/memory_write.rb', line 34

def execute(content:, tier: 'medium', category: nil)
  store = @memory_store || resolve_memory_store
  record = store.write(content: content, tier: tier, category: category)

  "Memory saved (ID: #{record.id}, tier: #{record.tier}" \
    "#{", category: #{record.category}" if record.category})."
end