lex-synapse 0.4.30 → 0.4.33
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 +12 -0
- data/README.md +6 -0
- data/lib/legion/extensions/synapse/helpers/challenge.rb +4 -21
- data/lib/legion/extensions/synapse/helpers/proposals.rb +4 -17
- data/lib/legion/extensions/synapse/runners/challenge.rb +22 -17
- data/lib/legion/extensions/synapse/runners/crystallize.rb +24 -3
- data/lib/legion/extensions/synapse/runners/propose.rb +14 -8
- data/lib/legion/extensions/synapse/runners/retrieve.rb +8 -4
- data/lib/legion/extensions/synapse/settings.rb +53 -0
- data/lib/legion/extensions/synapse/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4693d9ea96294087ce5edf804eec62b92106cb179748e4f4eeb78d65dcda9171
|
|
4
|
+
data.tar.gz: 0f816950bf81a388c2d2ee3fc06602fa15c78a0ca1b8f1c1e4662951a84d6507
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3c85871bc735230e8c5e2c73df99eea422ea028eb411462529ef9c6aa3599c4e691fe35b7979c5531659881233fd3f34903aa964bd391625910842d9becf8ae
|
|
7
|
+
data.tar.gz: 8cfbaf0885ad441ad2a462efa07e708bf3e521e7133c784704bec1ec3db143a6f3d8f9fcc07375a1eaa6d603210917b8f535914052e04ffdd3b5720b66463f12
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.33] - 2026-11-19
|
|
4
|
+
### Fixed
|
|
5
|
+
- Feed periodic crystallization from the latest 1000 completed parent-child task edges, retaining threshold and duplicate checks (fixes #29).
|
|
6
|
+
|
|
7
|
+
## [0.4.32] - 2026-11-19
|
|
8
|
+
### Fixed
|
|
9
|
+
- Resolve proposal and review options through native extension settings, define defaults, and emit structured runtime exceptions while propagating programming errors (fixes #32).
|
|
10
|
+
|
|
11
|
+
## [0.4.31] - 2026-11-19
|
|
12
|
+
### Fixed
|
|
13
|
+
- Claim proposal application and persist routing state, mutation history, and applied status in one transaction (fixes #23).
|
|
14
|
+
|
|
3
15
|
## [0.4.30] - 2026-11-19
|
|
4
16
|
### Fixed
|
|
5
17
|
- Report unknown downstream success rates as nil when no outcomes are complete; document reviewed recovery, retry, and decay behavior (fixes #25).
|
data/README.md
CHANGED
|
@@ -186,3 +186,9 @@ Only active synapses with at least one complete hour since their most recent sig
|
|
|
186
186
|
## License
|
|
187
187
|
|
|
188
188
|
MIT
|
|
189
|
+
|
|
190
|
+
### Proposal and review settings
|
|
191
|
+
|
|
192
|
+
Configure `extensions.synapse.proposals` and `extensions.synapse.challenge` using symbol keys through `Legion::Settings` (JSON configuration keys are normalized by the loader). Defaults are exposed by `Legion::Extensions::Synapse.default_settings`. Standalone clients use the same settings and defaults. Migrate the former top-level `lex-synapse` section to `extensions.synapse`; that legacy path is no longer read.
|
|
193
|
+
|
|
194
|
+
Scheduled crystallization samples the latest 1000 completed child tasks from the shared `tasks` table and groups their parent/child function IDs. At least 20 sampled edges are required for an observing emergent synapse. Failed or pending children do not count. Existing function pairs are skipped on later cycles. Standalone callers may still supply `signal_pairs:` explicitly; an empty array disables collection for that call.
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/extensions/synapse/settings'
|
|
4
|
+
|
|
3
5
|
module Legion
|
|
4
6
|
module Extensions
|
|
5
7
|
module Synapse
|
|
@@ -17,30 +19,11 @@ module Legion
|
|
|
17
19
|
'route_change' => 0.8
|
|
18
20
|
}.freeze
|
|
19
21
|
|
|
20
|
-
DEFAULT_SETTINGS =
|
|
21
|
-
enabled: true,
|
|
22
|
-
impact_threshold: 0.3,
|
|
23
|
-
auto_accept_threshold: 0.85,
|
|
24
|
-
auto_reject_threshold: 0.15,
|
|
25
|
-
llm_engine_options: { temperature: 0.2, max_tokens: 512 },
|
|
26
|
-
outcome_observation_window: 50,
|
|
27
|
-
max_per_cycle: 5,
|
|
28
|
-
review_max_attempts: 3,
|
|
29
|
-
review_retry_seconds: 300,
|
|
30
|
-
review_max_retry_seconds: 3600,
|
|
31
|
-
challenger_starting_confidence: 0.5,
|
|
32
|
-
challenger_correct_adjustment: 0.05,
|
|
33
|
-
challenger_incorrect_adjustment: -0.08
|
|
34
|
-
}.freeze
|
|
22
|
+
DEFAULT_SETTINGS = Legion::Extensions::Synapse::Settings::CHALLENGE
|
|
35
23
|
|
|
36
24
|
class << self
|
|
37
25
|
def settings
|
|
38
|
-
|
|
39
|
-
return DEFAULT_SETTINGS.dup unless raw.is_a?(Hash)
|
|
40
|
-
|
|
41
|
-
merged = DEFAULT_SETTINGS.dup
|
|
42
|
-
raw.each { |k, v| merged[k.to_sym] = v unless v.nil? }
|
|
43
|
-
merged
|
|
26
|
+
Legion::Extensions::Synapse::Settings.section(name: :challenge)
|
|
44
27
|
end
|
|
45
28
|
|
|
46
29
|
def enabled?
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'legion/extensions/synapse/settings'
|
|
4
|
+
|
|
3
5
|
module Legion
|
|
4
6
|
module Extensions
|
|
5
7
|
module Synapse
|
|
@@ -9,26 +11,11 @@ module Legion
|
|
|
9
11
|
VALID_TRIGGERS = %w[reactive proactive].freeze
|
|
10
12
|
VALID_STATUSES = %w[pending challenging challenged approved rejected applied expired auto_accepted auto_rejected].freeze
|
|
11
13
|
|
|
12
|
-
DEFAULT_SETTINGS =
|
|
13
|
-
enabled: true,
|
|
14
|
-
reactive: true,
|
|
15
|
-
proactive: true,
|
|
16
|
-
proactive_interval: 300,
|
|
17
|
-
max_per_run: 3,
|
|
18
|
-
llm_engine_options: { temperature: 0.3, max_tokens: 1024 },
|
|
19
|
-
success_rate_threshold: 0.8,
|
|
20
|
-
payload_drift_threshold: 0.2,
|
|
21
|
-
dedup_window_hours: 24
|
|
22
|
-
}.freeze
|
|
14
|
+
DEFAULT_SETTINGS = Legion::Extensions::Synapse::Settings::PROPOSALS
|
|
23
15
|
|
|
24
16
|
class << self
|
|
25
17
|
def settings
|
|
26
|
-
|
|
27
|
-
return DEFAULT_SETTINGS.dup unless raw.is_a?(Hash)
|
|
28
|
-
|
|
29
|
-
merged = DEFAULT_SETTINGS.dup
|
|
30
|
-
raw.each { |k, v| merged[k.to_sym] = v unless v.nil? }
|
|
31
|
-
merged
|
|
18
|
+
Legion::Extensions::Synapse::Settings.section(name: :proposals)
|
|
32
19
|
end
|
|
33
20
|
|
|
34
21
|
def enabled?
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require 'legion/logging/helper'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
5
|
+
require 'legion/extensions/synapse/helpers/challenge'
|
|
6
|
+
require 'legion/extensions/synapse/helpers/confidence'
|
|
7
|
+
require 'legion/extensions/synapse/data/models/synapse'
|
|
8
|
+
require 'legion/extensions/synapse/data/models/synapse_proposal'
|
|
9
|
+
require 'legion/extensions/synapse/data/models/synapse_challenge'
|
|
10
|
+
require 'legion/extensions/synapse/data/models/synapse_signal'
|
|
11
|
+
require 'legion/extensions/synapse/runners/blast_radius'
|
|
12
|
+
require 'legion/extensions/synapse/runners/mutate'
|
|
13
13
|
|
|
14
14
|
module Legion
|
|
15
15
|
module Extensions
|
|
@@ -128,16 +128,19 @@ module Legion
|
|
|
128
128
|
mutation = mutation_for_proposal(proposal)
|
|
129
129
|
return { success: false, error: "unsupported proposal_type: #{proposal.proposal_type}" } unless mutation
|
|
130
130
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
proposal.db.transaction do
|
|
132
|
+
claimed = Data::Model::SynapseProposal.where(id: proposal.id, status: proposal.status)
|
|
133
|
+
.update(status: 'applied', reviewed_at: Time.now)
|
|
134
|
+
next { success: false, error: 'proposal already claimed' } if claimed.zero?
|
|
135
|
+
|
|
136
|
+
result = Object.new.extend(Mutate).mutate(
|
|
137
|
+
synapse_id: proposal.synapse_id, mutation_type: mutation[:mutation_type],
|
|
138
|
+
changes: mutation[:changes], trigger: 'gaia'
|
|
139
|
+
)
|
|
140
|
+
raise Sequel::Error, result[:error] unless result[:success]
|
|
138
141
|
|
|
139
|
-
|
|
140
|
-
|
|
142
|
+
result.merge(proposal_id: proposal.id, status: 'applied', decision: 'applied')
|
|
143
|
+
end
|
|
141
144
|
end
|
|
142
145
|
|
|
143
146
|
def run_challenge_cycle(transformer_client: nil, **)
|
|
@@ -251,6 +254,8 @@ module Legion
|
|
|
251
254
|
challenger_confidence: llm_confidence
|
|
252
255
|
)
|
|
253
256
|
rescue StandardError => e
|
|
257
|
+
raise if e.is_a?(NoMethodError) || e.is_a?(ArgumentError) || e.is_a?(TypeError)
|
|
258
|
+
|
|
254
259
|
handle_exception(e, level: :warn, operation: :challenge_llm, proposal_id: proposal.id)
|
|
255
260
|
Data::Model::SynapseChallenge.create(
|
|
256
261
|
proposal_id: proposal.id, challenger_type: 'llm',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
require 'legion/extensions/synapse/helpers/confidence'
|
|
4
|
+
require 'legion/extensions/synapse/data/models/synapse'
|
|
5
5
|
|
|
6
6
|
module Legion
|
|
7
7
|
module Extensions
|
|
@@ -10,8 +10,11 @@ module Legion
|
|
|
10
10
|
module Crystallize
|
|
11
11
|
EMERGENCE_THRESHOLD = 20
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
TRAFFIC_SAMPLE_LIMIT = 1000
|
|
14
|
+
|
|
15
|
+
def crystallize(signal_pairs: nil, threshold: EMERGENCE_THRESHOLD, **)
|
|
14
16
|
Data::Model.define_synapse_model
|
|
17
|
+
signal_pairs ||= observed_task_pairs
|
|
15
18
|
created = []
|
|
16
19
|
|
|
17
20
|
signal_pairs.each do |pair|
|
|
@@ -33,6 +36,24 @@ module Legion
|
|
|
33
36
|
|
|
34
37
|
private
|
|
35
38
|
|
|
39
|
+
def observed_task_pairs
|
|
40
|
+
db = Data::Model::Synapse.db
|
|
41
|
+
return [] unless db.table_exists?(:tasks)
|
|
42
|
+
|
|
43
|
+
children = db[:tasks].where(status: 'task.completed').exclude(parent_id: nil)
|
|
44
|
+
.exclude(function_id: nil).reverse_order(:id).limit(TRAFFIC_SAMPLE_LIMIT).all
|
|
45
|
+
parents = db[:tasks].where(id: children.map { |child| child[:parent_id] })
|
|
46
|
+
.select_map(%i[id function_id]).to_h
|
|
47
|
+
counts = Hash.new(0)
|
|
48
|
+
children.each do |child|
|
|
49
|
+
source = parents[child[:parent_id]]
|
|
50
|
+
counts[[source, child[:function_id]]] += 1 if source
|
|
51
|
+
end
|
|
52
|
+
counts.map do |(source, target), count|
|
|
53
|
+
{ source_function_id: source, target_function_id: target, count: count }
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
36
57
|
def synapse_exists?(source_id, target_id)
|
|
37
58
|
Data::Model::Synapse.where(
|
|
38
59
|
source_function_id: source_id,
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
require 'legion/logging/helper'
|
|
4
|
+
|
|
5
|
+
require 'legion/extensions/synapse/helpers/confidence'
|
|
6
|
+
require 'legion/extensions/synapse/helpers/proposals'
|
|
7
|
+
require 'legion/extensions/synapse/data/models/synapse'
|
|
8
|
+
require 'legion/extensions/synapse/data/models/synapse_signal'
|
|
9
|
+
require 'legion/extensions/synapse/data/models/synapse_proposal'
|
|
8
10
|
|
|
9
11
|
module Legion
|
|
10
12
|
module Extensions
|
|
11
13
|
module Synapse
|
|
12
14
|
module Runners
|
|
13
15
|
module Propose
|
|
14
|
-
include Legion::Logging::Helper
|
|
16
|
+
include Legion::Logging::Helper
|
|
15
17
|
|
|
16
18
|
PAIN_CORRELATION_THRESHOLD = 3
|
|
17
19
|
|
|
@@ -214,7 +216,9 @@ module Legion
|
|
|
214
216
|
)
|
|
215
217
|
{ output: result[:success] ? Legion::JSON.dump(result[:result]) : nil }
|
|
216
218
|
rescue StandardError => e
|
|
217
|
-
|
|
219
|
+
raise if e.is_a?(NoMethodError) || e.is_a?(ArgumentError) || e.is_a?(TypeError)
|
|
220
|
+
|
|
221
|
+
handle_exception(e, level: :warn, operation: :proposal_llm)
|
|
218
222
|
{ output: nil }
|
|
219
223
|
end
|
|
220
224
|
|
|
@@ -236,7 +240,9 @@ module Legion
|
|
|
236
240
|
|
|
237
241
|
discovery.function_schema(function_id)
|
|
238
242
|
rescue StandardError => e
|
|
239
|
-
|
|
243
|
+
raise if e.is_a?(NoMethodError) || e.is_a?(ArgumentError) || e.is_a?(TypeError)
|
|
244
|
+
|
|
245
|
+
handle_exception(e, level: :warn, operation: :lookup_target_schema, function_id: function_id)
|
|
240
246
|
nil
|
|
241
247
|
end
|
|
242
248
|
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
require 'legion/logging/helper'
|
|
4
|
+
|
|
5
|
+
require 'legion/extensions/synapse/data/models/synapse'
|
|
6
|
+
require 'legion/extensions/synapse/helpers/confidence'
|
|
5
7
|
|
|
6
8
|
module Legion
|
|
7
9
|
module Extensions
|
|
8
10
|
module Synapse
|
|
9
11
|
module Runners
|
|
10
12
|
module Retrieve
|
|
11
|
-
include Legion::Logging::Helper
|
|
13
|
+
include Legion::Logging::Helper
|
|
12
14
|
|
|
13
15
|
SEED_CONFIDENCE_THRESHOLD = 0.7
|
|
14
16
|
|
|
@@ -48,7 +50,9 @@ module Legion
|
|
|
48
50
|
|
|
49
51
|
content.is_a?(String) ? Legion::JSON.load(content) : content
|
|
50
52
|
rescue StandardError => e
|
|
51
|
-
|
|
53
|
+
raise if e.is_a?(NoMethodError) || e.is_a?(ArgumentError) || e.is_a?(TypeError)
|
|
54
|
+
|
|
55
|
+
handle_exception(e, level: :warn, operation: :parse_synapse_pattern)
|
|
52
56
|
nil
|
|
53
57
|
end
|
|
54
58
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/settings'
|
|
4
|
+
require 'legion/settings/helper'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module Synapse
|
|
9
|
+
module Settings
|
|
10
|
+
extend Legion::Settings::Helper
|
|
11
|
+
|
|
12
|
+
PROPOSALS = {
|
|
13
|
+
enabled: true,
|
|
14
|
+
reactive: true,
|
|
15
|
+
proactive: true,
|
|
16
|
+
proactive_interval: 300,
|
|
17
|
+
max_per_run: 3,
|
|
18
|
+
llm_engine_options: { temperature: 0.3, max_tokens: 1024 },
|
|
19
|
+
success_rate_threshold: 0.8,
|
|
20
|
+
payload_drift_threshold: 0.2,
|
|
21
|
+
dedup_window_hours: 24
|
|
22
|
+
}.freeze
|
|
23
|
+
|
|
24
|
+
CHALLENGE = {
|
|
25
|
+
enabled: true,
|
|
26
|
+
impact_threshold: 0.3,
|
|
27
|
+
auto_accept_threshold: 0.85,
|
|
28
|
+
auto_reject_threshold: 0.15,
|
|
29
|
+
llm_engine_options: { temperature: 0.2, max_tokens: 512 },
|
|
30
|
+
outcome_observation_window: 50,
|
|
31
|
+
max_per_cycle: 5,
|
|
32
|
+
review_max_attempts: 3,
|
|
33
|
+
review_retry_seconds: 300,
|
|
34
|
+
review_max_retry_seconds: 3600,
|
|
35
|
+
challenger_starting_confidence: 0.5,
|
|
36
|
+
challenger_correct_adjustment: 0.05,
|
|
37
|
+
challenger_incorrect_adjustment: -0.08
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
def self.segments = [:synapse]
|
|
41
|
+
|
|
42
|
+
def self.section(name:, **)
|
|
43
|
+
defaults = Legion::Extensions::Synapse.default_settings.fetch(name)
|
|
44
|
+
defaults.merge(settings.fetch(name, {}))
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.default_settings
|
|
49
|
+
{ proposals: Settings::PROPOSALS.dup, challenge: Settings::CHALLENGE.dup }
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lex-synapse
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.33
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Esity
|
|
@@ -202,6 +202,7 @@ files:
|
|
|
202
202
|
- lib/legion/extensions/synapse/runners/report.rb
|
|
203
203
|
- lib/legion/extensions/synapse/runners/retrieve.rb
|
|
204
204
|
- lib/legion/extensions/synapse/runners/revert.rb
|
|
205
|
+
- lib/legion/extensions/synapse/settings.rb
|
|
205
206
|
- lib/legion/extensions/synapse/transport.rb
|
|
206
207
|
- lib/legion/extensions/synapse/transport/exchanges/synapse.rb
|
|
207
208
|
- lib/legion/extensions/synapse/transport/messages/pain.rb
|