Module: Legion::Extensions::Coldstart::Runners::Ingest

Includes:
Helpers::Lex
Defined in:
lib/legion/extensions/coldstart/runners/ingest.rb

Instance Method Summary collapse

Instance Method Details

#ingest_directory(dir_path:, pattern: '**/{CLAUDE,MEMORY}.md', store_traces: true) ⇒ Hash

Ingest all CLAUDE.md and MEMORY.md files under a directory.

Parameters:

  • dir_path (String)

    absolute path to the directory

  • pattern (String) (defaults to: '**/{CLAUDE,MEMORY}.md')

    glob pattern (default: '**/CLAUDE,MEMORY.md')

  • store_traces (Boolean) (defaults to: true)

    whether to store into agentic memory (default: true)

Returns:

  • (Hash)

    { directory:, files_found:, total_parsed:, total_stored:, files: }



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/extensions/coldstart/runners/ingest.rb', line 44

def ingest_directory(dir_path:, pattern: '**/{CLAUDE,MEMORY}.md', store_traces: true, **)
  unless Dir.exist?(dir_path)
    log.warn "[coldstart:ingest] directory not found: #{dir_path}"
    return { directory: dir_path, error: 'directory not found' }
  end

  candidates = Helpers::ClaudeParser.parse_directory(dir_path, pattern: pattern)
  files = candidates.map { |c| c[:source_file] }.uniq
  log.info "[coldstart:ingest] parsed #{candidates.size} traces from #{files.size} files in #{dir_path}"

  stored = store_traces ? store_candidates(candidates) : []

  {
    directory:    dir_path,
    files_found:  files.size,
    total_parsed: candidates.size,
    total_stored: stored.size,
    files:        files
  }
end

#ingest_file(file_path:, store_traces: true) ⇒ Hash

Ingest a single Claude memory or CLAUDE.md file into agentic memory traces. If lex-agentic-memory is not loaded, returns the parsed traces without storing.

Parameters:

  • file_path (String)

    absolute path to the markdown file

  • store_traces (Boolean) (defaults to: true)

    whether to store into agentic memory (default: true)

Returns:

  • (Hash)

    { file:, file_type:, traces_parsed:, traces_stored:, traces: }



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/legion/extensions/coldstart/runners/ingest.rb', line 17

def ingest_file(file_path:, store_traces: true, **)
  unless File.exist?(file_path)
    log.warn "[coldstart:ingest] file not found: #{file_path}"
    return { file: file_path, error: 'file not found' }
  end

  candidates = Helpers::ClaudeParser.parse_file(file_path)
  file_type = Helpers::ClaudeParser.detect_file_type(file_path)
  log.info "[coldstart:ingest] parsed #{candidates.size} traces from #{file_path} (#{file_type})"

  stored = store_traces ? store_candidates(candidates) : []

  {
    file:          file_path,
    file_type:     file_type,
    traces_parsed: candidates.size,
    traces_stored: stored.size,
    traces:        stored.empty? ? candidates : stored
  }
end

#preview_ingest(file_path:) ⇒ Hash

Preview what traces would be created from a file without storing them.

Parameters:

  • file_path (String)

    absolute path to the markdown file

Returns:

  • (Hash)

    { file:, file_type:, traces: }



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/legion/extensions/coldstart/runners/ingest.rb', line 69

def preview_ingest(file_path:, **)
  return { file: file_path, error: 'file not found' } unless File.exist?(file_path)

  candidates = Helpers::ClaudeParser.parse_file(file_path)
  file_type = Helpers::ClaudeParser.detect_file_type(file_path)

  {
    file:      file_path,
    file_type: file_type,
    traces:    candidates
  }
end