legion-data 1.1.5 → 1.3.7

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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +16 -0
  3. data/.gitignore +10 -2
  4. data/.rubocop.yml +41 -18
  5. data/CHANGELOG.md +82 -15
  6. data/CLAUDE.md +199 -0
  7. data/Gemfile +11 -1
  8. data/LICENSE +201 -0
  9. data/README.md +163 -19
  10. data/exe/legionio_migrate +0 -0
  11. data/legion-data.gemspec +22 -35
  12. data/lib/legion/data/connection.rb +39 -25
  13. data/lib/legion/data/encryption/cipher.rb +49 -0
  14. data/lib/legion/data/encryption/key_provider.rb +45 -0
  15. data/lib/legion/data/encryption/sequel_plugin.rb +54 -0
  16. data/lib/legion/data/event_store/projection.rb +56 -0
  17. data/lib/legion/data/event_store.rb +112 -0
  18. data/lib/legion/data/local.rb +77 -0
  19. data/lib/legion/data/migration.rb +5 -3
  20. data/lib/legion/data/migrations/001_add_schema_columns.rb +9 -3
  21. data/lib/legion/data/migrations/002_add_nodes.rb +18 -0
  22. data/lib/legion/data/migrations/003_add_settings.rb +18 -0
  23. data/lib/legion/data/migrations/004_add_extensions.rb +23 -0
  24. data/lib/legion/data/migrations/005_add_runners.rb +21 -0
  25. data/lib/legion/data/migrations/006_add_functions.rb +21 -0
  26. data/lib/legion/data/migrations/{015_add_default_extensions.rb → 007_add_default_extensions.rb} +3 -0
  27. data/lib/legion/data/migrations/008_add_tasks.rb +23 -0
  28. data/lib/legion/data/migrations/009_add_digital_workers.rb +45 -0
  29. data/lib/legion/data/migrations/010_add_value_metrics.rb +19 -0
  30. data/lib/legion/data/migrations/011_add_extensions_registry.rb +30 -0
  31. data/lib/legion/data/migrations/012_add_apollo_tables.rb +66 -0
  32. data/lib/legion/data/migrations/013_add_relationships.rb +21 -0
  33. data/lib/legion/data/migrations/014_add_relationship_columns.rb +27 -0
  34. data/lib/legion/data/migrations/015_add_rbac_tables.rb +49 -0
  35. data/lib/legion/data/migrations/016_add_worker_health.rb +33 -0
  36. data/lib/legion/data/migrations/017_add_audit_log.rb +30 -0
  37. data/lib/legion/data/migrations/018_add_governance_events.rb +21 -0
  38. data/lib/legion/data/migrations/019_add_audit_hash_chain.rb +29 -0
  39. data/lib/legion/data/migrations/020_add_webhooks.rb +37 -0
  40. data/lib/legion/data/model.rb +5 -2
  41. data/lib/legion/data/models/apollo_access_log.rb +13 -0
  42. data/lib/legion/data/models/apollo_entry.rb +18 -0
  43. data/lib/legion/data/models/apollo_expertise.rb +12 -0
  44. data/lib/legion/data/models/apollo_relation.rb +14 -0
  45. data/lib/legion/data/models/audit_log.rb +34 -0
  46. data/lib/legion/data/models/digital_worker.rb +44 -0
  47. data/lib/legion/data/models/extension.rb +0 -0
  48. data/lib/legion/data/models/function.rb +0 -2
  49. data/lib/legion/data/models/node.rb +17 -3
  50. data/lib/legion/data/models/rbac_cross_team_grant.rb +33 -0
  51. data/lib/legion/data/models/rbac_role_assignment.rb +29 -0
  52. data/lib/legion/data/models/rbac_runner_grant.rb +21 -0
  53. data/lib/legion/data/models/relationship.rb +3 -6
  54. data/lib/legion/data/models/runner.rb +0 -0
  55. data/lib/legion/data/models/setting.rb +0 -0
  56. data/lib/legion/data/models/task.rb +0 -0
  57. data/lib/legion/data/models/task_log.rb +0 -0
  58. data/lib/legion/data/settings.rb +37 -8
  59. data/lib/legion/data/version.rb +3 -1
  60. data/lib/legion/data.rb +31 -13
  61. metadata +64 -139
  62. data/.circleci/config.yml +0 -174
  63. data/.rspec +0 -1
  64. data/Gemfile.lock +0 -85
  65. data/Rakefile +0 -55
  66. data/bin/console +0 -14
  67. data/bin/setup +0 -8
  68. data/bitbucket-pipelines.yml +0 -26
  69. data/lib/legion/data/migrations/002_add_users.rb +0 -17
  70. data/lib/legion/data/migrations/003_add_groups.rb +0 -16
  71. data/lib/legion/data/migrations/004_add_chains.rb +0 -25
  72. data/lib/legion/data/migrations/005_add_envs.rb +0 -24
  73. data/lib/legion/data/migrations/006_add_dcs.rb +0 -24
  74. data/lib/legion/data/migrations/007_add_nodes.rb +0 -26
  75. data/lib/legion/data/migrations/008_add_settings.rb +0 -18
  76. data/lib/legion/data/migrations/009_add_extensions.rb +0 -25
  77. data/lib/legion/data/migrations/010_add_runners.rb +0 -21
  78. data/lib/legion/data/migrations/011_add_functions.rb +0 -29
  79. data/lib/legion/data/migrations/012_add_tasks.rb +0 -28
  80. data/lib/legion/data/migrations/013_add_task_logs.rb +0 -23
  81. data/lib/legion/data/migrations/014_add_relationships.rb +0 -27
  82. data/lib/legion/data/migrations/016_change_task_args.rb +0 -7
  83. data/lib/legion/data/migrations/017_add_payload_task.rb +0 -7
  84. data/lib/legion/data/migrations/018_add_migration_column.rb +0 -7
  85. data/lib/legion/data/migrations/019_add_debug_to_relationships.rb +0 -7
  86. data/lib/legion/data/migrations/020_add_delay_debug_to_tasks.rb +0 -8
  87. data/lib/legion/data/models/chain.rb +0 -11
  88. data/lib/legion/data/models/datacenter.rb +0 -11
  89. data/lib/legion/data/models/environment.rb +0 -11
  90. data/lib/legion/data/models/group.rb +0 -10
  91. data/lib/legion/data/models/user.rb +0 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '05917a40508eeb0fad578860bb1a13953eddc1eccf23f96792f2cc65fdfd8ee0'
