lex-cognitive-debugging 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,301 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/cognitive_debugging/client'
4
+
5
+ RSpec.describe Legion::Extensions::CognitiveDebugging::Runners::CognitiveDebugging do
6
+ subject(:client) { Legion::Extensions::CognitiveDebugging::Client.new }
7
+
8
+ let(:base_error_kwargs) do
9
+ {
10
+ error_type: :inconsistency,
11
+ description: 'Claim X contradicts Claim Y',
12
+ severity: 0.6,
13
+ source_phase: :prediction_engine,
14
+ confidence_at_detection: 0.85
15
+ }
16
+ end
17
+
18
+ def detect_one(overrides = {})
19
+ client.detect_error(**base_error_kwargs, **overrides)
20
+ end
21
+
22
+ describe '#detect_error' do
23
+ it 'returns success: true with an error_id' do
24
+ result = detect_one
25
+ expect(result[:success]).to be true
26
+ expect(result[:error_id]).to match(/\A[0-9a-f-]{36}\z/)
27
+ end
28
+
29
+ it 'returns the error_type' do
30
+ result = detect_one
31
+ expect(result[:error_type]).to eq(:inconsistency)
32
+ end
33
+
34
+ it 'includes severity_label' do
35
+ result = detect_one
36
+ expect(result[:severity_label]).to be_a(Symbol)
37
+ end
38
+
39
+ it 'returns success: false for invalid error_type' do
40
+ result = client.detect_error(**base_error_kwargs, error_type: :not_real)
41
+ expect(result[:success]).to be false
42
+ expect(result[:error]).to eq(:invalid_error_type)
43
+ end
44
+
45
+ it 'returns valid error types on failure' do
46
+ result = client.detect_error(**base_error_kwargs, error_type: :bogus)
47
+ expect(result[:valid]).to include(:inconsistency)
48
+ end
49
+
50
+ it 'uses default confidence_at_detection of 0.5 when omitted' do
51
+ result = client.detect_error(error_type: :overconfidence, description: 'x',
52
+ severity: 0.5, source_phase: :tick)
53
+ expect(result[:success]).to be true
54
+ end
55
+ end
56
+
57
+ describe '#trace_error' do
58
+ let(:error_id) { detect_one[:error_id] }
59
+ let(:steps) do
60
+ [
61
+ { phase: :emotional_evaluation, description: 'Urgency spike' },
62
+ { phase: :prediction_engine, description: 'Premature conclusion' }
63
+ ]
64
+ end
65
+
66
+ it 'returns success: true with trace_id and depth' do
67
+ result = client.trace_error(error_id: error_id, steps: steps, root_cause: :bad_prior, confidence: 0.7)
68
+ expect(result[:success]).to be true
69
+ expect(result[:trace_id]).to match(/\A[0-9a-f-]{36}\z/)
70
+ expect(result[:depth]).to eq(2)
71
+ end
72
+
73
+ it 'returns root_cause in response' do
74
+ result = client.trace_error(error_id: error_id, steps: steps, root_cause: :bad_prior, confidence: 0.7)
75
+ expect(result[:root_cause]).to eq(:bad_prior)
76
+ end
77
+
78
+ it 'returns success: false for unknown error_id' do
79
+ result = client.trace_error(error_id: 'nope', steps: steps, root_cause: :x, confidence: 0.5)
80
+ expect(result[:success]).to be false
81
+ expect(result[:error]).to eq(:not_found_or_cap)
82
+ end
83
+
84
+ it 'uses default confidence of 0.5 when omitted' do
85
+ result = client.trace_error(error_id: error_id, steps: steps, root_cause: :x)
86
+ expect(result[:success]).to be true
87
+ end
88
+ end
89
+
90
+ describe '#propose_correction' do
91
+ let(:error_id) { detect_one[:error_id] }
92
+
93
+ it 'returns success: true with correction_id and strategy' do
94
+ result = client.propose_correction(error_id: error_id, strategy: :retrace,
95
+ description: 'Re-examine from start')
96
+ expect(result[:success]).to be true
97
+ expect(result[:correction_id]).to match(/\A[0-9a-f-]{36}\z/)
98
+ expect(result[:strategy]).to eq(:retrace)
99
+ end
100
+
101
+ it 'returns success: false for invalid strategy' do
102
+ result = client.propose_correction(error_id: error_id, strategy: :invalid_strat, description: 'x')
103
+ expect(result[:success]).to be false
104
+ expect(result[:error]).to eq(:invalid_strategy)
105
+ end
106
+
107
+ it 'returns valid strategies on failure' do
108
+ result = client.propose_correction(error_id: error_id, strategy: :bad, description: 'x')
109
+ expect(result[:valid]).to include(:retrace, :devil_advocate)
110
+ end
111
+
112
+ it 'returns success: false for unknown error_id' do
113
+ result = client.propose_correction(error_id: 'nope', strategy: :retrace, description: 'x')
114
+ expect(result[:success]).to be false
115
+ expect(result[:error]).to eq(:not_found)
116
+ end
117
+ end
118
+
119
+ describe '#apply_correction' do
120
+ let(:correction_id) do
121
+ error_id = detect_one[:error_id]
122
+ client.propose_correction(error_id: error_id, strategy: :retrace, description: 'x')[:correction_id]
123
+ end
124
+
125
+ it 'returns success: true and applied: true' do
126
+ result = client.apply_correction(correction_id: correction_id)
127
+ expect(result[:success]).to be true
128
+ expect(result[:applied]).to be true
129
+ end
130
+
131
+ it 'returns success: false for unknown correction_id' do
132
+ result = client.apply_correction(correction_id: 'nope')
133
+ expect(result[:success]).to be false
134
+ expect(result[:error]).to eq(:not_found)
135
+ end
136
+ end
137
+
138
+ describe '#measure_correction' do
139
+ let(:correction_id) do
140
+ error_id = detect_one[:error_id]
141
+ client.propose_correction(error_id: error_id, strategy: :reframe, description: 'x')[:correction_id]
142
+ end
143
+
144
+ it 'returns effectiveness and effective flag' do
145
+ result = client.measure_correction(correction_id: correction_id, effectiveness: 0.8)
146
+ expect(result[:success]).to be true
147
+ expect(result[:effectiveness]).to eq(0.8)
148
+ expect(result[:effective]).to be true
149
+ end
150
+
151
+ it 'returns effective: false for low score' do
152
+ result = client.measure_correction(correction_id: correction_id, effectiveness: 0.4)
153
+ expect(result[:effective]).to be false
154
+ end
155
+
156
+ it 'returns success: false for unknown correction_id' do
157
+ result = client.measure_correction(correction_id: 'nope', effectiveness: 0.5)
158
+ expect(result[:success]).to be false
159
+ end
160
+ end
161
+
162
+ describe '#resolve_error' do
163
+ let(:error_id) { detect_one[:error_id] }
164
+
165
+ it 'returns success: true and resolved: true' do
166
+ result = client.resolve_error(error_id: error_id)
167
+ expect(result[:success]).to be true
168
+ expect(result[:resolved]).to be true
169
+ end
170
+
171
+ it 'returns success: false for unknown error_id' do
172
+ result = client.resolve_error(error_id: 'nope')
173
+ expect(result[:success]).to be false
174
+ end
175
+ end
176
+
177
+ describe '#active_errors' do
178
+ it 'returns a list of active errors' do
179
+ detect_one
180
+ result = client.active_errors
181
+ expect(result[:success]).to be true
182
+ expect(result[:count]).to be >= 1
183
+ expect(result[:errors]).to be_an(Array)
184
+ end
185
+
186
+ it 'does not include resolved errors' do
187
+ eid = detect_one[:error_id]
188
+ client.resolve_error(error_id: eid)
189
+ result = client.active_errors
190
+ ids = result[:errors].map { |e| e[:id] }
191
+ expect(ids).not_to include(eid)
192
+ end
193
+ end
194
+
195
+ describe '#resolved_errors' do
196
+ it 'returns empty list when nothing resolved' do
197
+ result = client.resolved_errors
198
+ expect(result[:success]).to be true
199
+ expect(result[:count]).to eq(0)
200
+ end
201
+
202
+ it 'includes resolved errors' do
203
+ eid = detect_one[:error_id]
204
+ client.resolve_error(error_id: eid)
205
+ result = client.resolved_errors
206
+ ids = result[:errors].map { |e| e[:id] }
207
+ expect(ids).to include(eid)
208
+ end
209
+ end
210
+
211
+ describe '#errors_by_type' do
212
+ it 'returns a tally hash' do
213
+ detect_one(error_type: :overconfidence)
214
+ detect_one(error_type: :overconfidence)
215
+ result = client.errors_by_type
216
+ expect(result[:success]).to be true
217
+ expect(result[:tally][:overconfidence]).to eq(2)
218
+ end
219
+ end
220
+
221
+ describe '#errors_by_phase' do
222
+ it 'returns a tally by source_phase' do
223
+ detect_one(source_phase: :emotional_evaluation)
224
+ result = client.errors_by_phase
225
+ expect(result[:success]).to be true
226
+ expect(result[:tally][:emotional_evaluation]).to be >= 1
227
+ end
228
+ end
229
+
230
+ describe '#most_common_error_type' do
231
+ it 'returns nil when no errors' do
232
+ result = client.most_common_error_type
233
+ expect(result[:success]).to be true
234
+ expect(result[:error_type]).to be_nil
235
+ end
236
+
237
+ it 'returns the most frequent type' do
238
+ detect_one(error_type: :circular_logic)
239
+ detect_one(error_type: :circular_logic)
240
+ detect_one(error_type: :missing_evidence)
241
+ result = client.most_common_error_type
242
+ expect(result[:error_type]).to eq(:circular_logic)
243
+ end
244
+ end
245
+
246
+ describe '#most_effective_strategy' do
247
+ it 'returns nil when no measured corrections' do
248
+ result = client.most_effective_strategy
249
+ expect(result[:success]).to be true
250
+ expect(result[:strategy]).to be_nil
251
+ end
252
+
253
+ it 'returns the best-performing strategy' do
254
+ eid = detect_one[:error_id]
255
+ c1 = client.propose_correction(error_id: eid, strategy: :retrace, description: 'x')
256
+ c2 = client.propose_correction(error_id: eid, strategy: :seek_evidence, description: 'y')
257
+ client.measure_correction(correction_id: c1[:correction_id], effectiveness: 0.3)
258
+ client.measure_correction(correction_id: c2[:correction_id], effectiveness: 0.95)
259
+ result = client.most_effective_strategy
260
+ expect(result[:strategy]).to eq(:seek_evidence)
261
+ end
262
+ end
263
+
264
+ describe '#correction_success_rate' do
265
+ it 'returns 0.0 when no corrections' do
266
+ result = client.correction_success_rate
267
+ expect(result[:success]).to be true
268
+ expect(result[:rate]).to eq(0.0)
269
+ end
270
+
271
+ it 'calculates correct rate after measuring' do
272
+ eid = detect_one[:error_id]
273
+ c1 = client.propose_correction(error_id: eid, strategy: :retrace, description: 'a')
274
+ c2 = client.propose_correction(error_id: eid, strategy: :reframe, description: 'b')
275
+ client.apply_correction(correction_id: c1[:correction_id])
276
+ client.apply_correction(correction_id: c2[:correction_id])
277
+ client.measure_correction(correction_id: c1[:correction_id], effectiveness: 0.9)
278
+ client.measure_correction(correction_id: c2[:correction_id], effectiveness: 0.9)
279
+ result = client.correction_success_rate
280
+ expect(result[:rate]).to eq(1.0)
281
+ end
282
+ end
283
+
284
+ describe '#debugging_report' do
285
+ it 'returns success: true with a complete report' do
286
+ detect_one
287
+ result = client.debugging_report
288
+ expect(result[:success]).to be true
289
+ expect(result[:report]).to include(:total_errors, :active_errors, :correction_success_rate)
290
+ end
291
+ end
292
+
293
+ describe '#snapshot' do
294
+ it 'returns success: true with snapshot data' do
295
+ detect_one
296
+ result = client.snapshot
297
+ expect(result[:success]).to be true
298
+ expect(result[:snapshot]).to include(:errors, :traces, :corrections)
299
+ end
300
+ end
301
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+
5
+ module Legion
6
+ module Logging
7
+ def self.debug(_msg); end
8
+ def self.info(_msg); end
9
+ def self.warn(_msg); end
10
+ def self.error(_msg); end
11
+ end
12
+
13
+ module Extensions
14
+ module Helpers
15
+ module Lex; end
16
+ end
17
+ end
18
+ end
19
+
20
+ require 'legion/extensions/cognitive_debugging'
21
+
22
+ RSpec.configure do |config|
23
+ config.example_status_persistence_file_path = '.rspec_status'
24
+ config.disable_monkey_patching!
25
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
26
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-cognitive-debugging
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: Self-debugging system for cognitive processes in LegionIO — detects reasoning
27
+ errors, traces causal chains, and applies corrective strategies
28
+ email:
29
+ - matthewdiverson@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - LICENSE
36
+ - README.md
37
+ - lex-cognitive-debugging.gemspec
38
+ - lib/legion/extensions/cognitive_debugging.rb
39
+ - lib/legion/extensions/cognitive_debugging/client.rb
40
+ - lib/legion/extensions/cognitive_debugging/helpers/causal_trace.rb
41
+ - lib/legion/extensions/cognitive_debugging/helpers/constants.rb
42
+ - lib/legion/extensions/cognitive_debugging/helpers/correction.rb
43
+ - lib/legion/extensions/cognitive_debugging/helpers/debugging_engine.rb
44
+ - lib/legion/extensions/cognitive_debugging/helpers/reasoning_error.rb
45
+ - lib/legion/extensions/cognitive_debugging/runners/cognitive_debugging.rb
46
+ - lib/legion/extensions/cognitive_debugging/version.rb
47
+ - spec/legion/extensions/cognitive_debugging/client_spec.rb
48
+ - spec/legion/extensions/cognitive_debugging/helpers/causal_trace_spec.rb
49
+ - spec/legion/extensions/cognitive_debugging/helpers/constants_spec.rb
50
+ - spec/legion/extensions/cognitive_debugging/helpers/correction_spec.rb
51
+ - spec/legion/extensions/cognitive_debugging/helpers/debugging_engine_spec.rb
52
+ - spec/legion/extensions/cognitive_debugging/helpers/reasoning_error_spec.rb
53
+ - spec/legion/extensions/cognitive_debugging/runners/cognitive_debugging_spec.rb
54
+ - spec/spec_helper.rb
55
+ homepage: https://github.com/LegionIO/lex-cognitive-debugging
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ homepage_uri: https://github.com/LegionIO/lex-cognitive-debugging
60
+ source_code_uri: https://github.com/LegionIO/lex-cognitive-debugging
61
+ documentation_uri: https://github.com/LegionIO/lex-cognitive-debugging
62
+ changelog_uri: https://github.com/LegionIO/lex-cognitive-debugging
63
+ bug_tracker_uri: https://github.com/LegionIO/lex-cognitive-debugging/issues
64
+ rubygems_mfa_required: 'true'
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '3.4'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubygems_version: 3.6.9
80
+ specification_version: 4
81
+ summary: LEX Cognitive Debugging
82
+ test_files: []