lex-cognitive-archaeology 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b06b2250b06c73483e0a73ab31f46136c644d7a44646f6f81305940aaee3de6f
4
+ data.tar.gz: 80352c5869543380812a6ff1215bb37564b64e7d2d2c07b9a9d03ae4a977ba68
5
+ SHA512:
6
+ metadata.gz: 35086ac86f3f1b13c1da78a85822b688629d4808c90ec016075a54940d4f376e34794bb821abc745485ee59dfe33609448107bde8322ab9175d3b75eb62125c0
7
+ data.tar.gz: 89870d749c7ea60cab920f3615688a07d9e228ff203ede1a1171a9697231d8c7a489c9eb798342e38814fcf6f50a24e6ba622a5135420ca86c1751c201ca940d
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [main]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
10
+ Gemfile.lock
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper
2
+ --format documentation
data/.rubocop.yml ADDED
@@ -0,0 +1,38 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 200
8
+
9
+ Layout/HashAlignment:
10
+ EnforcedHashRocketStyle: table
11
+ EnforcedColonStyle: table
12
+
13
+ Metrics/MethodLength:
14
+ Max: 25
15
+
16
+ Metrics/ClassLength:
17
+ Max: 200
18
+
19
+ Metrics/BlockLength:
20
+ Max: 50
21
+ Exclude:
22
+ - 'spec/**/*'
23
+
24
+ Metrics/AbcSize:
25
+ Max: 25
26
+
27
+ Metrics/ParameterLists:
28
+ Max: 8
29
+ MaxOptionalParameters: 8
30
+
31
+ Style/Documentation:
32
+ Enabled: false
33
+
34
+ Naming/PredicateMethod:
35
+ Enabled: false
36
+
37
+ Naming/PredicatePrefix:
38
+ Enabled: false
data/CLAUDE.md ADDED
@@ -0,0 +1,102 @@
1
+ # lex-cognitive-archaeology
2
+
3
+ **Level 3 Documentation**
4
+ - **Parent**: `/Users/miverso2/rubymine/legion/extensions-agentic/CLAUDE.md`
5
+ - **Grandparent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
6
+
7
+ ## Purpose
8
+
9
+ Cognitive archaeology metaphor for recovering deeply buried cognitive artifacts — excavation sites have depth levels (surface to bedrock), and digging surfaces artifacts with type probabilities weighted by depth and epoch.
10
+
11
+ ## Gem Info
12
+
13
+ - **Gem name**: `lex-cognitive-archaeology`
14
+ - **Version**: `0.1.0`
15
+ - **Module**: `Legion::Extensions::CognitiveArchaeology`
16
+ - **Ruby**: `>= 3.4`
17
+ - **License**: MIT
18
+
19
+ ## File Structure
20
+
21
+ ```
22
+ lib/legion/extensions/cognitive_archaeology/
23
+ cognitive_archaeology.rb # Main extension module
24
+ version.rb # VERSION = '0.1.0'
25
+ client.rb # Client wrapper
26
+ helpers/
27
+ constants.rb # Artifact types, depth levels, epoch names, rarity weights, labels
28
+ artifact.rb # Artifact value object (type, depth, preservation, integrity, epoch)
29
+ site.rb # Site value object (domain, depth levels, artifacts collected)
30
+ archaeology_engine.rb # ArchaeologyEngine — manages sites, excavation, restoration
31
+ runners/
32
+ cognitive_archaeology.rb # Runner module (extend self) with 7 public methods
33
+ spec/
34
+ (spec files)
35
+ ```
36
+
37
+ ## Key Constants
38
+
39
+ ```ruby
40
+ ARTIFACT_TYPES = %i[pattern skill knowledge memory_fragment association procedure belief schema]
41
+ DOMAIN_TYPES = %i[general infrastructure reasoning memory identity emotional procedural]
42
+ EXCAVATION_DEPTH_LEVELS = %i[surface shallow mid deep bedrock]
43
+ EPOCH_NAMES = %i[recent near_past medium_past distant_past ancient]
44
+
45
+ # Weighted probability tables: deeper levels surface rarer types
46
+ DEPTH_RARITY_WEIGHTS = {
47
+ surface: { pattern: 30, skill: 20, knowledge: 25, memory_fragment: 15, association: 10, ... },
48
+ bedrock: { schema: 30, procedure: 25, belief: 20, memory_fragment: 15, association: 10, ... }
49
+ # ... (each depth has its own probability distribution)
50
+ }
51
+
52
+ PRESERVATION_LABELS = {
53
+ (0.8..) => :pristine, (0.6...0.8) => :intact, (0.4...0.6) => :damaged,
54
+ (0.2...0.4) => :fragmented, (..0.2) => :ruins
55
+ }
56
+ INTEGRITY_LABELS = {
57
+ (0.85..) => :complete, (0.65...0.85) => :mostly_complete, (0.45...0.65) => :partial,
58
+ (0.25...0.45) => :fragmentary, (..0.25) => :trace_only
59
+ }
60
+ DENSITY_LABELS = { (0.7..) => :rich, (0.4...0.7) => :moderate, (..0.4) => :sparse }
61
+ DEPTH_LABELS = {
62
+ surface: :contemporary, shallow: :recent_history, mid: :historical,
63
+ deep: :ancient_history, bedrock: :primordial
64
+ }
65
+ ```
66
+
67
+ ## Runners
68
+
69
+ ### `Runners::CognitiveArchaeology`
70
+
71
+ Uses `extend self` — methods are module-level, not instance-delegating. Delegates to a per-call `engine` (parameter-injected `Helpers::ArchaeologyEngine` instance via `engine:` keyword, defaulting to a shared `@engine ||=`).
72
+
73
+ - `create_site(name:, domain:, engine: @engine)` — register an excavation site with a domain; initializes depth tracking at `:surface`
74
+ - `dig(site_id:, depth_level:, engine: @engine)` — excavate at a specific depth; surfaces artifacts with type probabilities drawn from `DEPTH_RARITY_WEIGHTS[depth_level]`; returns artifact or `:empty` if nothing found
75
+ - `excavate(site_id:, engine: @engine)` — full excavation sweep across all depth levels; returns array of all found artifacts
76
+ - `restore_artifact(artifact_id:, engine: @engine)` — increase preservation and integrity of a damaged artifact; returns restoration result hash
77
+ - `list_artifacts(engine: @engine)` — all artifacts across all sites as array of hashes
78
+ - `archaeology_status(engine: @engine)` — summary: site count, artifact count, depth distribution, average preservation
79
+
80
+ ## Helpers
81
+
82
+ ### `Helpers::ArchaeologyEngine`
83
+ Core engine managing `@sites` and `@artifacts` hashes. `dig_at_depth` performs weighted random draw from `DEPTH_RARITY_WEIGHTS[depth_level]` to determine artifact type, then generates artifact with preservation and integrity values that decrease with depth (surface artifacts are better preserved). `excavate_site` calls `dig_at_depth` for each depth level. `restore` increases preservation and integrity values, clamped to 1.0.
84
+
85
+ ### `Helpers::Artifact`
86
+ Value object: type, depth_level, preservation (0.0–1.0), integrity (0.0–1.0), epoch (one of `EPOCH_NAMES`), site_id, domain. `preservation_label` and `integrity_label` map values to human-readable labels. `recoverable?` returns true when preservation > 0.2 (ruins are not recoverable).
87
+
88
+ ### `Helpers::Site`
89
+ Value object: name, domain, depths_excavated array, artifact_ids array. `excavated_at?(depth_level)` checks whether a depth has been visited. `add_artifact!` records an artifact ID.
90
+
91
+ ## Integration Points
92
+
93
+ No actor defined. This extension models recovery of deeply buried cognitive content — ancient patterns, procedures, and schemas that are hard to access but high-value. Pairs with lex-memory (archaeology surfaces artifacts that map to memory traces by type: `:memory_fragment` artifacts correlate to `episodic` traces, `:schema` artifacts to `semantic` traces). Pairs with lex-cognitive-apprenticeship (archaeological recovery of a `:procedure` artifact can seed a new apprenticeship). Pairs with lex-dream (dream association walks can trigger archaeology to surface related ancient associations).
94
+
95
+ ## Development Notes
96
+
97
+ - `extend self` pattern: runner is a module with module-level methods; shared `@engine` lives in the module's singleton
98
+ - `DEPTH_RARITY_WEIGHTS` is the core mechanic: each depth level has its own weighted probability table; deeper levels have higher weights for rare types (`:schema`, `:procedure`) and lower weights for common types (`:pattern`, `:knowledge`)
99
+ - `dig` at `:surface` is more likely to surface `:pattern` and `:knowledge`; `dig` at `:bedrock` is more likely to surface `:schema` and `:procedure`
100
+ - Preservation values decrease with depth: surface artifacts start at high preservation; bedrock artifacts start degraded
101
+ - `restore_artifact` is the repair pathway — callers must actively restore damaged/fragmented artifacts before using them
102
+ - Epoch names (`:recent` to `:ancient`) are assigned based on depth level, providing temporal context for recovered artifacts
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'rspec', '~> 3.13'
9
+ gem 'rubocop', '~> 1.75', require: false
10
+ gem 'rubocop-rspec', require: false
11
+ end
12
+
13
+ gem 'legion-gaia', path: '../../legion-gaia'
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # lex-cognitive-archaeology
2
+
3
+ Cognitive archaeology metaphor for recovering deeply buried cognitive artifacts — excavation sites, depth-weighted artifact discovery, and restoration.
4
+
5
+ ## What It Does
6
+
7
+ Models the retrieval of deeply buried cognitive content as archaeological excavation. Sites have five depth levels (surface to bedrock), and digging at different depths surfaces different artifact types according to weighted probability tables. Surface digs find common patterns and knowledge; bedrock digs surface rare schemas and procedures. Artifacts degrade with depth — ancient finds need restoration.
8
+
9
+ ## Core Concept: Depth and Rarity
10
+
11
+ ```
12
+ surface -> common types (pattern, knowledge) -> high preservation
13
+ shallow -> mixed types -> good preservation
14
+ mid -> deeper history -> moderate preservation
15
+ deep -> ancient history -> degraded
16
+ bedrock -> primordial (schema, procedure, belief) -> ruins
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ client = Legion::Extensions::CognitiveArchaeology::Client.new
23
+
24
+ # Open an excavation site
25
+ site = client.create_site(name: :infrastructure_knowledge_base, domain: :infrastructure)
26
+
27
+ # Dig at a specific depth
28
+ artifact = client.dig(site_id: site[:site][:id], depth_level: :surface)
29
+ # => { artifact: { type: :pattern, preservation: 0.91, integrity: 0.88, epoch: :recent, ... } }
30
+
31
+ # Dig deeper for rarer artifacts
32
+ deep_find = client.dig(site_id: site[:site][:id], depth_level: :bedrock)
33
+ # => { artifact: { type: :schema, preservation: 0.23, integrity: 0.31, epoch: :ancient, ... } }
34
+
35
+ # Restore a damaged artifact
36
+ client.restore_artifact(artifact_id: deep_find[:artifact][:id])
37
+ # => { artifact: { preservation: 0.45, integrity: 0.52, ... } }
38
+
39
+ # Full excavation sweep across all depth levels
40
+ client.excavate(site_id: site[:site][:id])
41
+ # => { artifacts: [...all found artifacts across all depths...] }
42
+
43
+ # Check overall dig status
44
+ client.archaeology_status
45
+ # => { site_count: 1, artifact_count: 6, depth_distribution: {...}, avg_preservation: 0.61 }
46
+ ```
47
+
48
+ ## Integration
49
+
50
+ Pairs with lex-memory (artifact types map to memory trace types: `:memory_fragment` -> episodic, `:schema` -> semantic). Pairs with lex-cognitive-apprenticeship (a recovered `:procedure` artifact can seed a new apprenticeship). Pairs with lex-dream (dream association walks can trigger archaeology to surface related ancient associations).
51
+
52
+ ## Development
53
+
54
+ ```bash
55
+ bundle install
56
+ bundle exec rspec
57
+ bundle exec rubocop
58
+ ```
59
+
60
+ ## License
61
+
62
+ MIT
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/cognitive_archaeology/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-cognitive-archaeology'
7
+ spec.version = Legion::Extensions::CognitiveArchaeology::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX Cognitive Archaeology'
12
+ spec.description = 'Excavates buried cognitive artifacts from deep memory layers — ' \
13
+ 'uncovers forgotten patterns, dormant skills, and latent knowledge ' \
14
+ 'that was formed but never fully integrated'
15
+ spec.homepage = 'https://github.com/LegionIO/lex-cognitive-archaeology'
16
+ spec.license = 'MIT'
17
+
18
+ spec.required_ruby_version = '>= 3.4'
19
+
20
+ spec.metadata['homepage_uri'] = spec.homepage
21
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-cognitive-archaeology'
22
+ spec.metadata['documentation_uri'] = 'https://github.com/LegionIO/lex-cognitive-archaeology'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-cognitive-archaeology'
24
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/LegionIO/lex-cognitive-archaeology/issues'
25
+ spec.metadata['rubygems_mfa_required'] = 'true'
26
+
27
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+
31
+ spec.require_paths = ['lib']
32
+ spec.add_development_dependency 'legion-gaia'
33
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module CognitiveArchaeology
6
+ class Client
7
+ include Runners::CognitiveArchaeology
8
+
9
+ def initialize(engine: nil)
10
+ @default_engine = engine || Helpers::ArchaeologyEngine.new
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module CognitiveArchaeology
6
+ module Helpers
7
+ class ArchaeologyEngine
8
+ def initialize
9
+ @sites = {}
10
+ @artifacts = {}
11
+ end
12
+
13
+ def create_site(domain:)
14
+ validate_site_capacity!
15
+ site = ExcavationSite.new(domain: domain)
16
+ @sites[site.id] = site
17
+ site
18
+ end
19
+
20
+ def dig(site_id:)
21
+ site = fetch_site!(site_id)
22
+ dug = site.dig_deeper!
23
+ { site: site.survey, dug: dug }
24
+ end
25
+
26
+ def excavate(site_id:)
27
+ site = fetch_site!(site_id)
28
+ validate_artifact_capacity!
29
+ artifact = site.excavate!
30
+ @artifacts[artifact.id] = artifact
31
+ artifact
32
+ end
33
+
34
+ def restore_artifact(artifact_id:, boost: 0.15)
35
+ artifact = fetch_artifact!(artifact_id)
36
+ artifact.restore!(boost: boost)
37
+ artifact
38
+ end
39
+
40
+ def decay_all!(rate: Constants::PRESERVATION_DECAY)
41
+ @artifacts.each_value { |a| a.decay!(rate: rate) }
42
+ prune_dust!
43
+ @artifacts.size
44
+ end
45
+
46
+ def artifacts_by_type(type)
47
+ @artifacts.values.select { |a| a.artifact_type == type.to_sym }
48
+ end
49
+
50
+ def artifacts_by_domain(domain)
51
+ @artifacts.values.select { |a| a.domain == domain.to_sym }
52
+ end
53
+
54
+ def artifacts_by_depth(depth_level)
55
+ @artifacts.values.select do |a|
56
+ a.depth_level == depth_level.to_sym
57
+ end
58
+ end
59
+
60
+ def best_preserved(limit: 10)
61
+ @artifacts.values.sort_by { |a| -a.preservation }.first(limit)
62
+ end
63
+
64
+ def most_fragile(limit: 10)
65
+ @artifacts.values
66
+ .select(&:fragment?)
67
+ .sort_by(&:preservation)
68
+ .first(limit)
69
+ end
70
+
71
+ def site_report(site_id:)
72
+ fetch_site!(site_id).to_h
73
+ end
74
+
75
+ def archaeology_report
76
+ {
77
+ total_artifacts: @artifacts.size,
78
+ total_sites: @sites.size,
79
+ type_breakdown: type_breakdown,
80
+ domain_breakdown: domain_breakdown,
81
+ depth_breakdown: depth_breakdown,
82
+ avg_preservation: avg_preservation,
83
+ avg_integrity: avg_integrity,
84
+ fragment_count: @artifacts.values.count(&:fragment?),
85
+ ancient_count: @artifacts.values.count(&:ancient?),
86
+ sites: @sites.values.map { |s| site_summary(s) }
87
+ }
88
+ end
89
+
90
+ def all_artifacts
91
+ @artifacts.values
92
+ end
93
+
94
+ def all_sites
95
+ @sites.values
96
+ end
97
+
98
+ private
99
+
100
+ def fetch_site!(site_id)
101
+ @sites.fetch(site_id) do
102
+ raise ArgumentError, "site not found: #{site_id.inspect}"
103
+ end
104
+ end
105
+
106
+ def fetch_artifact!(artifact_id)
107
+ @artifacts.fetch(artifact_id) do
108
+ raise ArgumentError,
109
+ "artifact not found: #{artifact_id.inspect}"
110
+ end
111
+ end
112
+
113
+ def validate_site_capacity!
114
+ return if @sites.size < Constants::MAX_SITES
115
+
116
+ raise ArgumentError,
117
+ "site capacity reached (max #{Constants::MAX_SITES})"
118
+ end
119
+
120
+ def validate_artifact_capacity!
121
+ return if @artifacts.size < Constants::MAX_ARTIFACTS
122
+
123
+ raise ArgumentError,
124
+ "artifact capacity reached (max #{Constants::MAX_ARTIFACTS})"
125
+ end
126
+
127
+ def prune_dust!
128
+ @artifacts.delete_if { |_, a| a.preservation <= 0.0 }
129
+ end
130
+
131
+ def type_breakdown
132
+ count_by(:artifact_type, Constants::ARTIFACT_TYPES)
133
+ end
134
+
135
+ def domain_breakdown
136
+ count_by(:domain, Constants::DOMAIN_TYPES)
137
+ end
138
+
139
+ def depth_breakdown
140
+ count_by(:depth_level, Constants::EXCAVATION_DEPTH_LEVELS)
141
+ end
142
+
143
+ def count_by(attr, values)
144
+ values.to_h do |v|
145
+ [v, @artifacts.values.count { |a| a.public_send(attr) == v }]
146
+ end
147
+ end
148
+
149
+ def avg_preservation
150
+ return 0.0 if @artifacts.empty?
151
+
152
+ (@artifacts.values.sum(&:preservation) / @artifacts.size).round(10)
153
+ end
154
+
155
+ def avg_integrity
156
+ return 0.0 if @artifacts.empty?
157
+
158
+ (@artifacts.values.sum(&:integrity) / @artifacts.size).round(10)
159
+ end
160
+
161
+ def site_summary(site)
162
+ site.survey.merge(
163
+ depth_progress: depth_progress(site),
164
+ artifact_types: site.artifacts_found
165
+ .each_with_object(Hash.new(0)) do |a, h|
166
+ h[a.artifact_type] += 1
167
+ end
168
+ )
169
+ end
170
+
171
+ def depth_progress(site)
172
+ idx = Constants::EXCAVATION_DEPTH_LEVELS.index(site.current_depth)
173
+ total = Constants::EXCAVATION_DEPTH_LEVELS.size - 1
174
+ total.zero? ? 1.0 : (idx.to_f / total).round(4)
175
+ end
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,142 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module CognitiveArchaeology
8
+ module Helpers
9
+ class Artifact
10
+ attr_reader :id, :artifact_type, :domain, :content, :depth_level,
11
+ :discovered_at, :origin_epoch, :contextual_links
12
+
13
+ attr_accessor :preservation_quality, :integrity
14
+
15
+ alias type artifact_type
16
+
17
+ def initialize(type:, domain:, content:, depth_level:,
18
+ preservation: nil, integrity: nil,
19
+ origin_epoch: nil, contextual_links: nil)
20
+ validate_type!(type)
21
+ validate_domain!(domain)
22
+ validate_depth!(depth_level)
23
+
24
+ @id = SecureRandom.uuid
25
+ @artifact_type = type.to_sym
26
+ @domain = domain.to_sym
27
+ @content = content.to_s
28
+ @depth_level = depth_level.to_sym
29
+ pres = (preservation || Constants::DEFAULT_PRESERVATION).to_f
30
+ @preservation_quality = pres.clamp(0.0, 1.0).round(10)
31
+ @integrity = (integrity || derive_integrity).clamp(0.0, 1.0).round(10)
32
+ @discovered_at = Time.now.utc
33
+ @origin_epoch = origin_epoch || (Time.now.utc - rand(0..31_536_000))
34
+ @contextual_links = Array(contextual_links).dup
35
+ end
36
+
37
+ def preservation
38
+ @preservation_quality
39
+ end
40
+
41
+ def preservation=(val)
42
+ @preservation_quality = val.to_f.clamp(0.0, 1.0).round(10)
43
+ end
44
+
45
+ def decay!(rate: Constants::PRESERVATION_DECAY)
46
+ @preservation_quality = (@preservation_quality - rate.abs).clamp(0.0, 1.0).round(10)
47
+ @integrity = (@integrity - (rate.abs * 0.5)).clamp(0.0, 1.0).round(10)
48
+ self
49
+ end
50
+
51
+ def restore!(boost: 0.15)
52
+ @preservation_quality = (@preservation_quality + boost.abs).clamp(0.0, 1.0).round(10)
53
+ @integrity = (@integrity + (boost.abs * 0.5)).clamp(0.0, 1.0).round(10)
54
+ self
55
+ end
56
+
57
+ def fragment?
58
+ @preservation_quality < 0.3
59
+ end
60
+
61
+ def well_preserved?
62
+ @preservation_quality > 0.7
63
+ end
64
+
65
+ def ancient?
66
+ (Time.now.utc - @origin_epoch) > 15_552_000
67
+ end
68
+
69
+ def preservation_label
70
+ match_label(Constants::PRESERVATION_LABELS, @preservation_quality)
71
+ end
72
+
73
+ def integrity_label
74
+ match_label(Constants::INTEGRITY_LABELS, @integrity)
75
+ end
76
+
77
+ def link_to(other_id)
78
+ @contextual_links << other_id unless @contextual_links.include?(other_id)
79
+ end
80
+
81
+ def to_h
82
+ {
83
+ id: @id,
84
+ type: @artifact_type,
85
+ artifact_type: @artifact_type,
86
+ domain: @domain,
87
+ content: @content,
88
+ depth_level: @depth_level,
89
+ preservation: @preservation_quality,
90
+ preservation_quality: @preservation_quality,
91
+ preservation_label: preservation_label,
92
+ integrity: @integrity,
93
+ integrity_label: integrity_label,
94
+ discovered_at: @discovered_at,
95
+ origin_epoch: @origin_epoch,
96
+ contextual_links: @contextual_links,
97
+ fragment: fragment?,
98
+ well_preserved: well_preserved?,
99
+ ancient: ancient?
100
+ }
101
+ end
102
+
103
+ private
104
+
105
+ def derive_integrity
106
+ depth_mod = Constants::DEPTH_PRESERVATION_MODIFIER.fetch(@depth_level, 0.0)
107
+ (0.8 + depth_mod + rand(-0.1..0.1)).clamp(0.0, 1.0)
108
+ end
109
+
110
+ def validate_type!(type_val)
111
+ return if Constants::ARTIFACT_TYPES.include?(type_val.to_sym)
112
+
113
+ raise ArgumentError,
114
+ "unknown artifact type: #{type_val.inspect}; " \
115
+ "must be one of #{Constants::ARTIFACT_TYPES.inspect}"
116
+ end
117
+
118
+ def validate_domain!(domain_val)
119
+ return if Constants::DOMAIN_TYPES.include?(domain_val.to_sym)
120
+
121
+ raise ArgumentError,
122
+ "unknown domain: #{domain_val.inspect}; " \
123
+ "must be one of #{Constants::DOMAIN_TYPES.inspect}"
124
+ end
125
+
126
+ def validate_depth!(depth_val)
127
+ return if Constants::EXCAVATION_DEPTH_LEVELS.include?(depth_val.to_sym)
128
+
129
+ raise ArgumentError,
130
+ "unknown depth level: #{depth_val.inspect}; " \
131
+ "must be one of #{Constants::EXCAVATION_DEPTH_LEVELS.inspect}"
132
+ end
133
+
134
+ def match_label(label_table, value)
135
+ label_table.each { |range, label| return label if range.cover?(value) }
136
+ label_table.last.last
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module CognitiveArchaeology
6
+ module Helpers
7
+ module Constants
8
+ MAX_ARTIFACTS = 500
9
+ MAX_SITES = 50
10
+ DEFAULT_PRESERVATION = 0.5
11
+ PRESERVATION_DECAY = 0.02
12
+ SEDIMENT_DENSITY_DEFAULT = 0.5
13
+
14
+ ARTIFACT_TYPES = %i[
15
+ pattern skill knowledge memory_fragment
16
+ association procedure belief schema
17
+ ].freeze
18
+
19
+ DOMAIN_TYPES = %i[
20
+ cognitive emotional procedural semantic
21
+ episodic social creative analytical
22
+ ].freeze
23
+
24
+ EXCAVATION_DEPTH_LEVELS = %i[surface shallow mid deep bedrock].freeze
25
+
26
+ EPOCH_NAMES = %i[
27
+ genesis formation expansion consolidation
28
+ crisis renewal maturation current
29
+ ].freeze
30
+
31
+ DEPTH_PRESERVATION_MODIFIER = {
32
+ surface: 0.0,
33
+ shallow: -0.1,
34
+ mid: -0.2,
35
+ deep: -0.35,
36
+ bedrock: -0.5
37
+ }.freeze
38
+
39
+ DEPTH_RARITY_WEIGHTS = {
40
+ surface: { pattern: 3, skill: 2, knowledge: 3, memory_fragment: 5,
41
+ association: 3, procedure: 2, belief: 1, schema: 1 },
42
+ shallow: { pattern: 3, skill: 3, knowledge: 3, memory_fragment: 4,
43
+ association: 3, procedure: 3, belief: 1, schema: 1 },
44
+ mid: { pattern: 2, skill: 3, knowledge: 3, memory_fragment: 3,
45
+ association: 3, procedure: 3, belief: 2, schema: 2 },
46
+ deep: { pattern: 1, skill: 2, knowledge: 2, memory_fragment: 2,
47
+ association: 2, procedure: 3, belief: 3, schema: 3 },
48
+ bedrock: { pattern: 1, skill: 1, knowledge: 1, memory_fragment: 1,
49
+ association: 1, procedure: 2, belief: 4, schema: 4 }
50
+ }.freeze
51
+
52
+ PRESERVATION_LABELS = [
53
+ [0.0..0.2, :dust],
54
+ [0.2..0.4, :fragmented],
55
+ [0.4..0.6, :partial],
56
+ [0.6..0.8, :intact],
57
+ [0.8..1.0, :pristine]
58
+ ].freeze
59
+
60
+ INTEGRITY_LABELS = [
61
+ [0.0..0.3, :corrupted],
62
+ [0.3..0.6, :degraded],
63
+ [0.6..0.8, :coherent],
64
+ [0.8..1.0, :complete]
65
+ ].freeze
66
+
67
+ DENSITY_LABELS = [
68
+ [0.0..0.2, :friable],
69
+ [0.2..0.4, :loose],
70
+ [0.4..0.6, :moderate],
71
+ [0.6..0.8, :dense],
72
+ [0.8..1.0, :compacted]
73
+ ].freeze
74
+
75
+ DEPTH_LABELS = {
76
+ surface: 'Surface Layer (recent, well-preserved)',
77
+ shallow: 'Shallow Layer (familiar but fading)',
78
+ mid: 'Mid Layer (semi-dormant knowledge)',
79
+ deep: 'Deep Layer (long-dormant patterns)',
80
+ bedrock: 'Bedrock Layer (foundational cognitive strata)'
81
+ }.freeze
82
+
83
+ def self.label_for(table, value)
84
+ table.each { |range, label| return label if range.cover?(value) }
85
+ table.last.last
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,93 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module CognitiveArchaeology
6
+ module Helpers
7
+ class ExcavationSite
8
+ include Constants
9
+
10
+ attr_reader :id, :domain, :current_depth, :artifacts_found, :created_at
11
+
12
+ alias started_at created_at
13
+
14
+ def initialize(domain:)
15
+ validate_domain!(domain)
16
+ @id = SecureRandom.uuid
17
+ @domain = domain.to_sym
18
+ @current_depth = :surface
19
+ @artifacts_found = []
20
+ @created_at = Time.now.utc
21
+ end
22
+
23
+ def dig_deeper!
24
+ idx = EXCAVATION_DEPTH_LEVELS.index(@current_depth) || 0
25
+ return false if idx >= EXCAVATION_DEPTH_LEVELS.size - 1
26
+
27
+ @current_depth = EXCAVATION_DEPTH_LEVELS[idx + 1]
28
+ true
29
+ end
30
+
31
+ def complete?
32
+ @current_depth == EXCAVATION_DEPTH_LEVELS.last
33
+ end
34
+
35
+ def excavate!
36
+ weights = DEPTH_RARITY_WEIGHTS.fetch(@current_depth, {})
37
+ art_type = weighted_pick(weights)
38
+ artifact = Artifact.new(type: art_type, domain: @domain,
39
+ content: "#{art_type} from #{@current_depth}",
40
+ depth_level: @current_depth,
41
+ preservation: compute_base_preservation)
42
+ @artifacts_found << artifact
43
+ artifact
44
+ end
45
+
46
+ def survey
47
+ {
48
+ id: @id,
49
+ domain: @domain,
50
+ current_depth: @current_depth,
51
+ depth_label: DEPTH_LABELS.fetch(@current_depth, 'Unknown'),
52
+ artifacts_count: @artifacts_found.size,
53
+ complete: complete?,
54
+ started_at: @created_at.iso8601
55
+ }
56
+ end
57
+
58
+ def to_h
59
+ survey.merge(artifacts: @artifacts_found.map(&:to_h))
60
+ end
61
+
62
+ private
63
+
64
+ def validate_domain!(domain_val)
65
+ return if DOMAIN_TYPES.include?(domain_val.to_sym)
66
+
67
+ raise ArgumentError,
68
+ "unknown domain: #{domain_val.inspect}; " \
69
+ "must be one of #{DOMAIN_TYPES.inspect}"
70
+ end
71
+
72
+ def weighted_pick(weights)
73
+ total = weights.values.sum
74
+ return ARTIFACT_TYPES.sample if total.zero?
75
+
76
+ roll = rand(total)
77
+ cumulative = 0
78
+ weights.each do |type, weight|
79
+ cumulative += weight
80
+ return type if roll < cumulative
81
+ end
82
+ weights.keys.last
83
+ end
84
+
85
+ def compute_base_preservation
86
+ mod = DEPTH_PRESERVATION_MODIFIER.fetch(@current_depth, 0.0)
87
+ (DEFAULT_PRESERVATION + mod).clamp(0.0, 1.0)
88
+ end
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module CognitiveArchaeology
6
+ module Runners
7
+ module CognitiveArchaeology
8
+ extend self
9
+
10
+ def create_site(domain:, engine: nil, **)
11
+ eng = resolve_engine(engine)
12
+ site = eng.create_site(domain: domain)
13
+ { success: true, site: site.survey }
14
+ rescue ArgumentError => e
15
+ { success: false, error: e.message }
16
+ end
17
+
18
+ def dig(site_id:, engine: nil, **)
19
+ eng = resolve_engine(engine)
20
+ result = eng.dig(site_id: site_id)
21
+ { success: true }.merge(result)
22
+ rescue ArgumentError => e
23
+ { success: false, error: e.message }
24
+ end
25
+
26
+ def excavate(site_id:, engine: nil, **)
27
+ eng = resolve_engine(engine)
28
+ artifact = eng.excavate(site_id: site_id)
29
+ { success: true, artifact: artifact.to_h }
30
+ rescue ArgumentError => e
31
+ { success: false, error: e.message }
32
+ end
33
+
34
+ def restore_artifact(artifact_id:, boost: 0.15, engine: nil, **)
35
+ eng = resolve_engine(engine)
36
+ artifact = eng.restore_artifact(
37
+ artifact_id: artifact_id, boost: boost
38
+ )
39
+ { success: true, artifact: artifact.to_h }
40
+ rescue ArgumentError => e
41
+ { success: false, error: e.message }
42
+ end
43
+
44
+ def list_artifacts(engine: nil, type: nil, domain: nil,
45
+ depth_level: nil, **)
46
+ eng = resolve_engine(engine)
47
+ results = filter_results(eng.all_artifacts,
48
+ type: type, domain: domain,
49
+ depth_level: depth_level)
50
+ { success: true, artifacts: results.map(&:to_h),
51
+ count: results.size }
52
+ end
53
+
54
+ def archaeology_status(engine: nil, **)
55
+ eng = resolve_engine(engine)
56
+ { success: true, report: eng.archaeology_report }
57
+ end
58
+
59
+ include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
60
+
61
+ private
62
+
63
+ def filter_results(artifacts, type:, domain:, depth_level:)
64
+ r = artifacts
65
+ r = r.select { |a| a.artifact_type == type.to_sym } if type
66
+ r = r.select { |a| a.domain == domain.to_sym } if domain
67
+ r = r.select { |a| a.depth_level == depth_level.to_sym } if depth_level
68
+ r
69
+ end
70
+
71
+ def resolve_engine(engine)
72
+ engine || default_engine
73
+ end
74
+
75
+ def default_engine
76
+ @default_engine ||= Helpers::ArchaeologyEngine.new
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module CognitiveArchaeology
6
+ VERSION = '0.1.0'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ require_relative 'cognitive_archaeology/version'
6
+ require_relative 'cognitive_archaeology/helpers/constants'
7
+ require_relative 'cognitive_archaeology/helpers/artifact'
8
+ require_relative 'cognitive_archaeology/helpers/excavation_site'
9
+ require_relative 'cognitive_archaeology/helpers/archaeology_engine'
10
+ require_relative 'cognitive_archaeology/runners/cognitive_archaeology'
11
+ require_relative 'cognitive_archaeology/client'
12
+
13
+ module Legion
14
+ module Extensions
15
+ module CognitiveArchaeology
16
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
17
+ end
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-cognitive-archaeology
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: Excavates buried cognitive artifacts from deep memory layers — uncovers
27
+ forgotten patterns, dormant skills, and latent knowledge that was formed but never
28
+ fully integrated
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
+ - README.md
42
+ - lex-cognitive-archaeology.gemspec
43
+ - lib/legion/extensions/cognitive_archaeology.rb
44
+ - lib/legion/extensions/cognitive_archaeology/client.rb
45
+ - lib/legion/extensions/cognitive_archaeology/helpers/archaeology_engine.rb
46
+ - lib/legion/extensions/cognitive_archaeology/helpers/artifact.rb
47
+ - lib/legion/extensions/cognitive_archaeology/helpers/constants.rb
48
+ - lib/legion/extensions/cognitive_archaeology/helpers/excavation_site.rb
49
+ - lib/legion/extensions/cognitive_archaeology/runners/cognitive_archaeology.rb
50
+ - lib/legion/extensions/cognitive_archaeology/version.rb
51
+ homepage: https://github.com/LegionIO/lex-cognitive-archaeology
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ homepage_uri: https://github.com/LegionIO/lex-cognitive-archaeology
56
+ source_code_uri: https://github.com/LegionIO/lex-cognitive-archaeology
57
+ documentation_uri: https://github.com/LegionIO/lex-cognitive-archaeology
58
+ changelog_uri: https://github.com/LegionIO/lex-cognitive-archaeology
59
+ bug_tracker_uri: https://github.com/LegionIO/lex-cognitive-archaeology/issues
60
+ rubygems_mfa_required: 'true'
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.6.9
76
+ specification_version: 4
77
+ summary: LEX Cognitive Archaeology
78
+ test_files: []