lex-cognitive-cocoon 0.1.0

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.
@@ -0,0 +1,230 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe Legion::Extensions::CognitiveCocoon::Helpers::Incubator do
4
+ subject(:incubator) { described_class.new }
5
+
6
+ let(:cocoon_type) { :chrysalis }
7
+ let(:domain) { :cognitive }
8
+
9
+ describe '#create_cocoon' do
10
+ it 'returns a Cocoon instance' do
11
+ cocoon = incubator.create_cocoon(cocoon_type: cocoon_type, domain: domain)
12
+ expect(cocoon).to be_a(Legion::Extensions::CognitiveCocoon::Helpers::Cocoon)
13
+ end
14
+
15
+ it 'stores the cocoon in the incubator' do
16
+ incubator.create_cocoon(cocoon_type: cocoon_type, domain: domain)
17
+ report = incubator.incubator_report
18
+ expect(report[:total_cocoons]).to eq(1)
19
+ end
20
+
21
+ it 'accepts content' do
22
+ cocoon = incubator.create_cocoon(cocoon_type: :silk, domain: :emotional, content: 'idea')
23
+ expect(cocoon.content).to eq('idea')
24
+ end
25
+
26
+ it 'accepts custom maturity' do
27
+ cocoon = incubator.create_cocoon(cocoon_type: :silk, domain: :emotional, maturity: 0.5)
28
+ expect(cocoon.maturity).to eq(0.5)
29
+ end
30
+
31
+ it 'accepts custom protection' do
32
+ cocoon = incubator.create_cocoon(cocoon_type: :silk, domain: :emotional, protection: 0.4)
33
+ expect(cocoon.protection).to eq(0.4)
34
+ end
35
+
36
+ it 'creates multiple distinct cocoons' do
37
+ c1 = incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
38
+ c2 = incubator.create_cocoon(cocoon_type: :pod, domain: :emotional)
39
+ expect(c1.id).not_to eq(c2.id)
40
+ end
41
+ end
42
+
43
+ describe '#gestate_all!' do
44
+ before do
45
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
46
+ incubator.create_cocoon(cocoon_type: :shell, domain: :emotional)
47
+ end
48
+
49
+ it 'advances all active cocoons' do
50
+ incubator.gestate_all!
51
+ report = incubator.incubator_report
52
+ expect(report[:average_maturity]).to be > 0.0
53
+ end
54
+
55
+ it 'returns the incubator for chaining' do
56
+ expect(incubator.gestate_all!).to be(incubator)
57
+ end
58
+
59
+ it 'accepts a custom rate' do
60
+ incubator.gestate_all!(0.3)
61
+ report = incubator.incubator_report
62
+ expect(report[:average_maturity]).to be_within(0.001).of(0.3)
63
+ end
64
+
65
+ it 'does not advance emerged cocoons' do
66
+ c = incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 1.0)
67
+ c.emerge!
68
+ before_mat = c.maturity
69
+ incubator.gestate_all!
70
+ expect(c.maturity).to eq(before_mat)
71
+ end
72
+ end
73
+
74
+ describe '#harvest_ready' do
75
+ it 'returns an empty array when nothing is ready' do
76
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
77
+ expect(incubator.harvest_ready).to be_empty
78
+ end
79
+
80
+ it 'returns emerged results for ready cocoons' do
81
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 1.0)
82
+ results = incubator.harvest_ready
83
+ expect(results.size).to eq(1)
84
+ expect(results.first[:success]).to be true
85
+ end
86
+
87
+ it 'removes harvested cocoons from the incubator' do
88
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 1.0)
89
+ incubator.harvest_ready
90
+ expect(incubator.incubator_report[:total_cocoons]).to eq(0)
91
+ end
92
+
93
+ it 'leaves unready cocoons in place' do
94
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 1.0)
95
+ incubator.create_cocoon(cocoon_type: :shell, domain: :emotional, maturity: 0.3)
96
+ incubator.harvest_ready
97
+ expect(incubator.incubator_report[:total_cocoons]).to eq(1)
98
+ end
99
+ end
100
+
101
+ describe '#force_emerge' do
102
+ it 'returns success true for a valid id' do
103
+ cocoon = incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
104
+ result = incubator.force_emerge(cocoon.id)
105
+ expect(result[:success]).to be true
106
+ end
107
+
108
+ it 'returns success false for an unknown id' do
109
+ result = incubator.force_emerge('nonexistent-id')
110
+ expect(result[:success]).to be false
111
+ end
112
+
113
+ it 'returns not found error for unknown id' do
114
+ result = incubator.force_emerge('bad-id')
115
+ expect(result[:error]).to eq('cocoon not found')
116
+ end
117
+
118
+ it 'marks the cocoon as damaged when premature' do
119
+ cocoon = incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 0.2)
120
+ result = incubator.force_emerge(cocoon.id)
121
+ expect(result[:damaged]).to be true
122
+ end
123
+
124
+ it 'removes the cocoon from the incubator after emergence' do
125
+ cocoon = incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
126
+ incubator.force_emerge(cocoon.id)
127
+ expect(incubator.incubator_report[:total_cocoons]).to eq(0)
128
+ end
129
+ end
130
+
131
+ describe '#by_stage' do
132
+ before do
133
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
134
+ incubator.create_cocoon(cocoon_type: :pod, domain: :cognitive, maturity: 0.5)
135
+ incubator.create_cocoon(cocoon_type: :web, domain: :emotional, maturity: 0.8)
136
+ end
137
+
138
+ it 'returns cocoons in encapsulating stage' do
139
+ expect(incubator.by_stage(:encapsulating).size).to eq(1)
140
+ end
141
+
142
+ it 'returns cocoons in developing stage' do
143
+ expect(incubator.by_stage(:developing).size).to eq(1)
144
+ end
145
+
146
+ it 'returns cocoons in transforming stage' do
147
+ expect(incubator.by_stage(:transforming).size).to eq(1)
148
+ end
149
+
150
+ it 'returns empty array for an unused stage' do
151
+ expect(incubator.by_stage(:emerged)).to be_empty
152
+ end
153
+ end
154
+
155
+ describe '#most_mature' do
156
+ before do
157
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 0.2)
158
+ incubator.create_cocoon(cocoon_type: :shell, domain: :emotional, maturity: 0.8)
159
+ incubator.create_cocoon(cocoon_type: :pod, domain: :semantic, maturity: 0.5)
160
+ end
161
+
162
+ it 'returns cocoons sorted by descending maturity' do
163
+ results = incubator.most_mature(limit: 3)
164
+ maturities = results.map(&:maturity)
165
+ expect(maturities).to eq(maturities.sort.reverse)
166
+ end
167
+
168
+ it 'respects the limit' do
169
+ expect(incubator.most_mature(limit: 2).size).to eq(2)
170
+ end
171
+
172
+ it 'returns the most mature first' do
173
+ expect(incubator.most_mature(limit: 1).first.maturity).to eq(0.8)
174
+ end
175
+ end
176
+
177
+ describe '#incubator_report' do
178
+ it 'includes total_cocoons' do
179
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
180
+ expect(incubator.incubator_report[:total_cocoons]).to eq(1)
181
+ end
182
+
183
+ it 'includes average_maturity of 0.0 for empty incubator' do
184
+ expect(incubator.incubator_report[:average_maturity]).to eq(0.0)
185
+ end
186
+
187
+ it 'includes maturity_label' do
188
+ expect(incubator.incubator_report).to have_key(:maturity_label)
189
+ end
190
+
191
+ it 'includes average_protection' do
192
+ expect(incubator.incubator_report).to have_key(:average_protection)
193
+ end
194
+
195
+ it 'includes stage_distribution' do
196
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
197
+ dist = incubator.incubator_report[:stage_distribution]
198
+ expect(dist[:encapsulating]).to eq(1)
199
+ end
200
+
201
+ it 'includes ready_count' do
202
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive, maturity: 1.0)
203
+ expect(incubator.incubator_report[:ready_count]).to eq(1)
204
+ end
205
+
206
+ it 'includes most_mature array' do
207
+ incubator.create_cocoon(cocoon_type: :silk, domain: :cognitive)
208
+ expect(incubator.incubator_report[:most_mature]).to be_an(Array)
209
+ end
210
+
211
+ it 'includes all expected keys' do
212
+ report = incubator.incubator_report
213
+ expect(report).to include(
214
+ :total_cocoons, :average_maturity, :maturity_label,
215
+ :average_protection, :stage_distribution, :ready_count, :most_mature
216
+ )
217
+ end
218
+ end
219
+
220
+ describe '#to_h' do
221
+ it 'returns total_cocoons and average_maturity' do
222
+ h = incubator.to_h
223
+ expect(h).to include(:total_cocoons, :average_maturity)
224
+ end
225
+
226
+ it 'returns 0 total and 0.0 average for empty incubator' do
227
+ expect(incubator.to_h).to eq({ total_cocoons: 0, average_maturity: 0.0 })
228
+ end
229
+ end
230
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/cognitive_cocoon'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Helpers
8
+ module Lex; end
9
+ end
10
+ end
11
+
12
+ module Logging
13
+ def self.method_missing(_, *) = nil
14
+ def self.respond_to_missing?(_, _ = false) = true
15
+ end
16
+ end
17
+
18
+ RSpec.configure do |config|
19
+ config.expect_with :rspec do |expectations|
20
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
21
+ end
22
+ config.mock_with :rspec do |mocks|
23
+ mocks.verify_partial_doubles = true
24
+ end
25
+ config.shared_context_metadata_behavior = :apply_to_host_groups
26
+ config.order = :random
27
+ Kernel.srand config.seed
28
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-cognitive-cocoon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: legion-gaia
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: Models cognitive cocooning — fragile ideas enter protective shells, gestate
27
+ at complexity-appropriate rates, and emerge transformed. Premature exposure risks
28
+ idea death.
29
+ email:
30
+ - matthewdiverson@gmail.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".github/workflows/ci.yml"
36
+ - ".gitignore"
37
+ - ".rspec"
38
+ - ".rubocop.yml"
39
+ - CLAUDE.md
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - README.md
43
+ - lex-cognitive-cocoon.gemspec
44
+ - lib/legion/extensions/cognitive_cocoon.rb
45
+ - lib/legion/extensions/cognitive_cocoon/client.rb
46
+ - lib/legion/extensions/cognitive_cocoon/helpers/cocoon.rb
47
+ - lib/legion/extensions/cognitive_cocoon/helpers/constants.rb
48
+ - lib/legion/extensions/cognitive_cocoon/helpers/incubator.rb
49
+ - lib/legion/extensions/cognitive_cocoon/runners/cognitive_cocoon.rb
50
+ - lib/legion/extensions/cognitive_cocoon/version.rb
51
+ - spec/legion/extensions/cognitive_cocoon/client_spec.rb
52
+ - spec/legion/extensions/cognitive_cocoon/helpers/cocoon_spec.rb
53
+ - spec/legion/extensions/cognitive_cocoon/helpers/constants_spec.rb
54
+ - spec/legion/extensions/cognitive_cocoon/helpers/incubator_spec.rb
55
+ - spec/spec_helper.rb
56
+ homepage: https://github.com/LegionIO/lex-cognitive-cocoon
57
+ licenses:
58
+ - MIT
59
+ metadata:
60
+ homepage_uri: https://github.com/LegionIO/lex-cognitive-cocoon
61
+ source_code_uri: https://github.com/LegionIO/lex-cognitive-cocoon
62
+ documentation_uri: https://github.com/LegionIO/lex-cognitive-cocoon/blob/master/README.md
63
+ changelog_uri: https://github.com/LegionIO/lex-cognitive-cocoon/blob/master/CHANGELOG.md
64
+ bug_tracker_uri: https://github.com/LegionIO/lex-cognitive-cocoon/issues
65
+ rubygems_mfa_required: 'true'
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '3.4'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubygems_version: 3.6.9
81
+ specification_version: 4
82
+ summary: Protective encapsulation of fragile ideas during development for LegionIO
83
+ agents
84
+ test_files: []