@nxuss/lemma 0.6.1 → 0.7.1

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.
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
- # 🧠 Lemma v0.6.1
1
+ # 🧠 Lemma v0.7.0
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/@nxuss/lemma.svg?color=orange&style=flat-square)](https://www.npmjs.com/package/@nxuss/lemma)
4
4
  [![License](https://img.shields.io/npm/l/@nxuss/lemma.svg?color=blue&style=flat-square)](https://github.com/Nxusbets/lemma/blob/main/LICENSE)
5
- [![Build Status](https://img.shields.io/badge/tests-101%20passed-brightgreen.svg?style=flat-square)]()
6
- [![Security](https://img.shields.io/badge/privacy-firewall%20active-blueviolet?style=flat-square)]()
7
- [![Caching](https://img.shields.io/badge/semantic%20memory-enabled-success?style=flat-square)]()
5
+ [![Build Status](https://img.shields.io/badge/tests-101%20passed-brightgreen.svg?style=flat-square)](https://github.com/Nxusbets/lemma)
6
+ [![Security](https://img.shields.io/badge/privacy-firewall%20active-blueviolet?style=flat-square)](https://github.com/Nxusbets/lemma)
7
+ [![Caching](https://img.shields.io/badge/semantic%20memory-enabled-success?style=flat-square)](https://github.com/Nxusbets/lemma)
8
+ [![MCP Tools](https://img.shields.io/badge/MCP%20tools-13-ff69b4?style=flat-square)](https://github.com/Nxusbets/lemma)
8
9
 
9
10
  ```text
10
11
  __
@@ -132,13 +133,13 @@ Create or edit `lemma.config.json` in your project root to disable or fine-tune
132
133
  {
133
134
  "system": {
134
135
  "autoConfigure": {
135
- "disabled": false, // Set to true to disable all automated IDE/shell overrides
136
- "editor": true, // Set to false to prevent Cursor/Windsurf setting updates
137
- "shell": true, // Set to false to prevent .zshrc/.bashrc overrides
138
- "claude": true // Set to false to prevent Claude Desktop MCP updates
136
+ "disabled": false,
137
+ "editor": true,
138
+ "shell": true,
139
+ "claude": true
139
140
  },
140
141
  "clipboardWatcher": {
141
- "disabled": false // Set to true to prevent clipboard watching
142
+ "disabled": false
142
143
  }
143
144
  }
144
145
  }
@@ -146,6 +147,58 @@ Create or edit `lemma.config.json` in your project root to disable or fine-tune
146
147
 
147
148
  ---
148
149
 
150
+ ## 🛠️ MCP Tools Reference (v0.7.0 — 13 Tools)
151
+
152
+ When connected via `lemma mcp`, your Chat IDE gains access to **13 native tools** covering workspace navigation, code safety, semantic memory, and AI cost optimization.
153
+
154
+ ### 🗂️ Workspace Tools
155
+
156
+ | Tool | Description |
157
+ | :--- | :--- |
158
+ | `read_workspace_file` | Read a file with automatic token compression (up to 80% savings) and privacy scrubbing. |
159
+ | `write_workspace_file` | Write content to a file, creating directories as needed. |
160
+ | `apply_workspace_patch` | Smart search-and-replace patch — safe against duplicate matches. |
161
+ | `list_workspace_dir` | Recursively list the project structure up to a configurable depth. |
162
+ | `search_workspace` | Fast text search (grep) across all project files with optional extension filter. |
163
+ | `run_workspace_command` | Execute bash commands (tests, linters, git) in the workspace root. Returns stdout/stderr. |
164
+
165
+ ### 🔬 Code Intelligence Tools ✨ NEW in v0.7.0
166
+
167
+ | Tool | Description |
168
+ | :--- | :--- |
169
+ | `get_ast_hologram` | **Holographic AST Map.** Scans the workspace and returns a dense JSON index of all exported symbols (classes, functions, interfaces, types, consts) with their file paths and line numbers. Use this **instead of reading individual files** — saves up to 90% tokens when navigating large codebases. |
170
+ | `validate_patch_sandbox` | **AST Multiverse Auto-Debugger.** Validates a proposed patch in an isolated sandbox (`/tmp`) **before** applying it to the workspace. Runs `tsc --noEmit` and bracket-balance checks. Returns a clear `✅ SAFE TO APPLY` or `❌ DO NOT APPLY` verdict with full diagnostics. |
171
+
172
+ ### 🧠 Brain & Memory Tools ✨ NEW in v0.7.0
173
+
174
+ | Tool | Description |
175
+ | :--- | :--- |
176
+ | `search_memory` | Semantic search across The Brain — retrieves past solutions and context from all your projects. |
177
+ | `store_memory` | Explicitly save a key technical decision, code snippet, or architecture note into The Brain for future sessions. |
178
+ | `query_hybrid_consensus` | **Hybrid Consensus Engine.** Checks The Brain for a cached answer at a configurable similarity threshold (default 80%). Brain **HIT** → instant response, zero cloud tokens spent. Brain **MISS** → instructs the IDE to proceed with cloud and auto-stores the result afterward. |
179
+ | `get_telepathic_hints` | **Proactive Telepathy.** Given the path of the file being edited, automatically surfaces the top N most relevant memories and past solutions from The Brain — no explicit query needed. Front-loads context before you write a single line. |
180
+
181
+ ### ⚙️ Optimization & Privacy Tools
182
+
183
+ | Tool | Description |
184
+ | :--- | :--- |
185
+ | `scrub_privacy` | Mask PII, API keys, and secrets from any text block using the Privacy Firewall. |
186
+ | `squeeze_prompt` | Compress code blocks and boilerplate in any prompt — up to 80% token reduction. |
187
+ | `get_routing_advice` | Analyze a prompt and get the optimal model recommendation from the Complexity Router. |
188
+ | `auto_heal` | Diagnose and auto-heal the latest local server crash from Lemma's live context logs. |
189
+ | `get_project_onboarding` | Download a one-shot architectural mental model of the current project codebase. |
190
+
191
+ ### 📡 MCP Resources
192
+
193
+ | Resource URI | Description |
194
+ | :--- | :--- |
195
+ | `lemma://runtime/context` | Live application errors, stack traces, and runtime state. Subscribable — your IDE gets notified the instant a crash happens. |
196
+ | `lemma://stats/usage` | Current token savings, cost report, and cache hit metrics in JSON. |
197
+ | `lemma://project/onboarding` | Dynamic project architecture guide compiled on demand. |
198
+ | `lemma://multiverse/timeline` | Chronological AST diff timeline of the last 10 code micro-snapshots. |
199
+
200
+ ---
201
+
149
202
  ## 💎 Tier Comparison
150
203
 
151
204
  | Feature | 🆓 Free (Standard) | 💎 Pro ($12/mo) |
@@ -157,6 +210,10 @@ Create or edit `lemma.config.json` in your project root to disable or fine-tune
157
210
  | **AST Time-Travel Telemetry** | ❌ None | **Codebase Multiverse (Cap 10 AST Snapshots) 💎** |
158
211
  | **Kiro/Cursor Composer Bypass** | ❌ None | **Smart Patches & Sandbox Terminal MCP 💎** |
159
212
  | **Zero-Shot Onboarding Guide** | ❌ None | **Codebase Architecture Map MCP 💎** |
213
+ | **AST Hologram** | ❌ None | **Symbol Map — 90% token savings 💎** |
214
+ | **Sandbox Patch Validator** | ❌ None | **Pre-flight code safety checks 💎** |
215
+ | **Hybrid Consensus Engine** | ❌ None | **Brain-first query routing 💎** |
216
+ | **Proactive Telepathy** | ❌ None | **Auto-surfaced context hints 💎** |
160
217
  | **Telemetry Dashboard** | Basic Stats | **Time-Travel Debugger & 60fps Graph** |
161
218
  | **Limits** | 300 requests/mo | **Unlimited Agentic Power** |
162
219
 
@@ -174,16 +231,16 @@ You don't need to change your habits. Just point your tool's "Base URL" to Lemma
174
231
  * **Custom Apps:** Replace `https://api.openai.com/v1` with `http://localhost:8081/v1` in your SDK initialization.
175
232
 
176
233
  ### 💎 Pro Integration (Model Context Protocol - MCP)
177
- For **Lemma Pro** users, you can expose Lemma's entire intelligence layer (Privacy Firewall, Semantic Brain Search, and Auto-Heal, plus the new Composer Bypass Suite, AST Timeline, and Zero-Shot Onboarding Map) directly as native tools using the **Model Context Protocol (MCP)**. This lets the LLM read, search, write, patch, and compile files in your workspace autonomously.
234
+ For **Lemma Pro** users, expose Lemma's entire intelligence layer Privacy Firewall, Semantic Brain, AST Hologram, Sandbox Validator, Hybrid Consensus, and Proactive Telepathy directly as native tools using the **Model Context Protocol (MCP)**. This lets the LLM read, search, write, patch, validate, and compile files autonomously.
178
235
 
179
- #### 🟢 Cursor:
236
+ #### 🟢 Cursor / Antigravity / Windsurf:
180
237
  1. Go to **Settings > Features > MCP**.
181
238
  2. Click **+ Add New MCP Server**.
182
239
  3. Configure the server:
183
240
  * **Name**: `Lemma`
184
241
  * **Type**: `command`
185
242
  * **Command**: `lemma mcp`
186
- 4. Click **Save**. A green **"Connected"** dot will appear, confirming that the IDE has loaded all of Lemma's tools.
243
+ 4. Click **Save**. A green **"Connected"** dot will appear, confirming that the IDE has loaded all 13 of Lemma's tools.
187
244
 
188
245
  #### 🟢 Claude Desktop:
189
246
  Add the following to your `claude_desktop_config.json` configuration file:
@@ -202,7 +259,8 @@ Add the following to your `claude_desktop_config.json` configuration file:
202
259
  1. **Privacy:** Your IDE won't leak your secrets to the cloud.
203
260
  2. **Context:** Lemma syncs your runtime crashes directly to your chat window.
204
261
  3. **Speed:** Instant responses for similar questions via Semantic Cache.
205
- 4. **Observability:** Gorgeous dashboard showing you exactly how much cash and tokens you are saving.
262
+ 4. **Intelligence:** AST Hologram + Hybrid Consensus = dramatically fewer tokens spent per session.
263
+ 5. **Observability:** Gorgeous dashboard showing you exactly how much cash and tokens you are saving.
206
264
 
207
265
  ---
208
266
 
@@ -1 +1 @@
1
- {"version":3,"file":"lemma-proxy.d.ts","sourceRoot":"","sources":["../../../src/cli/lemma-proxy.ts"],"names":[],"mappings":";AA8NA,wBAAgB,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAkMnJ;AAED,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CA4DvF;AAm2DD,wBAAsB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA6KhL"}
1
+ {"version":3,"file":"lemma-proxy.d.ts","sourceRoot":"","sources":["../../../src/cli/lemma-proxy.ts"],"names":[],"mappings":";AAwOA,wBAAgB,gBAAgB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CAkMnJ;AAED,wBAAgB,+BAA+B,CAAC,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,IAAI,CA4DvF;AA03DD,wBAAsB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CA6KhL"}
@@ -104,6 +104,15 @@ async function writeJson(file, data) {
104
104
  function projectHash(name) {
105
105
  return crypto_1.default.createHash('sha1').update(name).digest('hex').slice(0, 12);
106
106
  }
107
+ function getCollectionName(projectName) {
108
+ let cleanName = projectName.replace(/[^a-zA-Z0-9._-]/g, '_');
109
+ cleanName = cleanName.replace(/^[^a-zA-Z0-9]+/, '');
110
+ cleanName = cleanName.replace(/[^a-zA-Z0-9]+$/, '');
111
+ if (cleanName.length < 3) {
112
+ cleanName = 'lemma_proj_' + cleanName;
113
+ }
114
+ return `lemma-cache-${cleanName}`;
115
+ }
107
116
  function detectProject() {
108
117
  const pkgPath = path_1.default.join(process.cwd(), 'package.json');
109
118
  if (fs_1.default.existsSync(pkgPath)) {
@@ -617,7 +626,7 @@ async function semanticGet(provider, prompt, projectName = 'global') {
617
626
  let localHit = null;
618
627
  try {
619
628
  const collection = await chroma.getOrCreateCollection({
620
- name: `lemma-cache-${projectName}`,
629
+ name: getCollectionName(projectName),
621
630
  embeddingFunction: dummyEmbeddingFunction,
622
631
  metadata: { "hnsw:space": "cosine" }
623
632
  });
@@ -656,7 +665,7 @@ async function semanticGet(provider, prompt, projectName = 'global') {
656
665
  // ─── Cross-Project Bug Telepathy Fallback ───
657
666
  try {
658
667
  const collections = await chroma.listCollections();
659
- const projectCollections = collections.filter((c) => c.name.startsWith('lemma-cache-') && c.name !== `lemma-cache-${projectName}`);
668
+ const projectCollections = collections.filter((c) => c.name.startsWith('lemma-cache-') && c.name !== getCollectionName(projectName));
660
669
  for (const colInfo of projectCollections) {
661
670
  try {
662
671
  const col = await chroma.getOrCreateCollection({
@@ -709,7 +718,7 @@ async function semanticSet(provider, prompt, data, projectName = 'global') {
709
718
  return;
710
719
  try {
711
720
  const collection = await chroma.getOrCreateCollection({
712
- name: `lemma-cache-${projectName}`,
721
+ name: getCollectionName(projectName),
713
722
  embeddingFunction: dummyEmbeddingFunction,
714
723
  metadata: { "hnsw:space": "cosine" }
715
724
  });
@@ -1100,7 +1109,7 @@ class LemmaServer {
1100
1109
  // Try to query ChromaDB for semantic cache count
1101
1110
  try {
1102
1111
  const collection = await chroma.getOrCreateCollection({
1103
- name: `lemma-cache-${this.projectName}`,
1112
+ name: getCollectionName(this.projectName),
1104
1113
  embeddingFunction: dummyEmbeddingFunction,
1105
1114
  metadata: { "hnsw:space": "cosine" }
1106
1115
  });
@@ -1156,28 +1165,46 @@ class LemmaServer {
1156
1165
  const emb = await getEmbedding(query);
1157
1166
  if (!emb)
1158
1167
  throw new Error('Failed to generate embedding');
1159
- const collection = await chroma.getOrCreateCollection({
1160
- name: `lemma-cache-${this.projectName}`,
1161
- embeddingFunction: dummyEmbeddingFunction,
1162
- metadata: { "hnsw:space": "cosine" }
1163
- });
1164
- const results = await collection.query({
1165
- queryEmbeddings: [emb],
1166
- nResults: 10
1167
- });
1168
- const formatted = (results.ids[0] || []).map((id, i) => {
1169
- const meta = results.metadatas[0][i];
1170
- const dists = results.distances;
1171
- const dist = (dists && dists[0] && dists[0][i] !== null && dists[0][i] !== undefined) ? dists[0][i] : 1.0;
1172
- return {
1173
- id,
1174
- prompt: meta.prompt,
1175
- response: JSON.parse(meta.response),
1176
- timestamp: meta.timestamp,
1177
- similarity: 1 - dist
1178
- };
1179
- });
1180
- res.json({ results: formatted });
1168
+ let allResults = [];
1169
+ // 1. Query all collections starting with 'lemma-cache' for cross-project search
1170
+ const collections = await chroma.listCollections();
1171
+ const targetCollections = collections.filter((c) => c.name.startsWith('lemma-cache'));
1172
+ for (const colInfo of targetCollections) {
1173
+ try {
1174
+ const collection = await chroma.getOrCreateCollection({
1175
+ name: colInfo.name,
1176
+ embeddingFunction: dummyEmbeddingFunction,
1177
+ metadata: { "hnsw:space": "cosine" }
1178
+ });
1179
+ const results = await collection.query({
1180
+ queryEmbeddings: [emb],
1181
+ nResults: 5
1182
+ });
1183
+ const originProject = colInfo.name === 'lemma-cache' ? 'global' : colInfo.name.replace('lemma-cache-', '');
1184
+ (results.ids[0] || []).forEach((id, i) => {
1185
+ const meta = results.metadatas[0][i];
1186
+ const dists = results.distances;
1187
+ const dist = (dists && dists[0] && dists[0][i] !== null && dists[0][i] !== undefined) ? dists[0][i] : 1.0;
1188
+ let parsedResponse = meta.response;
1189
+ try {
1190
+ parsedResponse = JSON.parse(meta.response);
1191
+ }
1192
+ catch { }
1193
+ allResults.push({
1194
+ id,
1195
+ prompt: meta.prompt,
1196
+ response: parsedResponse,
1197
+ timestamp: meta.timestamp,
1198
+ similarity: 1 - dist,
1199
+ project: originProject
1200
+ });
1201
+ });
1202
+ }
1203
+ catch { }
1204
+ }
1205
+ // 2. Sort all project results by similarity descending
1206
+ allResults.sort((a, b) => b.similarity - a.similarity);
1207
+ res.json({ results: allResults.slice(0, 10) });
1181
1208
  }
1182
1209
  catch (e) {
1183
1210
  res.status(500).json({ error: e.message });
@@ -1206,7 +1233,7 @@ class LemmaServer {
1206
1233
  }
1207
1234
  // Clear Chroma DB collection
1208
1235
  try {
1209
- await chroma.deleteCollection({ name: `lemma-cache-${this.projectName}` }).catch(() => { });
1236
+ await chroma.deleteCollection({ name: getCollectionName(this.projectName) }).catch(() => { });
1210
1237
  }
1211
1238
  catch (e) {
1212
1239
  console.error(`[CacheClear] Failed to clear Chroma collection: ${e.message}`);
@@ -1223,7 +1250,7 @@ class LemmaServer {
1223
1250
  // Selective delete from Chroma DB collection using provider metadata filter
1224
1251
  try {
1225
1252
  const collection = await chroma.getOrCreateCollection({
1226
- name: `lemma-cache-${this.projectName}`,
1253
+ name: getCollectionName(this.projectName),
1227
1254
  embeddingFunction: dummyEmbeddingFunction,
1228
1255
  metadata: { "hnsw:space": "cosine" }
1229
1256
  });
@@ -1291,7 +1318,7 @@ class LemmaServer {
1291
1318
  const emb = await getEmbedding("architectural design guidelines and core stack configuration decisions");
1292
1319
  if (emb) {
1293
1320
  const collection = await chroma.getOrCreateCollection({
1294
- name: `lemma-cache-${this.projectName}`,
1321
+ name: getCollectionName(this.projectName),
1295
1322
  embeddingFunction: dummyEmbeddingFunction,
1296
1323
  metadata: { "hnsw:space": "cosine" }
1297
1324
  });
@@ -1362,7 +1389,7 @@ class LemmaServer {
1362
1389
  return res.status(500).json({ error: 'Failed to generate embedding' });
1363
1390
  }
1364
1391
  const collection = await chroma.getOrCreateCollection({
1365
- name: `lemma-cache-${this.projectName}`,
1392
+ name: getCollectionName(this.projectName),
1366
1393
  embeddingFunction: dummyEmbeddingFunction,
1367
1394
  metadata: { "hnsw:space": "cosine" }
1368
1395
  });