4
- data.tar.gz: 394a1c4b2a7c8d022d04b97fb1a300a309b29a4b0a67de24258de75707a5ad9c
3
+ metadata.gz: d10f18bacc47360ad1829628bffc116ecbeea74b0b49359f1cee7fba0a7e9d44
4
+ data.tar.gz: e13f4acfa8992e3a00129322fef794b80877f723e0c59210016f64fee57c5cae
5
5
  SHA512:
6
- metadata.gz: 86564da23b0078eeb75d9c10c1810192f0eb7b092bad31645e06946d620a4d5bb0cc5259a3f12ee315289a64c7b137bc524f8ac8d7b13de2b76c01372bd48c04
7
- data.tar.gz: a3df723257736474cf2250112fe34732dcc275071ab62af5be3b397b848ac92233a2f31f86a6a0bc7b472727e3548f7cd4086d19734318d421f309dbe1baea6b
6
+ metadata.gz: 0e61649208294598ecdf19ffca469cba3db7b77d31e0e0a065e4c82e47949e4ea87aa291c5fae18970318e0c27ac1dfcd7eb53143bd7b5acc279eb84c0f2b231
7
+ data.tar.gz: 7692efc8d123ad178c3f3a66531723518e0fac2cb5999d01833bfa472ac8eb5bee06289dd193886fe66c369f3d49ebff689e68267eff4ab030ce746377a6c9a3
@@ -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 CHANGED
@@ -1,12 +1,20 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
+ /Gemfile.lock
3
4
  /_yardoc/
4
5
  /coverage/
5
6
  /doc/
6
7
  /pkg/
7
8
  /spec/reports/
8
9
  /tmp/
9
- /*.log
10
-
10
+ /legion/.idea/
11
+ /.idea/
12
+ *.key
11
13
  # rspec failure tracking
12
14
  .rspec_status
15
+ legionio.key
16
+ # logs and OS artifacts
17
+ legion.log
18
+ .DS_Store
19
+ # SQLite database files
20
+ *.db
data/.rubocop.yml CHANGED
@@ -1,28 +1,51 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
1
6
  Layout/LineLength:
2
- Max: 120
3
- Exclude:
4
- - 'lib/legion/data/migrations/*.rb'
5
- Metrics/MethodLength:
6
- Max: 30
7
- Metrics/ClassLength:
8
- Max: 1500
9
- Metrics/AbcSize:
10
- Max: 34
11
- Metrics/BlockLength:
12
- Max: 50
13
- Exclude:
14
- - 'lib/legion/data/migrations/*'
7
+ Max: 160
8
+
15
9
  Layout/SpaceAroundEqualsInParameterDefault:
16
10
  EnforcedStyle: space
17
- Style/SymbolArray:
18
- Enabled: true
11
+
19
12
  Layout/HashAlignment:
20
13
  EnforcedHashRocketStyle: table
21
14
  EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+ - 'lib/legion/data/migrations/**/*'
30
+
31
+ Metrics/AbcSize:
32
+ Max: 60
33
+
34
+ Metrics/CyclomaticComplexity:
35
+ Max: 15
36
+
37
+ Metrics/PerceivedComplexity:
38
+ Max: 17
39
+
22
40
  Style/Documentation:
23
41
  Enabled: false
24
- AllCops:
25
- TargetRubyVersion: 2.5
26
- NewCops: enable
42
+
43
+ Style/SymbolArray:
44
+ Enabled: true
45
+
27
46
  Style/FrozenStringLiteralComment:
47
+ Enabled: true
48
+ EnforcedStyle: always
49
+
50
+ Naming/FileName:
28
51
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,16 +1,83 @@
1
1
  # Legion::Data Changelog
2
- ## v1.1.2
3
- * Updating connection details to support JDBC
4
- * Changing default max connections to 10
5
- * Fixing issue with Legion::Cache always throwing an error
6
-
7
- ## v0.2.0
8
- * Redesigning schema
9
-
10
- ## v0.1.1
11
- * Updated `rubocop.yml` with updated syntax
12
- * Changing default connection count to 100 from 10
13
- * Updating some exception handling to meet rubocop requirements
14
- * Updating gemspec to have more things
15
- * Fixing logic in debug_logging
16
- * Adding RSpec tests for debug_logging
2
+
3
+ ## v1.3.7
4
+
5
+ ### Added
6
+ - Migration 020: `webhooks`, `webhook_deliveries`, `webhook_dead_letters` tables
7
+
8
+ ### Fixed
9
+ - Migration 019: guard against duplicate column adds when `record_hash` already exists from migration 017
10
+
11
+ ## v1.3.6
12
+
13
+ ### Added
14
+ - Migration 019: adds `record_hash`, `previous_hash`, `retention_tier` columns to `audit_log`
15
+
16
+ ## v1.3.5
17
+
18
+ ### Added
19
+ - `Legion::Data::EventStore`: append-only governance event store with stream semantics
20
+ - Hash chain integrity verification for tamper detection
21
+ - `EventStore::Projection` base class with `build_from` stream replay
22
+ - `ConsentState` projection: rebuild consent state from event history
23
+ - `GovernanceTimeline` projection: chronological governance event timeline
24
+ - Migration 018: governance_events table with stream/sequence indexing
25
+
26
+ ## v1.3.4
27
+
28
+ ### Added
29
+ - `Legion::Data::Encryption::Cipher`: AES-256-GCM with versioned binary format, random IV, and AAD
30
+ - `Legion::Data::Encryption::KeyProvider`: Vault-backed key derivation with local fallback for dev mode
31
+ - `Legion::Data::Encryption::SequelPlugin`: transparent `encrypted_column` DSL for Sequel models
32
+ - Per-tenant key scope support for cryptographic erasure compliance
33
+
34
+ ## v1.3.3
35
+
36
+ ### Added
37
+ - Migration 017: `audit_log` table with SHA-256 hash chain columns (`record_hash`, `prev_hash`)
38
+ - `Legion::Data::Model::AuditLog` immutable Sequel model with event type/status validation
39
+ - Indexes on `event_type`, `principal_id`, and `created_at` for audit query performance
40
+
41
+ ## v1.3.2
42
+
43
+ ### Added
44
+ - Migration 016: worker health columns (`health_status`, `last_heartbeat_at`, `health_node` on digital_workers; `metrics`, `hosted_worker_ids`, `version` on nodes)
45
+ - `DigitalWorker#health_status` validation against `HEALTH_STATUSES` (`online`, `offline`, `unknown`)
46
+ - `DigitalWorker#online?` and `DigitalWorker#offline?` convenience methods
47
+ - `Node#parsed_metrics` and `Node#parsed_hosted_worker_ids` JSON deserialization helpers
48
+
49
+ ## v1.3.1
50
+
51
+ ### Added
52
+ - Migration 015: RBAC tables (rbac_role_assignments, rbac_runner_grants, rbac_cross_team_grants)
53
+ - `Legion::Data::Model::RbacRoleAssignment` Sequel model with expiry and validation
54
+ - `Legion::Data::Model::RbacRunnerGrant` Sequel model with actions_list helper
55
+ - `Legion::Data::Model::RbacCrossTeamGrant` Sequel model with cross-team validation
56
+
57
+ ## v1.3.0
58
+
59
+ ### Added
60
+ - `Legion::Data::Local` module — parallel local SQLite database for agentic cognitive state persistence
61
+ - TimestampMigrator-based migration registration for per-extension local schemas
62
+ - `Legion::Data::Local.model(:table)` helper for local-bound Sequel models
63
+ - Dev mode fallback: shared DB falls back to SQLite when `dev_mode: true` and network DB unreachable
64
+ - New settings: `data.local.enabled`, `data.local.database`, `data.dev_mode`, `data.dev_fallback`
65
+ - `Legion::Data.local` accessor for the Local module
66
+ - Local connection lifecycle wired into `Legion::Data.setup` / `.shutdown`
67
+ - 13 new specs (62 total)
68
+
69
+ ## v1.2.2
70
+
71
+ ### Added
72
+ - Migration 014: add missing columns to `relationships` table (`delay`, `chain_id`, `debug`, `allow_new_chains`, `conditions`, `transformation`, `active`) required by lex-tasker query helpers
73
+
74
+ ## v1.2.1
75
+
76
+ ### Added
77
+ - Migration 013: `relationships` table with trigger/action foreign keys to functions
78
+ - `Legion::Data::Model::Relationship` Sequel model with trigger/action associations
79
+ - Relationship model registered in model loader (loaded before Task for association resolution)
80
+ - Uncommented `trigger_relationships` and `action_relationships` associations on Function model
81
+
82
+ ## v1.2.0
83
+ Moving from BitBucket to GitHub. All git history is reset from this point on
data/CLAUDE.md ADDED
@@ -0,0 +1,199 @@
1
+ # legion-data: Persistent Storage for LegionIO
2
+
3
+ **Repository Level 3 Documentation**
4
+ - **Parent**: `/Users/miverso2/rubymine/legion/CLAUDE.md`
5
+
6
+ ## Purpose
7
+
8
+ Manages persistent database storage for the LegionIO framework. Supports SQLite (default), MySQL, and PostgreSQL via Sequel ORM. Provides automatic schema migrations and data models for extensions, functions, runners, nodes, tasks, settings, digital workers, task relationships, and Apollo shared knowledge tables (PostgreSQL only). Also provides a parallel local SQLite database (`Legion::Data::Local`) for agentic cognitive state persistence.
9
+
10
+ **GitHub**: https://github.com/LegionIO/legion-data
11
+ **License**: Apache-2.0
12
+
13
+ ## Supported Databases
14
+
15
+ | Database | Adapter | Gem | Use Case |
16
+ |----------|---------|-----|----------|
17
+ | SQLite | `sqlite` | `sqlite3` (bundled) | Default, dev/test, single-node |
18
+ | MySQL | `mysql2` | `mysql2` (optional) | Production |
19
+ | PostgreSQL | `postgres` | `pg` (optional) | Production |
20
+
21
+ Adapter is set via `Legion::Settings[:data][:adapter]`. All migrations use Sequel DSL for cross-database compatibility.
22
+
23
+ ## Architecture
24
+
25
+ ```
26
+ Legion::Data (singleton module)
27
+ ├── .setup # Connect, migrate, load models, setup cache, setup local
28
+ ├── .connection # Sequel database handle (shared/central)
29
+ ├── .local # Legion::Data::Local accessor
30
+ ├── .shutdown # Close both connections
31
+
32
+ ├── Connection # Sequel database connection management (shared)
33
+ │ ├── .adapter # Reads from settings (sqlite, mysql2, postgres)
34
+ │ ├── .setup # Establish connection (dev_mode fallback to SQLite if network DB unreachable)
35
+ │ ├── .sequel # Raw Sequel::Database accessor
36
+ │ └── .shutdown # Close connection
37
+
38
+ ├── Local # Local SQLite database for agentic cognitive state
39
+ │ ├── .setup # Lazy init — creates legionio_local.db on first access
40
+ │ ├── .connection # Sequel::SQLite::Database handle
41
+ │ ├── .connected? # Whether local DB is active
42
+ │ ├── .db_path # Path to the local SQLite file
43
+ │ ├── .model(:table) # Create Sequel::Model bound to local connection
44
+ │ ├── .register_migrations(name:, path:) # Extensions register their migration dirs
45
+ │ ├── .shutdown # Close local connection
46
+ │ └── .reset! # Clear all state (testing)
47
+
48
+ ├── Migration # Auto-migration system (14 migrations, Sequel DSL)
49
+ │ └── migrations/
50
+ │ ├── 001_add_schema_columns
51
+ │ ├── 002_add_nodes
52
+ │ ├── 003_add_settings
53
+ │ ├── 004_add_extensions
54
+ │ ├── 005_add_runners
55
+ │ ├── 006_add_functions
56
+ │ ├── 007_add_default_extensions
57
+ │ ├── 008_add_tasks
58
+ │ ├── 009_add_digital_workers
59
+ │ ├── 010_add_value_metrics
60
+ │ ├── 011_add_extensions_registry
61
+ │ ├── 012_add_apollo_tables # postgres-only: pgvector, uuid-ossp, 4 apollo tables
62
+ │ ├── 013_add_relationships # relationships table with trigger/action FK to functions
63
+ │ ├── 014_add_relationship_columns # delay, chain_id, debug, conditions, transformation, active, allow_new_chains
64
+ │ ├── 015_add_rbac_tables
65
+ │ ├── 016_add_worker_health
66
+ │ ├── 017_add_audit_log
67
+ │ └── 018_add_governance_events # append-only event store with hash chain
68
+
69
+ ├── Model # Sequel model loader
70
+ │ └── Models/
71
+ │ ├── Extension # Installed LEX extensions
72
+ │ ├── Function # Available functions per extension (with trigger/action relationship associations)
73
+ │ ├── Runner # Runner definitions (extension + function bindings)
74
+ │ ├── Node # Cluster node registry
75
+ │ ├── Task # Task instances (belongs_to Relationship, belongs_to DigitalWorker)
76
+ │ ├── TaskLog # Task execution logs
77
+ │ ├── Setting # Persistent settings store
78
+ │ ├── DigitalWorker # Digital worker registry (lifecycle: bootstrap/active/paused/retired/terminated)
79
+ │ ├── Relationship # Task trigger/action relationships between functions (migration 013/014)
80
+ │ ├── ApolloEntry # Apollo knowledge entries — postgres only (pgvector embedding, confidence lifecycle)
81
+ │ ├── ApolloRelation # Weighted relations between Apollo entries — postgres only
82
+ │ ├── ApolloExpertise # Per-agent domain expertise tracking — postgres only
83
+ │ └── ApolloAccessLog # Apollo entry access audit log — postgres only
84
+ │ Note: value_metrics table (migration 010) is accessed via raw Sequel dataset,
85
+ │ not via a named Sequel::Model subclass.
86
+ │ Note: Apollo models are guarded with `return unless adapter == :postgres` at load time.
87
+
88
+ ├── Settings # Default DB config with per-adapter credential presets
89
+ └── Version
90
+ ```
91
+
92
+ ### Key Design Patterns
93
+
94
+ - **Two-Database Architecture**: Shared (MySQL/PG/SQLite) for control plane data + Local (always SQLite) for agentic cognitive state. Two files, always separate, no cross-database joins.
95
+ - **Adapter-Driven**: `Connection.adapter` reads from settings; SQLite uses `Sequel.sqlite(path)`, others use `Sequel.connect`
96
+ - **Dev Mode Fallback**: When `dev_mode: true` and network DB unreachable, shared connection falls back to SQLite (`legionio.db`) with warning log
97
+ - **Cross-DB Migrations**: Shared migrations use IntegerMigrator (Sequel DSL), local migrations use TimestampMigrator (per-extension registration)
98
+ - **Auto-Migration**: Runs Sequel migrations on startup (`auto_migrate: true` by default)
99
+ - **Sequel ORM**: Shared models are `Sequel::Model` subclasses (inherit global connection). Local models use `Legion::Data::Local.model(:table)` (explicit connection binding).
100
+ - **Optional Caching**: `setup_cache` checks for `Legion::Cache` presence but Sequel model caching is currently disabled (code is commented out, pending implementation)
101
+ - **Cryptographic Erasure**: Deleting `legionio_local.db` is a hard guarantee — no residual data. Used by `lex-privatecore`.
102
+ - **CLI Executable**: Ships with `legionio_migrate` executable in `exe/` for running database migrations standalone
103
+
104
+ ## Default Settings
105
+
106
+ ```json
107
+ {
108
+ "adapter": "sqlite",
109
+ "connected": false,
110
+ "dev_mode": false,
111
+ "dev_fallback": true,
112
+ "connect_on_start": true,
113
+ "connection": {
114
+ "log": false,
115
+ "log_connection_info": false,
116
+ "log_warn_duration": 1,
117
+ "sql_log_level": "debug",
118
+ "max_connections": 10,
119
+ "preconnect": false
120
+ },
121
+ "creds": {
122
+ "database": "legionio.db"
123
+ },
124
+ "migrations": {
125
+ "continue_on_fail": false,
126
+ "auto_migrate": true,
127
+ "ran": false,
128
+ "version": null
129
+ },
130
+ "models": {
131
+ "continue_on_load_fail": false,
132
+ "autoload": true
133
+ },
134
+ "local": {
135
+ "enabled": true,
136
+ "database": "legionio_local.db",
137
+ "migrations": {
138
+ "auto_migrate": true
139
+ }
140
+ },
141
+ "cache": {
142
+ "connected": false,
143
+ "auto_enable": false,
144
+ "ttl": 60
145
+ }
146
+ }
147
+ ```
148
+
149
+ Per-adapter credential defaults are defined in `Settings::CREDS`:
150
+ - **sqlite**: `{ database: "legionio.db" }`
151
+ - **mysql2**: `{ username: "legion", password: "legion", database: "legionio", host: "127.0.0.1", port: 3306 }`
152
+ - **postgres**: `{ user: "legion", password: "legion", database: "legionio", host: "127.0.0.1", port: 5432 }`
153
+
154
+ ## Dependencies
155
+
156
+ | Gem | Purpose |
157
+ |-----|---------|
158
+ | `sequel` (>= 5.70) | ORM and migration framework |
159
+ | `sqlite3` (>= 2.0) | SQLite adapter (default, bundled) |
160
+ | `mysql2` (>= 0.5.5) | MySQL adapter (optional) |
161
+ | `pg` (>= 1.5) | PostgreSQL adapter (optional) |
162
+ | `legion-logging` | Logging |
163
+ | `legion-settings` | Configuration |
164
+
165
+ ## File Map
166
+
167
+ | Path | Purpose |
168
+ |------|---------|
169
+ | `lib/legion/data.rb` | Module entry, setup/shutdown lifecycle |
170
+ | `lib/legion/data/connection.rb` | Sequel database connection (adapter selection) |
171
+ | `lib/legion/data/migration.rb` | Migration runner |
172
+ | `lib/legion/data/migrations/` | 14 numbered migration files (Sequel DSL) |
173
+ | `lib/legion/data/model.rb` | Model autoloader |
174
+ | `lib/legion/data/local.rb` | Local SQLite module for agentic cognitive state |
175
+ | `lib/legion/data/models/` | Sequel models (Extension, Function, Runner, Node, Task, TaskLog, Setting, DigitalWorker, Relationship, ApolloEntry, ApolloRelation, ApolloExpertise, ApolloAccessLog) |
176
+ | `lib/legion/data/encryption/cipher.rb` | AES-256-GCM encrypt/decrypt with versioned binary format and AAD |
177
+ | `lib/legion/data/encryption/key_provider.rb` | Vault-backed key derivation with per-tenant scope and local fallback |
178
+ | `lib/legion/data/encryption/sequel_plugin.rb` | Transparent `encrypted_column` DSL for Sequel models |
179
+ | `lib/legion/data/event_store.rb` | Append-only governance event store with hash chain integrity |
180
+ | `lib/legion/data/event_store/projection.rb` | Projection base class, ConsentState, GovernanceTimeline |
181
+ | `lib/legion/data/settings.rb` | Default configuration with per-adapter credential presets |
182
+ | `lib/legion/data/version.rb` | VERSION constant |
183
+ | `exe/legionio_migrate` | CLI executable for running database migrations standalone |
184
+
185
+ ## Role in LegionIO
186
+
187
+ Optional persistent storage initialized during `Legion::Service` startup (after transport). Provides:
188
+ 1. Extension and function registry (which LEXs are installed, what functions they expose)
189
+ 2. Task scheduling and logging
190
+ 3. Node cluster membership tracking
191
+ 4. Persistent settings storage
192
+ 5. Digital worker registry (AI-as-labor platform)
193
+ 6. Task relationship graph (trigger/action chains)
194
+ 7. Apollo shared knowledge store (PostgreSQL + pgvector only, used by lex-apollo)
195
+ 8. Local SQLite for agentic cognitive state (memory traces, trust scores, dream journals) — always on-node, independent of shared DB
196
+
197
+ ---
198
+
199
+ **Maintained By**: Matthew Iverson (@Esity)
data/Gemfile CHANGED
@@ -1,4 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- # Specify your gem's dependencies in legion-data.gemspec
4
5
  gemspec
6
+ group :test do
7
+ gem 'rake'
8
+ gem 'rspec'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'simplecov'
12
+ end
13
+ gem 'mysql2', '>= 0.5.5'
14
+ gem 'pg', '>= 1.5'
data/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2021 Esity
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.