legion-apollo 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 618bc61aef669f5084bf63093f5ad71705adc70981cc267c66c17e47ca4f5a95
4
- data.tar.gz: 3170ead8864d7ca3ec97788d07e3e672eaf37c093ea70447516fe91f99a39c09
3
+ metadata.gz: fd344e49282eb4e397ce81a5920980466dea27d9b23cf4156f549280f46af768
4
+ data.tar.gz: 96b8d482992dbbe9d442bead192f128cf96dc776879cebd68e8b934b281c157e
5
5
  SHA512:
6
- metadata.gz: c819ce92195d179a520115219f650ddf43638905bcf0d522b74a87e09acfce7537a7c3a9f407f265a5f867486f3cac708c25ed989ed0ca28a1c6d26b5ea23746
7
- data.tar.gz: c27a2fbd299e4af232625efccaeb75b7bb2e54c925975df507e72d9e7d941383a3de9d87672ec3c5cc3816445a2c2f48e0c55c3a569126c47a4c04252fb677ed
6
+ metadata.gz: 35bc5fac20a5d153a54805d23a33218fed71177fe4b4f63724b527cc8fe3ca761912b617c0dc80380609d7eaa32a3197070525c9b08330f200343198ea01988d
7
+ data.tar.gz: 6b84f74fd517e4500d389fe51d9bd7f149abd96ccd4eaac2d110899f82ed6856be775f5a55c104a0f59cb92a974ba9da6237bc1bce16c564bd1725e738c3de43
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [Unreleased]
4
+
5
+ ### Added
6
+ - `Apollo::Local.promote_to_global(tags:, min_confidence:)` — promotes local entries to Apollo Global
7
+ - `Apollo::Local.query_by_tags(tags:, limit:)` — tag-only query (bypasses FTS5)
8
+ - `Apollo::Local.hydrate_from_global` — boots local store from global partner data with 0.9 confidence discount
9
+ - Boot hook: auto-hydrates partner data from global on first start
10
+
3
11
  ## [0.3.6] - 2026-03-31
4
12
 
5
13
  ### Added
@@ -131,6 +131,86 @@ module Legion
131
131
  @seeded == true
132
132
  end
133
133
 
134
+ def query_by_tags(tags:, limit: 50) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
135
+ return { success: false, error: :not_started } unless started?
136
+
137
+ candidates = db[:local_knowledge]
138
+ .where { expires_at > Time.now.utc.iso8601 }
139
+ .limit(limit)
140
+ .all
141
+
142
+ results = candidates.select do |row|
143
+ row_tags = parse_tags(row[:tags])
144
+ tags.all? { |t| row_tags.include?(t) }
145
+ end
146
+
147
+ { success: true, results: results, count: results.size }
148
+ rescue StandardError => e
149
+ { success: false, error: e.message }
150
+ end
151
+
152
+ def promote_to_global(tags:, min_confidence: 0.6) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
153
+ return { success: false, error: :not_started } unless started?
154
+
155
+ entries = query_by_tags(tags: tags)
156
+ return { success: true, promoted: 0 } unless entries[:success] && entries[:results]&.any?
157
+
158
+ promoted = 0
159
+ entries[:results].each do |entry|
160
+ next if entry[:confidence].to_f < min_confidence
161
+
162
+ entry_tags = parse_tags(entry[:tags])
163
+ hostname = ::Socket.gethostname rescue 'unknown' # rubocop:disable Style/RescueModifier
164
+ result = Legion::Apollo.ingest(
165
+ content: entry[:content],
166
+ tags: entry_tags + ['promoted_from_local'],
167
+ source_channel: 'local_promotion',
168
+ submitted_by: "node:#{hostname}",
169
+ confidence: entry[:confidence],
170
+ scope: :global
171
+ )
172
+ promoted += 1 if result[:success]
173
+ end
174
+
175
+ { success: true, promoted: promoted }
176
+ rescue StandardError => e
177
+ { success: false, error: e.message }
178
+ end
179
+
180
+ def hydrate_from_global # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
181
+ return { success: false, error: :not_started } unless started?
182
+
183
+ local_check = query_by_tags(tags: ['partner'])
184
+ return { success: true, skipped: :local_data_exists } if local_check[:success] && local_check[:results]&.any?
185
+
186
+ unless Legion::Apollo.transport_available? || Legion::Apollo.data_available?
187
+ return { success: true, skipped: :global_unavailable }
188
+ end
189
+
190
+ global_entries = Legion::Apollo.retrieve(text: 'partner bond', scope: :global, limit: 20)
191
+ unless global_entries[:success] && global_entries[:results]&.any?
192
+ return { success: true, skipped: :no_global_data }
193
+ end
194
+
195
+ hydrated = 0
196
+ global_entries[:results].each do |entry|
197
+ entry_tags = entry[:tags].is_a?(Array) ? entry[:tags] : []
198
+ clean_tags = entry_tags.reject { |t| t == 'promoted_from_local' } + ['hydrated_from_global']
199
+
200
+ result = ingest(
201
+ content: entry[:content],
202
+ tags: clean_tags,
203
+ confidence: ((entry[:confidence] || 0.5) * 0.9).round(10),
204
+ source_channel: 'global_hydration'
205
+ )
206
+ hydrated += 1 if result[:success]
207
+ end
208
+
209
+ { success: true, hydrated: hydrated }
210
+ rescue StandardError => e
211
+ { success: false, error: e.message }
212
+ end
213
+
134
214
  private
135
215
 
136
216
  def self_knowledge_files
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module Apollo
5
- VERSION = '0.3.6'
5
+ VERSION = '0.3.7'
6
6
  end
7
7
  end
data/lib/legion/apollo.rb CHANGED
@@ -27,6 +27,7 @@ module Legion
27
27
  register_routes
28
28
  Legion::Apollo::Local.start
29
29
  seed_self_knowledge
30
+ Legion::Apollo::Local.hydrate_from_global if Legion::Apollo::Local.started?
30
31
  end
31
32
 
32
33
  def shutdown
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-apollo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity