lex-agentic-imagination 0.1.4 → 0.1.8
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 +4 -4
- data/CHANGELOG.md +24 -1
- data/README.md +2 -2
- data/lib/legion/extensions/agentic/imagination/alchemy/helpers/constants.rb +2 -2
- data/lib/legion/extensions/agentic/imagination/constellation/helpers/constants.rb +2 -2
- data/lib/legion/extensions/agentic/imagination/dream/helpers/constants.rb +1 -0
- data/lib/legion/extensions/agentic/imagination/dream/helpers/dream_journal.rb +17 -2
- data/lib/legion/extensions/agentic/imagination/dream/helpers/llm_enhancer.rb +22 -3
- data/lib/legion/extensions/agentic/imagination/dream/runners/dream_cycle.rb +93 -0
- data/lib/legion/extensions/agentic/imagination/dream/version.rb +1 -1
- data/lib/legion/extensions/agentic/imagination/garden/helpers/constants.rb +2 -2
- data/lib/legion/extensions/agentic/imagination/version.rb +1 -1
- data/spec/legion/extensions/agentic/imagination/dream/runners/dream_cycle_spec.rb +50 -2
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e50d0cb324b64593bf8ac064273feba7c453af93923ab022025bcc2d0f07afad
|
|
4
|
+
data.tar.gz: 1b75ce86a846fa3fd91c119ef0934702ca21b79eab9da0e34cfdb25440ee2f24
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ea955c3ead922c989acbfaf189c402488a79cd58da007c1d3ab02986b88099fe117d87c2f1950eff0f3bfbc9571c5b05fa3b6a707231cbb01b2f16e257c5f86
|
|
7
|
+
data.tar.gz: a4be072f0d3b3654fef4bd89a6308f0000543888ef164cf8877901bd50d5d10e0c69dfe0d15eb0612e2c6ef6a76f4513416802dad75e9497dea42d1937490cfc
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
-
## [
|
|
3
|
+
## [0.1.8] - 2026-03-24
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Remove redundant parentheses around beginless ranges in alchemy, constellation, and garden constants (rubocop Style/RedundantParentheses)
|
|
7
|
+
|
|
8
|
+
## [0.1.7] - 2026-03-24
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Mind Growth integration in `phase_agenda_formation`: calls `MindGrowth::Runners::DreamIdeation.dream_agenda_items` when available and injects architectural gap items into the dream agenda
|
|
12
|
+
- `mind_growth_available?` private guard method using `defined?()` for safe optional dependency check
|
|
13
|
+
- Errors from MindGrowth are rescued and logged as warnings so agenda formation always continues
|
|
14
|
+
|
|
15
|
+
## [0.1.6] - 2026-03-23
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- route llm calls through pipeline when available, add caller identity for attribution
|
|
19
|
+
|
|
20
|
+
## [0.1.5] - 2026-03-23
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
- Dream cycle knowledge promotion phase: promotes high-novelty association discoveries and resolved contradictions to Apollo knowledge graph
|
|
24
|
+
- `phase_knowledge_promotion` ingests novel walks (novelty > 0.8) as associations and resolved contradictions as facts
|
|
25
|
+
- Dream journal now includes Phase 7: Knowledge Promotion section with promotion count
|
|
26
|
+
- Soft guard: phase is a no-op when lex-apollo or legion-data are not loaded
|
|
4
27
|
|
|
5
28
|
## [0.1.4] - 2026-03-22
|
|
6
29
|
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Domain consolidation gem for imagination, creativity, and offline simulation. Bu
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
7
|
**Gem**: `lex-agentic-imagination`
|
|
8
|
-
**Version**: 0.1.
|
|
8
|
+
**Version**: 0.1.0
|
|
9
9
|
**Namespace**: `Legion::Extensions::Agentic::Imagination`
|
|
10
10
|
|
|
11
11
|
## Sub-Modules
|
|
@@ -45,7 +45,7 @@ gem 'lex-agentic-imagination'
|
|
|
45
45
|
|
|
46
46
|
```bash
|
|
47
47
|
bundle install
|
|
48
|
-
bundle exec rspec #
|
|
48
|
+
bundle exec rspec # 1885 examples, 0 failures
|
|
49
49
|
bundle exec rubocop # 0 offenses
|
|
50
50
|
```
|
|
51
51
|
|
|
@@ -51,7 +51,7 @@ module Legion
|
|
|
51
51
|
[(0.6...0.8), :argentum],
|
|
52
52
|
[(0.4...0.6), :cuprum],
|
|
53
53
|
[(0.2...0.4), :ferrum],
|
|
54
|
-
[
|
|
54
|
+
[..0.2, :plumbum]
|
|
55
55
|
].freeze
|
|
56
56
|
|
|
57
57
|
# Potency labels
|
|
@@ -60,7 +60,7 @@ module Legion
|
|
|
60
60
|
[(0.6...0.8), :potent],
|
|
61
61
|
[(0.4...0.6), :moderate],
|
|
62
62
|
[(0.2...0.4), :weak],
|
|
63
|
-
[
|
|
63
|
+
[..0.2, :inert]
|
|
64
64
|
].freeze
|
|
65
65
|
|
|
66
66
|
def self.label_for(table, value)
|
|
@@ -34,7 +34,7 @@ module Legion
|
|
|
34
34
|
[(0.6...0.8), :giant],
|
|
35
35
|
[(0.4...0.6), :main_sequence],
|
|
36
36
|
[(0.2...0.4), :dwarf],
|
|
37
|
-
[
|
|
37
|
+
[..0.2, :brown_dwarf]
|
|
38
38
|
].freeze
|
|
39
39
|
|
|
40
40
|
# Constellation maturity labels
|
|
@@ -43,7 +43,7 @@ module Legion
|
|
|
43
43
|
[(0.6...0.8), :established],
|
|
44
44
|
[(0.4...0.6), :forming],
|
|
45
45
|
[(0.2...0.4), :nascent],
|
|
46
|
-
[
|
|
46
|
+
[..0.2, :proto]
|
|
47
47
|
].freeze
|
|
48
48
|
|
|
49
49
|
def self.label_for(table, value)
|
|
@@ -38,6 +38,7 @@ module Legion
|
|
|
38
38
|
section_identity_entropy(lines, results, phase_data)
|
|
39
39
|
section_agenda(lines, results, phase_data)
|
|
40
40
|
section_consolidation(lines, results)
|
|
41
|
+
section_knowledge_promotion(lines, results)
|
|
41
42
|
section_summary(lines, results, phase_data)
|
|
42
43
|
lines.join("\n")
|
|
43
44
|
end
|
|
@@ -160,6 +161,18 @@ module Legion
|
|
|
160
161
|
lines << ''
|
|
161
162
|
end
|
|
162
163
|
|
|
164
|
+
def section_knowledge_promotion(lines, results)
|
|
165
|
+
promo = results[:knowledge_promotion] || {}
|
|
166
|
+
lines << '## Phase 7: Knowledge Promotion'
|
|
167
|
+
lines << ''
|
|
168
|
+
lines << if promo[:status] == :skipped
|
|
169
|
+
"- Skipped: #{promo[:reason]}"
|
|
170
|
+
else
|
|
171
|
+
"- Insights promoted to Apollo: #{promo[:promoted]}"
|
|
172
|
+
end
|
|
173
|
+
lines << ''
|
|
174
|
+
end
|
|
175
|
+
|
|
163
176
|
def section_summary(lines, results, phase_data)
|
|
164
177
|
audit = results[:memory_audit] || {}
|
|
165
178
|
contra = results[:contradiction_resolution] || {}
|
|
@@ -179,6 +192,7 @@ module Legion
|
|
|
179
192
|
lines << "| Contradictions resolved | #{resolved} |"
|
|
180
193
|
lines << "| Agenda items formed | #{(results[:agenda_formation] || {})[:agenda_items]} |"
|
|
181
194
|
lines << "| Traces consolidated | #{(results[:consolidation_commit] || {})[:traces_written]} |"
|
|
195
|
+
lines << "| Knowledge promoted | #{(results[:knowledge_promotion] || {})[:promoted]} |"
|
|
182
196
|
end
|
|
183
197
|
|
|
184
198
|
def format_resolutions(lines, resolutions)
|
|
@@ -220,8 +234,9 @@ module Legion
|
|
|
220
234
|
|
|
221
235
|
private_class_method :section_narrative, :section_memory_audit, :section_association_walk,
|
|
222
236
|
:section_contradiction_resolution, :section_identity_entropy,
|
|
223
|
-
:section_agenda, :section_consolidation, :
|
|
224
|
-
:
|
|
237
|
+
:section_agenda, :section_consolidation, :section_knowledge_promotion,
|
|
238
|
+
:section_summary, :format_resolutions, :extract_payload,
|
|
239
|
+
:truncate, :summarize_content
|
|
225
240
|
end
|
|
226
241
|
end
|
|
227
242
|
end
|
|
@@ -66,12 +66,31 @@ module Legion
|
|
|
66
66
|
# --- Private helpers ---
|
|
67
67
|
|
|
68
68
|
def llm_ask(prompt)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if pipeline_available?
|
|
70
|
+
response = Legion::LLM::Pipeline::GaiaCaller.chat(
|
|
71
|
+
message: prompt,
|
|
72
|
+
phase: 'dream',
|
|
73
|
+
caller: { extension: 'lex-agentic-imagination', mode: :dream }
|
|
74
|
+
)
|
|
75
|
+
content = response&.message&.dig(:content)
|
|
76
|
+
::Struct.new(:content).new(content) if content
|
|
77
|
+
else
|
|
78
|
+
chat = Legion::LLM.chat
|
|
79
|
+
chat.with_instructions(DREAM_SYSTEM_PROMPT)
|
|
80
|
+
chat.ask(prompt)
|
|
81
|
+
end
|
|
72
82
|
end
|
|
73
83
|
private_class_method :llm_ask
|
|
74
84
|
|
|
85
|
+
def pipeline_available?
|
|
86
|
+
!!(defined?(Legion::LLM::Pipeline::GaiaCaller) &&
|
|
87
|
+
Legion::LLM.respond_to?(:pipeline_enabled?) &&
|
|
88
|
+
Legion::LLM.pipeline_enabled?)
|
|
89
|
+
rescue StandardError
|
|
90
|
+
false
|
|
91
|
+
end
|
|
92
|
+
private_class_method :pipeline_available?
|
|
93
|
+
|
|
75
94
|
def build_contradiction_prompt(trace_a, trace_b, strategy)
|
|
76
95
|
<<~PROMPT
|
|
77
96
|
Two memory traces in domain "#{(trace_a[:domain_tags] & trace_b[:domain_tags]).first}" contradict each other.
|
|
@@ -239,6 +239,19 @@ module Legion
|
|
|
239
239
|
entropy: entropy
|
|
240
240
|
)
|
|
241
241
|
|
|
242
|
+
# Mind Growth integration: inject architectural gap agenda items during dreams
|
|
243
|
+
if mind_growth_available?
|
|
244
|
+
begin
|
|
245
|
+
gap_result = Legion::Extensions::MindGrowth::Runners::DreamIdeation.dream_agenda_items
|
|
246
|
+
if gap_result[:success] && gap_result[:items]&.any?
|
|
247
|
+
items.concat(gap_result[:items])
|
|
248
|
+
Legion::Logging.debug "[dream] mind_growth injected #{gap_result[:count]} architectural gap items"
|
|
249
|
+
end
|
|
250
|
+
rescue StandardError => e
|
|
251
|
+
Legion::Logging.warn "[dream] mind_growth integration failed: #{e.message}"
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
242
255
|
items.each do |item|
|
|
243
256
|
dream_store.add_agenda_item(type: item[:type], content: item[:content], weight: item[:weight])
|
|
244
257
|
end
|
|
@@ -267,6 +280,19 @@ module Legion
|
|
|
267
280
|
{ traces_written: traces.size, dream_store_cleared: true }
|
|
268
281
|
end
|
|
269
282
|
|
|
283
|
+
def phase_knowledge_promotion(**)
|
|
284
|
+
return { status: :skipped, reason: :apollo_unavailable } unless apollo_available?
|
|
285
|
+
|
|
286
|
+
runner = Object.new.extend(Legion::Extensions::Apollo::Runners::Knowledge)
|
|
287
|
+
promoted = promote_novel_associations(runner) + promote_resolved_contradictions(runner)
|
|
288
|
+
|
|
289
|
+
Legion::Logging.debug "[dream] knowledge_promotion: promoted=#{promoted}"
|
|
290
|
+
{ promoted: promoted }
|
|
291
|
+
rescue StandardError => e
|
|
292
|
+
Legion::Logging.warn "[dream] knowledge_promotion failed: #{e.message}"
|
|
293
|
+
{ status: :error, error: e.message }
|
|
294
|
+
end
|
|
295
|
+
|
|
270
296
|
def phase_dream_reflection(**)
|
|
271
297
|
return { status: :skipped, reason: :extension_not_loaded } unless reflection_available?
|
|
272
298
|
|
|
@@ -316,6 +342,73 @@ module Legion
|
|
|
316
342
|
false
|
|
317
343
|
end
|
|
318
344
|
|
|
345
|
+
def mind_growth_available?
|
|
346
|
+
defined?(Legion::Extensions::MindGrowth::Runners::DreamIdeation)
|
|
347
|
+
rescue StandardError
|
|
348
|
+
false
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
def promote_novel_associations(knowledge_runner)
|
|
352
|
+
walk_results = @phase_data[:walk_results] || []
|
|
353
|
+
store = memory.send(:default_store)
|
|
354
|
+
count = 0
|
|
355
|
+
|
|
356
|
+
walk_results.select { |w| w[:novelty_score] && w[:novelty_score] > 0.8 }.each do |walk|
|
|
357
|
+
path_traces = walk[:path]&.filter_map { |id| store.get(id) }
|
|
358
|
+
next if path_traces.size < 2
|
|
359
|
+
|
|
360
|
+
payloads = path_traces.map { |t| summarize_trace_payload(t) }.compact
|
|
361
|
+
next if payloads.empty?
|
|
362
|
+
|
|
363
|
+
knowledge_runner.handle_ingest(
|
|
364
|
+
content: "Novel association discovered: #{payloads.join(' -> ')}",
|
|
365
|
+
content_type: :association,
|
|
366
|
+
tags: ['dream_cycle', 'association_walk', "novelty:#{walk[:novelty_score].round(2)}"],
|
|
367
|
+
source_agent: 'dream-cycle',
|
|
368
|
+
source_provider: 'legion',
|
|
369
|
+
source_channel: 'dream_association_walk',
|
|
370
|
+
context: { path_length: walk[:path]&.size, novelty: walk[:novelty_score] }
|
|
371
|
+
)
|
|
372
|
+
count += 1
|
|
373
|
+
end
|
|
374
|
+
count
|
|
375
|
+
end
|
|
376
|
+
|
|
377
|
+
def promote_resolved_contradictions(knowledge_runner)
|
|
378
|
+
contradictions = @phase_data[:contradictions] || []
|
|
379
|
+
count = 0
|
|
380
|
+
|
|
381
|
+
contradictions.select { |c| c[:resolution] == :resolved && c[:reasoning] }.each do |contra|
|
|
382
|
+
knowledge_runner.handle_ingest(
|
|
383
|
+
content: "Contradiction resolved: #{contra[:reasoning][0, 500]}",
|
|
384
|
+
content_type: :fact,
|
|
385
|
+
tags: ['dream_cycle', 'contradiction_resolved', "domain:#{contra[:domain]}"],
|
|
386
|
+
source_agent: 'dream-cycle',
|
|
387
|
+
source_provider: 'legion',
|
|
388
|
+
source_channel: 'dream_contradiction',
|
|
389
|
+
context: { domain: contra[:domain], winner_id: contra[:winner_id] }
|
|
390
|
+
)
|
|
391
|
+
count += 1
|
|
392
|
+
end
|
|
393
|
+
count
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def apollo_available?
|
|
397
|
+
defined?(Legion::Extensions::Apollo::Runners::Knowledge) &&
|
|
398
|
+
defined?(Legion::Data::Model::ApolloEntry)
|
|
399
|
+
rescue StandardError
|
|
400
|
+
false
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def summarize_trace_payload(trace)
|
|
404
|
+
payload = trace[:content_payload]
|
|
405
|
+
case payload
|
|
406
|
+
when String then payload[0, 120]
|
|
407
|
+
when Hash then payload.values.first(3).map { |v| v.to_s[0, 40] }.join(', ')
|
|
408
|
+
else payload.to_s[0, 120]
|
|
409
|
+
end
|
|
410
|
+
end
|
|
411
|
+
|
|
319
412
|
def dream_store
|
|
320
413
|
@dream_store ||= Helpers::DreamStore.new
|
|
321
414
|
end
|
|
@@ -25,7 +25,7 @@ module Legion
|
|
|
25
25
|
[(0.6...0.8), :thriving],
|
|
26
26
|
[(0.4...0.6), :growing],
|
|
27
27
|
[(0.2...0.4), :wilting],
|
|
28
|
-
[
|
|
28
|
+
[..0.2, :withered]
|
|
29
29
|
].freeze
|
|
30
30
|
|
|
31
31
|
FERTILITY_LABELS = [
|
|
@@ -33,7 +33,7 @@ module Legion
|
|
|
33
33
|
[(0.6...0.8), :rich],
|
|
34
34
|
[(0.4...0.6), :adequate],
|
|
35
35
|
[(0.2...0.4), :poor],
|
|
36
|
-
[
|
|
36
|
+
[..0.2, :barren]
|
|
37
37
|
].freeze
|
|
38
38
|
|
|
39
39
|
def self.label_for(table, value)
|
|
@@ -15,12 +15,12 @@ RSpec.describe Legion::Extensions::Agentic::Imagination::Dream::Runners::DreamCy
|
|
|
15
15
|
let(:trace_helper) { Legion::Extensions::Memory::Helpers::Trace }
|
|
16
16
|
|
|
17
17
|
describe '#execute_dream_cycle' do
|
|
18
|
-
it 'returns a result hash with all
|
|
18
|
+
it 'returns a result hash with all nine phases' do
|
|
19
19
|
result = client.execute_dream_cycle
|
|
20
20
|
expect(result[:phases].keys).to contain_exactly(
|
|
21
21
|
:memory_audit, :association_walk, :contradiction_resolution,
|
|
22
22
|
:identity_entropy_check, :agenda_formation, :consolidation_commit,
|
|
23
|
-
:dream_reflection, :dream_narration
|
|
23
|
+
:knowledge_promotion, :dream_reflection, :dream_narration
|
|
24
24
|
)
|
|
25
25
|
end
|
|
26
26
|
|
|
@@ -105,6 +105,54 @@ RSpec.describe Legion::Extensions::Agentic::Imagination::Dream::Runners::DreamCy
|
|
|
105
105
|
end
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
+
describe '#phase_agenda_formation mind_growth integration' do
|
|
109
|
+
before do
|
|
110
|
+
client.phase_memory_audit
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
context 'when MindGrowth is available and returns gap items' do
|
|
114
|
+
let(:gap_items) { [{ type: :curious, content: { description: 'missing module' }, weight: 0.7 }] }
|
|
115
|
+
|
|
116
|
+
before do
|
|
117
|
+
stub_const('Legion::Extensions::MindGrowth::Runners::DreamIdeation', Class.new)
|
|
118
|
+
allow(Legion::Extensions::MindGrowth::Runners::DreamIdeation)
|
|
119
|
+
.to receive(:dream_agenda_items)
|
|
120
|
+
.and_return({ success: true, items: gap_items, count: 1 })
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
it 'injects gap items into the agenda' do
|
|
124
|
+
result = client.phase_agenda_formation
|
|
125
|
+
expect(result[:agenda_items]).to be >= 1
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it 'calls dream_agenda_items on DreamIdeation' do
|
|
129
|
+
client.phase_agenda_formation
|
|
130
|
+
expect(Legion::Extensions::MindGrowth::Runners::DreamIdeation).to have_received(:dream_agenda_items)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
context 'when MindGrowth is not defined' do
|
|
135
|
+
it 'builds agenda without error' do
|
|
136
|
+
result = client.phase_agenda_formation
|
|
137
|
+
expect(result).to have_key(:agenda_items)
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
context 'when MindGrowth raises an error' do
|
|
142
|
+
before do
|
|
143
|
+
stub_const('Legion::Extensions::MindGrowth::Runners::DreamIdeation', Class.new)
|
|
144
|
+
allow(Legion::Extensions::MindGrowth::Runners::DreamIdeation)
|
|
145
|
+
.to receive(:dream_agenda_items)
|
|
146
|
+
.and_raise(StandardError, 'connection refused')
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
it 'rescues the error and agenda formation continues' do
|
|
150
|
+
result = client.phase_agenda_formation
|
|
151
|
+
expect(result).to have_key(:agenda_items)
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
108
156
|
describe '#phase_consolidation_commit' do
|
|
109
157
|
it 'writes agenda traces to memory and clears dream store' do
|
|
110
158
|
client.dream_store.add_agenda_item(type: :curious, content: { path: %w[a b] }, weight: 0.8)
|