Class: ClaudeMemory::Ingest::ObservationCompressor

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_memory/ingest/observation_compressor.rb

Overview

Compresses tool call observations into human-readable summaries. Reduces ~70% token usage vs raw tool I/O in provenance descriptions.

Examples:

compressor = ObservationCompressor.new
summary = compressor.compress("Edit", '{"file_path":"/src/auth.rb","old_string":"def login","new_string":"def async_login"}')
# => "Edited auth.rb: 'def login' → 'def async_login'"

Constant Summary collapse

MAX_SUMMARY_LENGTH =
200

Instance Method Summary collapse

Instance Method Details

#compress(tool_name, tool_input_json) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/claude_memory/ingest/observation_compressor.rb', line 17

def compress(tool_name, tool_input_json)
  return nil if tool_input_json.nil? || tool_input_json.empty?

  input = parse_input(tool_input_json)
  return nil unless input

  summary = case tool_name
  when "Edit"
    compress_edit(input)
  when "Write"
    compress_write(input)
  when "Bash"
    compress_bash(input)
  when "Read"
    compress_read(input)
  when "Glob"
    compress_glob(input)
  when "Grep"
    compress_grep(input)
  when "Task"
    compress_task(input)
  when "WebFetch"
    compress_web_fetch(input)
  when "WebSearch"
    compress_web_search(input)
  when "NotebookEdit"
    compress_notebook_edit(input)
  else
    compress_generic(tool_name, input)
  end

  truncate(summary)
end