Class: Legion::CLI::Apollo

Inherits:
Thor
  • Object
show all
Defined in:
lib/legion/cli/apollo_command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/legion/cli/apollo_command.rb', line 9

def self.exit_on_failure?
  true
end

Instance Method Details

#ingest(content) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/legion/cli/apollo_command.rb', line 74

def ingest(content)
  body = {
    content:          content,
    content_type:     options[:content_type],
    tags:             options[:tags]&.split(',') || [],
    source_agent:     'cli',
    source_channel:   'cli',
    knowledge_domain: options[:domain]
  }
  data = api_post('/api/apollo/ingest', body)
  if options[:json]
    formatter.json(data)
  else
    formatter.header('Apollo Ingest')
    if data[:success]
      formatter.success("Entry created (id: #{data[:id]})")
    else
      formatter.warn("Ingest failed: #{data[:error]}")
    end
  end
end

#maintain(action) ⇒ Object



97
98
99
100
101
102
103
104
105
# File 'lib/legion/cli/apollo_command.rb', line 97

def maintain(action)
  data = api_post('/api/apollo/maintenance', { action: action })
  if options[:json]
    formatter.json(data)
  else
    formatter.header("Apollo Maintenance: #{action}")
    formatter.detail(data.transform_values(&:to_s))
  end
end

#query(search_query) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/legion/cli/apollo_command.rb', line 54

def query(search_query)
  body = { query: search_query, limit: options[:limit], domain: options[:domain] }
  data = api_post('/api/apollo/query', body)
  if options[:json]
    formatter.json(data)
  else
    entries = data[:entries] || []
    formatter.header("Apollo Query (#{entries.size} results)")
    entries.each_with_index do |entry, idx|
      puts "  #{idx + 1}. [#{entry[:content_type]}] #{truncate(entry[:content].to_s, 120)}"
      puts "     confidence: #{entry[:confidence]} | status: #{entry[:status]}"
    end
    puts '  No results found.' if entries.empty?
  end
end

#statsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/legion/cli/apollo_command.rb', line 34

def stats
  data = api_get('/api/apollo/stats')
  if options[:json]
    formatter.json(data)
  else
    formatter.header('Apollo Knowledge Graph')
    formatter.detail({
                       'Total Entries'  => (data[:total_entries] || 0).to_s,
                       'Recent (24h)'   => (data[:recent_24h] || 0).to_s,
                       'Avg Confidence' => (data[:avg_confidence] || 0.0).to_s
                     })

    show_breakdown('By Status', data[:by_status]) if data[:by_status]
    show_breakdown('By Content Type', data[:by_content_type]) if data[:by_content_type]
  end
end

#statusObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/legion/cli/apollo_command.rb', line 19

def status
  data = api_get('/api/apollo/status')
  if options[:json]
    formatter.json(data)
  else
    formatter.header('Apollo Status')
    formatter.detail({
                       'Available'      => (data[:available] || false).to_s,
                       'Data Connected' => (data[:data_connected] || false).to_s
                     })
  end
end