{"id":47633910,"url":"https://github.com/legionio/lex-synapse","last_synced_at":"2026-04-07T01:01:35.467Z","repository":{"id":345281932,"uuid":"1184690002","full_name":"LegionIO/lex-synapse","owner":"LegionIO","description":"Cognitive routing layer for LegionIO task chains — attention, transformation, and routing with confidence scoring, pain signals, and self-governance","archived":false,"fork":false,"pushed_at":"2026-03-31T23:36:46.000Z","size":216,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-02T07:58:58.152Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LegionIO.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-17T20:49:00.000Z","updated_at":"2026-03-31T23:36:16.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/LegionIO/lex-synapse","commit_stats":null,"previous_names":["legionio/lex-synapse"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/LegionIO/lex-synapse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegionIO%2Flex-synapse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegionIO%2Flex-synapse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegionIO%2Flex-synapse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegionIO%2Flex-synapse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LegionIO","download_url":"https://codeload.github.com/LegionIO/lex-synapse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LegionIO%2Flex-synapse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31495466,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-06T17:22:55.647Z","status":"ssl_error","status_checked_at":"2026-04-06T17:22:54.741Z","response_time":112,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-01T23:57:53.076Z","updated_at":"2026-04-07T01:01:35.428Z","avatar_url":"https://github.com/LegionIO.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lex-synapse\n\nCognitive routing layer for [LegionIO](https://github.com/LegionIO/LegionIO) task chains. Wraps task relationships with observation, learning, confidence scoring, pain signals, and self-governance.\n\n## Installation\n\n```bash\ngem install lex-synapse\n```\n\nOr add to your Gemfile:\n\n```ruby\ngem 'lex-synapse'\n```\n\n## Standalone Client\n\nUse the synapse engine without the full LegionIO framework:\n\n```ruby\nrequire 'legion/extensions/synapse/client'\n\n# Optionally inject conditioner and transformer clients\nconditioner = Legion::Extensions::Conditioner::Client.new\ntransformer = Legion::Extensions::Transformer::Client.new\n\nclient = Legion::Extensions::Synapse::Client.new(\n  conditioner_client: conditioner,\n  transformer_client: transformer\n)\n\n# Create a synapse\nsynapse = client.create(\n  source_function_id: 1,\n  target_function_id: 2,\n  attention: '{\"all\":[{\"fact\":\"status\",\"operator\":\"equal\",\"value\":\"open\"}]}',\n  transform: '{\"template\":\"{\\\"message\\\":\\\"\u003c%= title %\u003e\\\"}\",\"engine\":\"erb\"}'\n)\n\n# Evaluate a signal through the synapse\nresult = client.evaluate(synapse_id: synapse.id, payload: { status: 'open', title: 'Bug fix' })\nresult[:success]     # =\u003e true\nresult[:mode]        # =\u003e :transform (based on confidence level)\nresult[:result]      # =\u003e { message: \"Bug fix\" }\n\n# Get synapse stats\nreport = client.report(synapse_id: synapse.id)\nreport[:confidence]  # =\u003e 0.72\nreport[:signals_24h] # =\u003e 1\nreport[:success_rate] # =\u003e 1.0\n```\n\n## Architecture\n\n### Three-Layer Model\n\n```\nLayer 1 (Bones)  — Explicit relationships defined by users (lex-tasker)\nLayer 2 (Nerves) — Synapses wrapping relationships with learning (lex-synapse)\nLayer 3 (Mind)   — GAIA cognitive coordination + Apollo shared knowledge\n```\n\n### Confidence Scoring\n\nEach synapse has a confidence score (0.0-1.0) that governs what it's allowed to do:\n\n| Range | Mode | Permitted Actions |\n|-------|------|-------------------|\n| 0.0-0.3 | OBSERVE | Log what it would do, pass through unchanged |\n| 0.3-0.6 | FILTER | Can suppress signals, cannot modify |\n| 0.6-0.8 | TRANSFORM | Can filter + transform within defined schemas |\n| 0.8-1.0 | AUTONOMOUS | Can self-modify rules, infer transforms, adjust routing |\n\n**Starting scores**: explicit=0.7, emergent=0.3, seeded=0.5\n\n**Adjustments**: success +0.02, failure -0.05, validation failure -0.03, 50+ consecutive successes +0.05 bonus\n\n**Decay**: Unused synapses fade at 0.998x per hour (~15% per day of inactivity)\n\n### Pain Signals\n\nDownstream task failures propagate backward through the chain:\n- Each failure reduces confidence by 0.05\n- 3+ consecutive failures trigger auto-revert to last known-good state\n- Extreme failure rates trigger dampening (homeostasis)\n\n### Homeostasis\n\n- **Spike detection**: Throughput \u003e3x baseline for 60+ seconds triggers dampening\n- **Drought detection**: Zero throughput for 10x average interval flags for review\n- **Baseline tracking**: Exponential moving average of signals/minute\n\n## Runners\n\n### Evaluate\n`evaluate(synapse_id:, payload:, conditioner_client:, transformer_client:)`\n\nMain signal flow: load synapse, check autonomy, run attention (conditioner), run transform (transformer), record signal, adjust confidence.\n\n### Pain\n`handle_pain(synapse_id:, task_id:)`\n\nDownstream failure handler. Records failed signal, adjusts confidence, checks for auto-revert threshold, may dampen synapse.\n\n### Crystallize\n`crystallize(signal_pairs:, threshold: 20)`\n\nBottom-up emergence. Given pairs of `{source_function_id, target_function_id, count}`, creates new synapses for pairs exceeding the threshold.\n\n### Mutate\n`mutate(synapse_id:, mutation_type:, changes:, trigger:)`\n\nVersioned self-modification. Records before/after state snapshots. Types: `attention_adjusted`, `transform_adjusted`, `route_changed`, `confidence_changed`. Triggers: `hebbian`, `pain`, `dream`, `gaia`, `manual`.\n\n### Revert\n`revert(synapse_id:, to_version:, trigger:)`\n\nRolls back to a previous mutation version, restoring the before_state.\n\n### Report\n`report(synapse_id:)`\n\nAggregates stats: confidence, status, 24h signal count, success rate, last mutation.\n\n### Dream\n`dream(synapse_id:, limit:)`\n\nReplays historical signals in simulation mode without affecting live state. Used by the dream cycle to test routing hypothesis changes.\n\n### Propose\n`propose(synapse_id:, ...)` / `proposals(synapse_id:, status:)` / `review_proposal(proposal_id:, status:)`\n\nGenerates proposed changes (reactive on signal evaluation, proactive on periodic analysis) for AUTONOMOUS-tier synapses. Proposals enter a status lifecycle: pending -\u003e approved/rejected/applied/expired/auto_accepted/auto_rejected.\n\n### Challenge\n`challenge_proposal(proposal_id:)` / `challenges(proposal_id:)` / `challenger_stats`\n\nRuns the adversarial challenge pipeline on pending proposals: conflict detection -\u003e impact scoring -\u003e LLM challenge (gated by impact score) -\u003e weighted aggregation -\u003e auto-accept/reject/await-review outcome.\n\n## Relationship Wrapper\n\nWrap existing Layer 1 relationships as synapses (opt-in, zero breaking changes):\n\n```ruby\nrelationship = { id: 42, trigger_function_id: 1, function_id: 2,\n                 conditions: '{\"all\":[...]}', transformation: '{\"template\":\"...\"}' }\nsynapse = Legion::Extensions::Synapse::Helpers::RelationshipWrapper.wrap(relationship)\n```\n\n## Transport\n\n- **Exchange**: `synapse` (inherits from `Legion::Transport::Exchanges::Task`)\n- **Queues**: `synapse.evaluate`, `synapse.pain`\n- **Routing keys**: `synapse.evaluate`, `task.failed`\n\n## Autonomous Observation Mode\n\nAUTONOMOUS-tier synapses (confidence \u003e= 0.8) generate proposals instead of directly executing changes. Proposals are reactive (triggered on signal evaluation) or proactive (generated periodically). The `lex-synapse.proposals.*` settings control enabled state, LLM engine options, and thresholds.\n\n## Adversarial Challenge Phase\n\nPending proposals are subjected to a multi-stage challenge pipeline: conflict detection among sibling proposals, impact scoring, optional LLM challenge (for high-impact proposals), weighted aggregation across verdicts, and auto-accept/reject based on configurable thresholds. The `lex-synapse.challenge.*` settings control gating.\n\n## Data Model\n\nFive tables: `synapses` (core routing definition + confidence + status), `synapse_mutations` (versioned change history), `synapse_signals` (per-signal outcome records), `synapse_proposals` (proposal lifecycle), `synapse_challenges` (per-challenge verdicts).\n\n## Dependencies\n\n- `lex-conditioner` \u003e= 0.3.0\n- `lex-transformer` \u003e= 0.3.0\n- Ruby \u003e= 3.4\n- [LegionIO](https://github.com/LegionIO/LegionIO) framework (for AMQP actor mode)\n- Standalone Client works without the framework (requires Sequel + database)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegionio%2Flex-synapse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flegionio%2Flex-synapse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flegionio%2Flex-synapse/lists"}