lore-kg 6.0.0__tar.gz

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 (118) hide show
  1. lore_kg-6.0.0/LICENSE +21 -0
  2. lore_kg-6.0.0/PKG-INFO +207 -0
  3. lore_kg-6.0.0/README.md +176 -0
  4. lore_kg-6.0.0/cli/adr.py +80 -0
  5. lore_kg-6.0.0/cli/agent_delta.py +866 -0
  6. lore_kg-6.0.0/cli/agent_history.py +40 -0
  7. lore_kg-6.0.0/cli/agent_retrieval.py +658 -0
  8. lore_kg-6.0.0/cli/agent_runner.py +958 -0
  9. lore_kg-6.0.0/cli/agent_stage.py +111 -0
  10. lore_kg-6.0.0/cli/agent_tools.py +189 -0
  11. lore_kg-6.0.0/cli/apply.py +194 -0
  12. lore_kg-6.0.0/cli/audit.py +31 -0
  13. lore_kg-6.0.0/cli/audit_runner.py +412 -0
  14. lore_kg-6.0.0/cli/batch.py +149 -0
  15. lore_kg-6.0.0/cli/benchmark.py +237 -0
  16. lore_kg-6.0.0/cli/brief_builder.py +552 -0
  17. lore_kg-6.0.0/cli/cache.py +255 -0
  18. lore_kg-6.0.0/cli/check_vuln.py +274 -0
  19. lore_kg-6.0.0/cli/cve.py +187 -0
  20. lore_kg-6.0.0/cli/cve_data.py +856 -0
  21. lore_kg-6.0.0/cli/cve_registry.py +10 -0
  22. lore_kg-6.0.0/cli/cve_runner.py +533 -0
  23. lore_kg-6.0.0/cli/diff_server.py +414 -0
  24. lore_kg-6.0.0/cli/feedback.py +32 -0
  25. lore_kg-6.0.0/cli/gh_check.py +717 -0
  26. lore_kg-6.0.0/cli/git_hook.py +84 -0
  27. lore_kg-6.0.0/cli/html_builders.py +348 -0
  28. lore_kg-6.0.0/cli/ingest_chat.py +31 -0
  29. lore_kg-6.0.0/cli/ingest_github.py +249 -0
  30. lore_kg-6.0.0/cli/ingest_slack.py +213 -0
  31. lore_kg-6.0.0/cli/init.py +88 -0
  32. lore_kg-6.0.0/cli/lsp.py +284 -0
  33. lore_kg-6.0.0/cli/mcp_server.py +465 -0
  34. lore_kg-6.0.0/cli/patch_validator.py +502 -0
  35. lore_kg-6.0.0/cli/prompts.py +223 -0
  36. lore_kg-6.0.0/cli/query.py +252 -0
  37. lore_kg-6.0.0/cli/reindex.py +65 -0
  38. lore_kg-6.0.0/cli/sandbox_evaluator.py +233 -0
  39. lore_kg-6.0.0/cli/shared.py +155 -0
  40. lore_kg-6.0.0/cli/templates/audit_ui.html +97 -0
  41. lore_kg-6.0.0/cli/templates/cve_ui.html +142 -0
  42. lore_kg-6.0.0/cli/templates/dashboard_ui.html +1344 -0
  43. lore_kg-6.0.0/cli/templates/diff_ui.html +144 -0
  44. lore_kg-6.0.0/cli/templates/impact_ui.html +297 -0
  45. lore_kg-6.0.0/cli/v11_retrieval.py +392 -0
  46. lore_kg-6.0.0/cli/vuln_analysis.py +233 -0
  47. lore_kg-6.0.0/cli/vuln_cache.py +38 -0
  48. lore_kg-6.0.0/cli/vuln_cure.py +102 -0
  49. lore_kg-6.0.0/cli/watch.py +27 -0
  50. lore_kg-6.0.0/cli/webhook_server.py +210 -0
  51. lore_kg-6.0.0/core/__init__.py +1 -0
  52. lore_kg-6.0.0/core/_batch_consolidator.py +273 -0
  53. lore_kg-6.0.0/core/_cold_start.py +230 -0
  54. lore_kg-6.0.0/core/_cold_start_intent.py +165 -0
  55. lore_kg-6.0.0/core/_dl_link_builders.py +337 -0
  56. lore_kg-6.0.0/core/_dl_mention_builder.py +167 -0
  57. lore_kg-6.0.0/core/_intent_miner.py +214 -0
  58. lore_kg-6.0.0/core/_macro_change.py +174 -0
  59. lore_kg-6.0.0/core/ast_extractor.py +208 -0
  60. lore_kg-6.0.0/core/ast_patcher.py +24 -0
  61. lore_kg-6.0.0/core/ast_patcher_core.py +95 -0
  62. lore_kg-6.0.0/core/ast_taint.py +372 -0
  63. lore_kg-6.0.0/core/ast_taint_helpers.py +185 -0
  64. lore_kg-6.0.0/core/base_tracer.py +15 -0
  65. lore_kg-6.0.0/core/boundary_miner.py +76 -0
  66. lore_kg-6.0.0/core/chat_miner.py +234 -0
  67. lore_kg-6.0.0/core/cst_patcher.py +465 -0
  68. lore_kg-6.0.0/core/decision_linker.py +240 -0
  69. lore_kg-6.0.0/core/git_historian.py +505 -0
  70. lore_kg-6.0.0/core/git_miner.py +942 -0
  71. lore_kg-6.0.0/core/guardian.py +168 -0
  72. lore_kg-6.0.0/core/invariant_miner.py +269 -0
  73. lore_kg-6.0.0/core/llm_client.py +562 -0
  74. lore_kg-6.0.0/core/qa_engine.py +164 -0
  75. lore_kg-6.0.0/core/reconciler.py +125 -0
  76. lore_kg-6.0.0/core/symbol_db.py +714 -0
  77. lore_kg-6.0.0/core/symbol_extractor.py +407 -0
  78. lore_kg-6.0.0/core/symbol_map.py +306 -0
  79. lore_kg-6.0.0/core/symbol_retriever.py +308 -0
  80. lore_kg-6.0.0/core/symbol_scanner.py +287 -0
  81. lore_kg-6.0.0/core/symbol_types.py +16 -0
  82. lore_kg-6.0.0/lore.py +133 -0
  83. lore_kg-6.0.0/lore_kg.egg-info/PKG-INFO +207 -0
  84. lore_kg-6.0.0/lore_kg.egg-info/SOURCES.txt +116 -0
  85. lore_kg-6.0.0/lore_kg.egg-info/dependency_links.txt +1 -0
  86. lore_kg-6.0.0/lore_kg.egg-info/entry_points.txt +2 -0
  87. lore_kg-6.0.0/lore_kg.egg-info/requires.txt +12 -0
  88. lore_kg-6.0.0/lore_kg.egg-info/top_level.txt +4 -0
  89. lore_kg-6.0.0/parsers/go_parser.py +451 -0
  90. lore_kg-6.0.0/parsers/go_taint_tracer.py +207 -0
  91. lore_kg-6.0.0/parsers/parse_result.py +86 -0
  92. lore_kg-6.0.0/parsers/ts_taint_tracer.py +215 -0
  93. lore_kg-6.0.0/parsers/typescript_parser.py +599 -0
  94. lore_kg-6.0.0/pyproject.toml +48 -0
  95. lore_kg-6.0.0/setup.cfg +4 -0
  96. lore_kg-6.0.0/tests/test_ast_patcher.py +106 -0
  97. lore_kg-6.0.0/tests/test_benchmark_taint.py +13 -0
  98. lore_kg-6.0.0/tests/test_boundary_miner.py +34 -0
  99. lore_kg-6.0.0/tests/test_brief_builder.py +308 -0
  100. lore_kg-6.0.0/tests/test_chat_miner.py +112 -0
  101. lore_kg-6.0.0/tests/test_cli_commands.py +136 -0
  102. lore_kg-6.0.0/tests/test_cross_file_taint.py +77 -0
  103. lore_kg-6.0.0/tests/test_cross_language.py +106 -0
  104. lore_kg-6.0.0/tests/test_fase4.py +269 -0
  105. lore_kg-6.0.0/tests/test_fase5a.py +339 -0
  106. lore_kg-6.0.0/tests/test_fase5b.py +106 -0
  107. lore_kg-6.0.0/tests/test_fase6.py +17 -0
  108. lore_kg-6.0.0/tests/test_ingestion_cli.py +118 -0
  109. lore_kg-6.0.0/tests/test_init.py +30 -0
  110. lore_kg-6.0.0/tests/test_invariant_miner.py +152 -0
  111. lore_kg-6.0.0/tests/test_llm_client.py +199 -0
  112. lore_kg-6.0.0/tests/test_lsp_handlers.py +43 -0
  113. lore_kg-6.0.0/tests/test_mcp.py +73 -0
  114. lore_kg-6.0.0/tests/test_precision_calibration.py +66 -0
  115. lore_kg-6.0.0/tests/test_reindex.py +29 -0
  116. lore_kg-6.0.0/tests/test_sprint3_ci_feedback.py +54 -0
  117. lore_kg-6.0.0/tests/test_symbol_map.py +237 -0
  118. lore_kg-6.0.0/tests/test_webhook_server.py +62 -0
lore_kg-6.0.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Filippo Gabriele
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
lore_kg-6.0.0/PKG-INFO ADDED
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: lore-kg
3
+ Version: 6.0.0
4
+ Summary: LORE: Local Institutional Memory & 5-Layer Knowledge Graph for Enterprise Codebases
5
+ License: MIT
6
+ Project-URL: Homepage, https://github.com/filippogabriele19/lore
7
+ Project-URL: Repository, https://github.com/filippogabriele19/lore
8
+ Project-URL: Issues, https://github.com/filippogabriele19/lore/issues
9
+ Keywords: knowledge-graph,architecture,ai-code-memory,mcp,static-analysis,code-governance
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Software Development :: Code Generators
14
+ Classifier: Topic :: Software Development :: Quality Assurance
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: anthropic>=0.7.0
19
+ Requires-Dist: fastapi>=0.100.0
20
+ Requires-Dist: libcst>=1.0.0
21
+ Requires-Dist: networkx>=3.0.0
22
+ Requires-Dist: pydantic>=2.0.0
23
+ Requires-Dist: rich>=13.0.0
24
+ Requires-Dist: sqlite-vec>=0.1.0
25
+ Requires-Dist: tree-sitter-languages>=1.8.0
26
+ Requires-Dist: typer>=0.12.0
27
+ Requires-Dist: uvicorn[standard]>=0.20.0
28
+ Requires-Dist: sentence-transformers>=2.2.0
29
+ Requires-Dist: mcp>=1.0.0
30
+ Dynamic: license-file
31
+
32
+ # 🚀 LORE: The Local Institutional Memory Layer for AI Coding Agents
33
+
34
+ **Stop AI from breaking your architecture. A 5-layer Knowledge Graph & Semantic Firewall for Cursor, Claude, and CI/CD.**
35
+
36
+ [![PyPI Version](https://img.shields.io/pypi/v/lore-kg.svg)](https://pypi.org/project/lore-kg/)
37
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
38
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
39
+ [![Model Context Protocol](https://img.shields.io/badge/MCP-Supported-green.svg)](https://modelcontextprotocol.io/)
40
+ [![Build Status](https://github.com/filippogabriele19/lore/actions/workflows/test-and-lint.yml/badge.svg)](https://github.com/filippogabriele19/lore/actions)
41
+
42
+ ---
43
+
44
+ ## 📊 Empirical Performance (Django & LangChain Benchmark)
45
+
46
+ LORE is backed by an empirical benchmark suite evaluated over **199 real commits** across the Django and LangChain repositories:
47
+
48
+ | Metric | Performance | Impact |
49
+ | :--- | :---: | :--- |
50
+ | **High-Signal Precision** | **97.2%** [95% CI: 85.8%–99.5%] | When LORE issues a critical alert, **97.2% of the time it is a true regression**. |
51
+ | **Clean PR False Positive Rate** | **1.0%** [95% CI: 0.2%–5.4%] | Near-zero alert fatigue on benign refactoring and documentation PRs. |
52
+ | **Overall False Positive Reduction** | **88.7% Noise Reduction** | Precision-calibrated thresholds eliminate alert fatigue in production pipelines. |
53
+ | **Symbol Co-Change Associations** | **816 Active Rules Mined** | Deep symbol-level association rules prevent missing coupled updates. |
54
+
55
+ ---
56
+
57
+ ## 💡 The Problem: AI Code Amnesia
58
+
59
+ AI coding assistants (Cursor, Claude Code, Copilot, Devin) are incredibly good at writing syntax (the *what*), but they are completely blind to architectural intent and history (the *why*):
60
+ - They refactor key endpoints without knowing the performance constraints or GDPR policies behind them.
61
+ - They replace custom authentication schemes with standard ones, breaking compliance rules.
62
+ - They lack context on implicit dependencies and files that always co-evolve (co-changes), leading to silent regressions.
63
+
64
+ **When senior architects leave or team size grows, this knowledge debt leads to architectural decay.**
65
+
66
+ ---
67
+
68
+ ## 🎯 The Solution: LORE
69
+
70
+ LORE reconstructs intent from your codebase evidence—mining git history, commit messages, PRs, Slack/GitHub webhooks, and Architectural Decision Records (ADRs) into a structured **5-layer Knowledge Graph**.
71
+
72
+ It serves as a **Semantic Firewall**, exposing this graph via **Model Context Protocol (MCP)**, **SARIF 2.1.0**, and a **GitHub Action** to guide AI agents and developers *before* they apply breaking changes.
73
+
74
+ ```mermaid
75
+ graph TD
76
+ subgraph Evidence Sources
77
+ A1[Codebase & Git History]
78
+ A2["GitHub PRs & Issues (Webhooks & CLI)"]
79
+ A3["Slack Channel Chat logs (Webhooks & CLI)"]
80
+ end
81
+
82
+ A1 & A2 & A3 -->|Ingestion & Mining| B[LORE Engine]
83
+ B -->|Builds| C[5-Layer Knowledge Graph]
84
+
85
+ subgraph Knowledge Graph Layers
86
+ C1[L1: Structural AST Symbols (Py, Go, TS)]
87
+ C2[L2: Semantic Vector Store sqlite-vec]
88
+ C3[L3: Historical Co-changes & Fragility Scores]
89
+ C4[L4: Decisional Links to ADRs & PRs]
90
+ C5[L5: Institutional Policy & Boundary Rules]
91
+ end
92
+
93
+ C --> C1 & C2 & C3 & C4 & C5
94
+ C -->|Exposes Context| D[Model Context Protocol Server]
95
+ C -->|Validates Diff| E[LORE Guardian & SARIF Output]
96
+
97
+ D -->|Guide Agent| F[Cursor / Claude Desktop / Claude Code]
98
+ E -->|Block Breaking PR| G[Pull Request Gatekeeper]
99
+ ```
100
+
101
+ ---
102
+
103
+ ## ⚡ Quick Start: Experience LORE in 60 Seconds
104
+
105
+ ### 1. Install LORE
106
+ ```bash
107
+ pip install lore-kg
108
+ ```
109
+
110
+ ### 2. Initialize Workspace & Index Codebase
111
+ Set your LLM API key (e.g. Anthropic, OpenAI, DeepSeek, or OpenRouter):
112
+ ```bash
113
+ export ANTHROPIC_API_KEY="your-api-key"
114
+ ```
115
+
116
+ Then, run the bootstrap helper inside your repository to scan files and build your Knowledge Graph:
117
+ ```bash
118
+ lore init .
119
+ ```
120
+
121
+ ### 3. Run Architectural Audit in CI/CD or PRs
122
+ Audit local modifications or PR commit ranges:
123
+ ```bash
124
+ lore gh-check --commit-range "origin/main...HEAD" --format sarif --fail-on critical
125
+ ```
126
+
127
+ ### 4. Query the Knowledge Graph
128
+ Ask questions about why the codebase is structured the way it is:
129
+ ```bash
130
+ lore query "Why did we replace JWT with opaque tokens in auth.py?"
131
+ ```
132
+
133
+ ---
134
+
135
+ ## ⚖️ What Makes LORE Different?
136
+
137
+ | Feature | Standard RAG / Code Search | AI IDE / Assistants | LORE |
138
+ | :--- | :---: | :---: | :---: |
139
+ | **AST Symbol Resolution** | ❌ (reads text chunks) | ❌ (raw file contents) | **✅ L1-L2 AST Graph (Py, Go, TS)** |
140
+ | **Understand *Why* (ADRs)** | ❌ | ❌ | **✅ L4 Scoped Decisional Links** |
141
+ | **Symbol Co-Change Rules** | ❌ | ❌ | **✅ 800+ Mined Association Rules** |
142
+ | **Boundary Condition Miner** | ❌ | ❌ | **✅ Operator Weakening Alerts (`>` $\rightarrow$ `>=`)** |
143
+ | **Inter-Procedural Taint Graph**| ❌ | ❌ | **✅ Source-to-Sink Dataflow Tracing** |
144
+ | **AI Compliance Gate** | ❌ | ❌ | **✅ Pre-commit / SARIF CI/CD Gate** |
145
+ | **Offline Vector Search** | ❌ (cloud dependency) | ❌ | **✅ Local via `sqlite-vec` (C)** |
146
+
147
+ ---
148
+
149
+ ## 🛠️ CLI Command Overview
150
+
151
+ | Command | Description |
152
+ | :--- | :--- |
153
+ | `lore init` | Initialize LORE workspace and index project files (bootstrap). |
154
+ | `lore gh-check` | Run PR security & architecture audit with `--format [markdown\|json\|sarif]` and `--fail-on`. |
155
+ | `lore reindex` | Re-compute symbol fragility scores & co-changes across existing Knowledge Graphs. |
156
+ | `lore dismiss` | Suppress a false positive LORE warning for a file or symbol persistent in SQLite. |
157
+ | `lore query` | Query the Knowledge Graph for architectural questions (read-only). |
158
+ | `lore adr` | Generate and index an Architectural Decision Record (ADR) to cure Amnesia. |
159
+ | `lore mcp` | Start the Model Context Protocol (MCP) server for Cursor & Claude Desktop. |
160
+ | `lore git-hook` | Install or uninstall LORE pre-commit git hooks. |
161
+
162
+ ---
163
+
164
+ ## 🛡️ GitHub Action & SARIF Integration
165
+
166
+ Integrate LORE Guardian into your GitHub Code Scanning and Security tab via native SARIF 2.1.0 output:
167
+
168
+ ```yaml
169
+ # .github/workflows/lore-audit.yml
170
+ name: LORE Security & Architecture Guard
171
+
172
+ on:
173
+ pull_request:
174
+ branches: [ main ]
175
+
176
+ jobs:
177
+ lore-guard:
178
+ runs-on: ubuntu-latest
179
+ steps:
180
+ - uses: actions/checkout@v4
181
+ with:
182
+ fetch-depth: 0 # Fetch all history for git mining
183
+
184
+ - name: Set up Python
185
+ uses: actions/setup-python@v5
186
+ with:
187
+ python-version: '3.10'
188
+
189
+ - name: Install LORE
190
+ run: pip install lore-kg
191
+
192
+ - name: Run LORE Audit
193
+ run: lore gh-check --commit-range "origin/main...HEAD" --format sarif --fail-on critical > lore-results.sarif
194
+
195
+ - name: Upload SARIF report to GitHub Security Tab
196
+ uses: github/codeql-action/upload-sarif@v3
197
+ with:
198
+ sarif_file: lore-results.sarif
199
+ ```
200
+
201
+ ---
202
+
203
+ ## 📜 Contributing & License
204
+
205
+ For development setup instructions, please read [CONTRIBUTING.md](CONTRIBUTING.md).
206
+
207
+ LORE is open-source software licensed under the [MIT License](LICENSE).
@@ -0,0 +1,176 @@
1
+ # 🚀 LORE: The Local Institutional Memory Layer for AI Coding Agents
2
+
3
+ **Stop AI from breaking your architecture. A 5-layer Knowledge Graph & Semantic Firewall for Cursor, Claude, and CI/CD.**
4
+
5
+ [![PyPI Version](https://img.shields.io/pypi/v/lore-kg.svg)](https://pypi.org/project/lore-kg/)
6
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
8
+ [![Model Context Protocol](https://img.shields.io/badge/MCP-Supported-green.svg)](https://modelcontextprotocol.io/)
9
+ [![Build Status](https://github.com/filippogabriele19/lore/actions/workflows/test-and-lint.yml/badge.svg)](https://github.com/filippogabriele19/lore/actions)
10
+
11
+ ---
12
+
13
+ ## 📊 Empirical Performance (Django & LangChain Benchmark)
14
+
15
+ LORE is backed by an empirical benchmark suite evaluated over **199 real commits** across the Django and LangChain repositories:
16
+
17
+ | Metric | Performance | Impact |
18
+ | :--- | :---: | :--- |
19
+ | **High-Signal Precision** | **97.2%** [95% CI: 85.8%–99.5%] | When LORE issues a critical alert, **97.2% of the time it is a true regression**. |
20
+ | **Clean PR False Positive Rate** | **1.0%** [95% CI: 0.2%–5.4%] | Near-zero alert fatigue on benign refactoring and documentation PRs. |
21
+ | **Overall False Positive Reduction** | **88.7% Noise Reduction** | Precision-calibrated thresholds eliminate alert fatigue in production pipelines. |
22
+ | **Symbol Co-Change Associations** | **816 Active Rules Mined** | Deep symbol-level association rules prevent missing coupled updates. |
23
+
24
+ ---
25
+
26
+ ## 💡 The Problem: AI Code Amnesia
27
+
28
+ AI coding assistants (Cursor, Claude Code, Copilot, Devin) are incredibly good at writing syntax (the *what*), but they are completely blind to architectural intent and history (the *why*):
29
+ - They refactor key endpoints without knowing the performance constraints or GDPR policies behind them.
30
+ - They replace custom authentication schemes with standard ones, breaking compliance rules.
31
+ - They lack context on implicit dependencies and files that always co-evolve (co-changes), leading to silent regressions.
32
+
33
+ **When senior architects leave or team size grows, this knowledge debt leads to architectural decay.**
34
+
35
+ ---
36
+
37
+ ## 🎯 The Solution: LORE
38
+
39
+ LORE reconstructs intent from your codebase evidence—mining git history, commit messages, PRs, Slack/GitHub webhooks, and Architectural Decision Records (ADRs) into a structured **5-layer Knowledge Graph**.
40
+
41
+ It serves as a **Semantic Firewall**, exposing this graph via **Model Context Protocol (MCP)**, **SARIF 2.1.0**, and a **GitHub Action** to guide AI agents and developers *before* they apply breaking changes.
42
+
43
+ ```mermaid
44
+ graph TD
45
+ subgraph Evidence Sources
46
+ A1[Codebase & Git History]
47
+ A2["GitHub PRs & Issues (Webhooks & CLI)"]
48
+ A3["Slack Channel Chat logs (Webhooks & CLI)"]
49
+ end
50
+
51
+ A1 & A2 & A3 -->|Ingestion & Mining| B[LORE Engine]
52
+ B -->|Builds| C[5-Layer Knowledge Graph]
53
+
54
+ subgraph Knowledge Graph Layers
55
+ C1[L1: Structural AST Symbols (Py, Go, TS)]
56
+ C2[L2: Semantic Vector Store sqlite-vec]
57
+ C3[L3: Historical Co-changes & Fragility Scores]
58
+ C4[L4: Decisional Links to ADRs & PRs]
59
+ C5[L5: Institutional Policy & Boundary Rules]
60
+ end
61
+
62
+ C --> C1 & C2 & C3 & C4 & C5
63
+ C -->|Exposes Context| D[Model Context Protocol Server]
64
+ C -->|Validates Diff| E[LORE Guardian & SARIF Output]
65
+
66
+ D -->|Guide Agent| F[Cursor / Claude Desktop / Claude Code]
67
+ E -->|Block Breaking PR| G[Pull Request Gatekeeper]
68
+ ```
69
+
70
+ ---
71
+
72
+ ## ⚡ Quick Start: Experience LORE in 60 Seconds
73
+
74
+ ### 1. Install LORE
75
+ ```bash
76
+ pip install lore-kg
77
+ ```
78
+
79
+ ### 2. Initialize Workspace & Index Codebase
80
+ Set your LLM API key (e.g. Anthropic, OpenAI, DeepSeek, or OpenRouter):
81
+ ```bash
82
+ export ANTHROPIC_API_KEY="your-api-key"
83
+ ```
84
+
85
+ Then, run the bootstrap helper inside your repository to scan files and build your Knowledge Graph:
86
+ ```bash
87
+ lore init .
88
+ ```
89
+
90
+ ### 3. Run Architectural Audit in CI/CD or PRs
91
+ Audit local modifications or PR commit ranges:
92
+ ```bash
93
+ lore gh-check --commit-range "origin/main...HEAD" --format sarif --fail-on critical
94
+ ```
95
+
96
+ ### 4. Query the Knowledge Graph
97
+ Ask questions about why the codebase is structured the way it is:
98
+ ```bash
99
+ lore query "Why did we replace JWT with opaque tokens in auth.py?"
100
+ ```
101
+
102
+ ---
103
+
104
+ ## ⚖️ What Makes LORE Different?
105
+
106
+ | Feature | Standard RAG / Code Search | AI IDE / Assistants | LORE |
107
+ | :--- | :---: | :---: | :---: |
108
+ | **AST Symbol Resolution** | ❌ (reads text chunks) | ❌ (raw file contents) | **✅ L1-L2 AST Graph (Py, Go, TS)** |
109
+ | **Understand *Why* (ADRs)** | ❌ | ❌ | **✅ L4 Scoped Decisional Links** |
110
+ | **Symbol Co-Change Rules** | ❌ | ❌ | **✅ 800+ Mined Association Rules** |
111
+ | **Boundary Condition Miner** | ❌ | ❌ | **✅ Operator Weakening Alerts (`>` $\rightarrow$ `>=`)** |
112
+ | **Inter-Procedural Taint Graph**| ❌ | ❌ | **✅ Source-to-Sink Dataflow Tracing** |
113
+ | **AI Compliance Gate** | ❌ | ❌ | **✅ Pre-commit / SARIF CI/CD Gate** |
114
+ | **Offline Vector Search** | ❌ (cloud dependency) | ❌ | **✅ Local via `sqlite-vec` (C)** |
115
+
116
+ ---
117
+
118
+ ## 🛠️ CLI Command Overview
119
+
120
+ | Command | Description |
121
+ | :--- | :--- |
122
+ | `lore init` | Initialize LORE workspace and index project files (bootstrap). |
123
+ | `lore gh-check` | Run PR security & architecture audit with `--format [markdown\|json\|sarif]` and `--fail-on`. |
124
+ | `lore reindex` | Re-compute symbol fragility scores & co-changes across existing Knowledge Graphs. |
125
+ | `lore dismiss` | Suppress a false positive LORE warning for a file or symbol persistent in SQLite. |
126
+ | `lore query` | Query the Knowledge Graph for architectural questions (read-only). |
127
+ | `lore adr` | Generate and index an Architectural Decision Record (ADR) to cure Amnesia. |
128
+ | `lore mcp` | Start the Model Context Protocol (MCP) server for Cursor & Claude Desktop. |
129
+ | `lore git-hook` | Install or uninstall LORE pre-commit git hooks. |
130
+
131
+ ---
132
+
133
+ ## 🛡️ GitHub Action & SARIF Integration
134
+
135
+ Integrate LORE Guardian into your GitHub Code Scanning and Security tab via native SARIF 2.1.0 output:
136
+
137
+ ```yaml
138
+ # .github/workflows/lore-audit.yml
139
+ name: LORE Security & Architecture Guard
140
+
141
+ on:
142
+ pull_request:
143
+ branches: [ main ]
144
+
145
+ jobs:
146
+ lore-guard:
147
+ runs-on: ubuntu-latest
148
+ steps:
149
+ - uses: actions/checkout@v4
150
+ with:
151
+ fetch-depth: 0 # Fetch all history for git mining
152
+
153
+ - name: Set up Python
154
+ uses: actions/setup-python@v5
155
+ with:
156
+ python-version: '3.10'
157
+
158
+ - name: Install LORE
159
+ run: pip install lore-kg
160
+
161
+ - name: Run LORE Audit
162
+ run: lore gh-check --commit-range "origin/main...HEAD" --format sarif --fail-on critical > lore-results.sarif
163
+
164
+ - name: Upload SARIF report to GitHub Security Tab
165
+ uses: github/codeql-action/upload-sarif@v3
166
+ with:
167
+ sarif_file: lore-results.sarif
168
+ ```
169
+
170
+ ---
171
+
172
+ ## 📜 Contributing & License
173
+
174
+ For development setup instructions, please read [CONTRIBUTING.md](CONTRIBUTING.md).
175
+
176
+ LORE is open-source software licensed under the [MIT License](LICENSE).
@@ -0,0 +1,80 @@
1
+ import os, sys, argparse, json
2
+ from pathlib import Path
3
+ from cli.shared import console, DEFAULT_PROJECT, _get_db_path
4
+
5
+ def _main_adr(argv: list[str]) -> None:
6
+ """adr mode — generate a draft ADR to cure institutional amnesia and index it in the KG."""
7
+ import argparse
8
+ parser = argparse.ArgumentParser(
9
+ prog="lore adr",
10
+ description="Generate and index an Architectural Decision Record (ADR) to cure Amnesia",
11
+ )
12
+ parser.add_argument("--project", default=DEFAULT_PROJECT,
13
+ help=f"Path to project root (default: {DEFAULT_PROJECT})")
14
+ parser.add_argument("--file", required=True,
15
+ help="Relative file path associated with the decision")
16
+ parser.add_argument("--title", required=True,
17
+ help="Short title/description of the architectural invariant")
18
+ parser.add_argument("--symbol", default=None,
19
+ help="Optional symbol name (class/function) to bind the decision to")
20
+ args = parser.parse_args(argv)
21
+
22
+ project_root = Path(args.project)
23
+ if not project_root.exists():
24
+ console.print(f"[error]Project path not found: {project_root}[/]")
25
+ sys.exit(1)
26
+
27
+ db_path = _get_db_path(project_root)
28
+ if not db_path.exists():
29
+ console.print(f"[error]✖ Database not found under {project_root}[/]")
30
+ sys.exit(1)
31
+
32
+ # 1. Write the markdown ADR file
33
+ adr_dir = project_root / ".lore" / "adr"
34
+ adr_dir.mkdir(parents=True, exist_ok=True)
35
+
36
+ # Generate unique ID/filename
37
+ from datetime import datetime as _dt
38
+ import random
39
+ ts = _dt.now().strftime("%Y%m%d_%H%M%S")
40
+ rand_id = random.randint(1000, 9999)
41
+ adr_filename = f"adr_{ts}_{rand_id}.md"
42
+ adr_path = adr_dir / adr_filename
43
+
44
+ adr_content = f"""# ADR: {args.title}
45
+
46
+ ## Metadata
47
+ - **Date**: {_dt.now().strftime("%Y-%m-%d")}
48
+ - **Target File**: {args.file}
49
+ - **Target Symbol**: {args.symbol or "File-level Invariant"}
50
+ - **Status**: Accepted
51
+
52
+ ## Context
53
+ Describe the context and the problem we are solving, including any security requirements or invariants (e.g. inputs must be validated, credentials must come from environment).
54
+
55
+ ## Decision
56
+ Describe the decision and the design rules. What must developers do or avoid doing in this subsystem?
57
+
58
+ ## Consequences
59
+ What are the consequences of this decision? What are the tradeoffs?
60
+ """
61
+ adr_path.write_text(adr_content, encoding="utf-8")
62
+ console.print(f"[success]✔ ADR file generated successfully:[/] [underline info]{adr_path}[/]")
63
+
64
+ # 2. Register it in decision_links table in the database
65
+ from core.symbol_db import SymbolDB
66
+ db = SymbolDB(db_path)
67
+
68
+ try:
69
+ # Try to find symbol ID if symbol is specified
70
+ symbol_name = args.symbol if args.symbol else args.file.replace("\\", "/").split("/")[-1]
71
+
72
+ db.register_decision_link(symbol_name, "adr", f".lore/adr/{adr_filename}", 1.0, args.title)
73
+ db.commit()
74
+ finally:
75
+ db.close()
76
+
77
+
78
+ console.print(f"[success]✔ Decision Link registered in the Knowledge Graph for symbol [bold cyan]{symbol_name}[/]. Amnesia cured![/]\n")
79
+
80
+