lemma-mcp 0.8.7 → 0.9.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.
Files changed (64) hide show
  1. package/README.md +155 -424
  2. package/dist/guides/core.d.ts.map +1 -1
  3. package/dist/guides/core.js +8 -1
  4. package/dist/guides/core.js.map +1 -1
  5. package/dist/guides/index.d.ts +1 -0
  6. package/dist/guides/index.d.ts.map +1 -1
  7. package/dist/guides/index.js +1 -0
  8. package/dist/guides/index.js.map +1 -1
  9. package/dist/guides/seed.d.ts +7 -0
  10. package/dist/guides/seed.d.ts.map +1 -0
  11. package/dist/guides/seed.js +190 -0
  12. package/dist/guides/seed.js.map +1 -0
  13. package/dist/logger.d.ts +2 -0
  14. package/dist/logger.d.ts.map +1 -1
  15. package/dist/logger.js +10 -1
  16. package/dist/logger.js.map +1 -1
  17. package/dist/memory/config.d.ts.map +1 -1
  18. package/dist/memory/config.js +8 -1
  19. package/dist/memory/config.js.map +1 -1
  20. package/dist/memory/core.d.ts +3 -3
  21. package/dist/memory/core.d.ts.map +1 -1
  22. package/dist/memory/core.js +53 -3
  23. package/dist/memory/core.js.map +1 -1
  24. package/dist/memory/embeddings.d.ts +20 -0
  25. package/dist/memory/embeddings.d.ts.map +1 -0
  26. package/dist/memory/embeddings.js +187 -0
  27. package/dist/memory/embeddings.js.map +1 -0
  28. package/dist/memory/index.d.ts +1 -0
  29. package/dist/memory/index.d.ts.map +1 -1
  30. package/dist/memory/index.js +1 -0
  31. package/dist/memory/index.js.map +1 -1
  32. package/dist/memory/seed.d.ts.map +1 -1
  33. package/dist/memory/seed.js +99 -104
  34. package/dist/memory/seed.js.map +1 -1
  35. package/dist/server/agents-md.d.ts +7 -0
  36. package/dist/server/agents-md.d.ts.map +1 -0
  37. package/dist/server/agents-md.js +106 -0
  38. package/dist/server/agents-md.js.map +1 -0
  39. package/dist/server/handlers.d.ts +3 -0
  40. package/dist/server/handlers.d.ts.map +1 -1
  41. package/dist/server/handlers.js +146 -40
  42. package/dist/server/handlers.js.map +1 -1
  43. package/dist/server/index.d.ts +0 -3
  44. package/dist/server/index.d.ts.map +1 -1
  45. package/dist/server/index.js +129 -221
  46. package/dist/server/index.js.map +1 -1
  47. package/dist/server/system-prompt.d.ts +5 -2
  48. package/dist/server/system-prompt.d.ts.map +1 -1
  49. package/dist/server/system-prompt.js +293 -110
  50. package/dist/server/system-prompt.js.map +1 -1
  51. package/dist/server/tools.d.ts.map +1 -1
  52. package/dist/server/tools.js +5 -5
  53. package/dist/server/tools.js.map +1 -1
  54. package/dist/server/traffic-log.d.ts +5 -0
  55. package/dist/server/traffic-log.d.ts.map +1 -0
  56. package/dist/server/traffic-log.js +180 -0
  57. package/dist/server/traffic-log.js.map +1 -0
  58. package/dist/sessions/virtual.d.ts +11 -1
  59. package/dist/sessions/virtual.d.ts.map +1 -1
  60. package/dist/sessions/virtual.js +226 -4
  61. package/dist/sessions/virtual.js.map +1 -1
  62. package/dist/types.d.ts +9 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/package.json +10 -7
package/README.md CHANGED
@@ -1,424 +1,155 @@
1
- <p align="center">
2
- <img src="assets/logo.png" width="200" alt="Lemma Logo">
3
- </p>
4
-
5
- # Lemma - Persistent Memory for LLMs via MCP
6
-
7
- [English](README.md) | [Türkçe](docs/README.tr.md)
8
-
9
- Lemma is an MCP server that gives LLMs persistent, cross-session memory. Memories are injected automatically into every session — no explicit tool call needed. Knowledge evolves through use: frequently accessed memories strengthen, unused ones fade, and patterns are promoted into reusable skills.
10
-
11
- ## Quick Start
12
-
13
- Add Lemma to your MCP client configuration:
14
-
15
- **Claude Desktop (Windows):** `%APPDATA%\Claude\claude_desktop_config.json`
16
- **Claude Desktop (macOS):** `~/Library/Application Support/Claude/claude_desktop_config.json`
17
- **opencode:** `%APPDATA%\opencode\opencode.json`
18
-
19
- ```json
20
- {
21
- "mcpServers": {
22
- "lemma": {
23
- "command": "npx",
24
- "args": ["-y", "lemma-mcp@latest"]
25
- }
26
- }
27
- }
28
- ```
29
-
30
- > Using `@latest` ensures npx always fetches the newest version.
31
-
32
- **Requirements:** Node.js 18.0.0 or higher
33
-
34
- ## How It Works
35
-
36
- ### Universal Memory Injection
37
-
38
- Memories are injected into tool descriptions via `tools/list`. The LLM starts every session already knowing its most important memories — works on every MCP client.
39
-
40
- **3-layer architecture:**
41
- - Layer 1: Full content for top memories (token-budgeted)
42
- - Layer 2: Summary index for remaining memories
43
- - Layer 3: Active guides with learnings
44
-
45
- ### Fragment Types
46
-
47
- Every memory fragment has a type that classifies its nature:
48
-
49
- | Type | Use For | Example |
50
- |------|---------|---------|
51
- | `fact` | Technical info, API behavior, versions | "Node.js 22 has native fetch" |
52
- | `pattern` | Repeated solution, best practice | "React useEffect cleanup pattern" |
53
- | `lesson` | Learned from experience, debugging | "JSONL parse errors silently swallow broken lines" |
54
- | `warning` | Caution, gotcha, pitfall | "fs.writeFileSync blocks the event loop" |
55
- | `context` | Environment info, project setup | "This project uses Python 3.11 with py launcher" |
56
-
57
- Default is `fact` if not specified.
58
-
59
- ### Memory Guide Pipeline
60
-
61
- Knowledge flows through a two-way pipeline:
62
-
63
- 1. **Memory** = WHAT you know — facts, observations, technical details (`memory_add`)
64
- 2. **Guide** = HOW you work — accumulated experience, procedural skills (`guide_practice`, `guide_distill`)
65
-
66
- Connections are **bidirectional** and automatic:
67
- - `guide_distill` links memory to guide AND guide to memory
68
- - `guide_practice` session-read memories validate the guide
69
- - `memory_merge` relations, guide links, and associations are inherited by the merged fragment
70
-
71
- ### Response Hooks (Suggested Actions)
72
-
73
- Tool responses include contextual `SUGGESTED ACTIONS` when meaningful connections are detected. For example:
74
-
75
- - `memory_add` with topic overlap → "Call `memory_relate` to link these fragments"
76
- - `memory_add` with type `pattern` → "Call `guide_distill` to promote into a skill"
77
- - `memory_feedback` positive "Call `guide_distill` to convert into a reusable skill"
78
- - `session_end` with activity → Full review with relate + distill + practice suggestions
79
-
80
- Hooks only appear when there's meaningful context no noise in empty states.
81
-
82
- ### Learning System
83
-
84
- Knowledge evolves through use with a biological memory model:
85
-
86
- - **Shield**: Accessed items are protected from decay entirely
87
- - **Unused items** decay very slowly (0.002 per session)
88
- - **Negative feedback** reduces confidence by -0.02
89
- - **Associations**: Fragments used together build cross-references automatically
90
- - **No time-based decay**: Confidence only changes when the system is actively used
91
-
92
- ### Memory Structure
93
-
94
- | Field | Type | Description |
95
- |-------|------|-------------|
96
- | `id` | string | Unique identifier (`m` + 12 hex chars) |
97
- | `title` | string | Short title |
98
- | `fragment` | string | Synthesized memory text |
99
- | `type` | FragmentType | `fact`, `pattern`, `lesson`, `warning`, or `context` |
100
- | `project` | string | Project scope (`null` for global) |
101
- | `confidence` | float | Reliability 0.0-1.0 |
102
- | `source` | string | `"user"` or `"ai"` |
103
- | `relations` | MemoryRelation[] | Typed links to other fragments |
104
- | `related_guides` | string[] | Guide names this fragment informs |
105
- | `associatedWith` | string[] | IDs of co-accessed fragments |
106
- | `tags` | string[] | Context tags from usage |
107
- | `accessed` | int | Access count in current decay cycle |
108
-
109
- ### Guide Structure
110
-
111
- | Field | Type | Description |
112
- |-------|------|-------------|
113
- | `guide` | string | Guide name |
114
- | `category` | string | Category (e.g., `web-frontend`, `dev-tool`) |
115
- | `description` | string | Full manual/protocols |
116
- | `source_memories` | string[] | Memory IDs that spawned this guide |
117
- | `validated_by` | string[] | Memory IDs that validated this guide in practice |
118
- | `usage_count` | int | Times practiced |
119
- | `success_count` | int | Successful uses |
120
- | `failure_count` | int | Failed uses |
121
- | `learnings` | string[] | Accumulated learnings |
122
- | `contexts` | string[] | Contexts where used |
123
-
124
- ### Virtual Sessions
125
-
126
- Tool calls are automatically correlated into virtual sessions:
127
- - Auto-starts on first tool call, auto-finalizes after 30 min inactivity
128
- - Tracks technologies seen, guides used, memories created/accessed
129
- - No explicit `session_start`/`session_end` required
130
-
131
- ### Configuration
132
-
133
- Optional config at `~/.lemma/config.json`:
134
-
135
- ```json
136
- {
137
- "token_budget": {
138
- "full_content": 3000,
139
- "summary_index": 1000,
140
- "guides_detail": 1000
141
- },
142
- "injection": {
143
- "max_full_content_fragments": 15,
144
- "max_summary_fragments": 30,
145
- "max_guides": 20,
146
- "max_guide_detail": 3
147
- },
148
- "virtual_session": {
149
- "timeout_minutes": 30
150
- }
151
- }
152
- ```
153
-
154
- ### File Locations
155
-
156
- | OS | Path |
157
- |---|---|
158
- | **Windows** | `C:\Users\{username}\.lemma\` |
159
- | **macOS** | `/Users/{username}/.lemma/` |
160
- | **Linux** | `/home/{username}/.lemma/` |
161
-
162
- Files: `memory.jsonl`, `guides.jsonl`, `config.json`, `sessions/`, `logs/`, `.bak` backups
163
-
164
- ---
165
-
166
- ## Available Tools (21)
167
-
168
- ### Memory Tools (11)
169
-
170
- #### `memory_read`
171
-
172
- Read memory fragments. SUMMARY MODE shows title + description; use `id` for full detail.
173
-
174
- **Parameters:**
175
- - `project` (string, optional): Project name to filter
176
- - `query` (string, optional): Semantic search keyword
177
- - `id` (string, optional): Get full detail for a specific fragment
178
- - `ids` (string[], optional): Get full details for multiple fragments at once
179
- - `context` (string, optional): Tag this access with a context (e.g., "debugging")
180
- - `all` (boolean, optional): Show fragments from all projects (default: false)
181
- - `minConfidence` (number, optional): Minimum confidence threshold (0-1)
182
- - `afterDate` (string, optional): ISO date — only fragments created on or after
183
- - `beforeDate` (string, optional): ISO date — only fragments created on or before
184
-
185
- #### `memory_add`
186
-
187
- **MANDATORY:** Call AFTER completing analysis to save findings. Automatically redacts secrets unless `confirm: true`.
188
-
189
- **Parameters:**
190
- - `fragment` (string, required): Memory text. Use structured markdown: `## [Topic]\n[Context]\n- [Key points]`
191
- - `title` (string, optional): Short title (max 80 chars)
192
- - `description` (string, optional): Short summary (max 150 chars)
193
- - `project` (string, optional): Project scope (null = global)
194
- - `source` (string, optional): "user" or "ai", default "ai"
195
- - `confirm` (boolean, optional): Store as-is even if secrets detected (default: false)
196
- - `type` (string, optional): Fragment type — `fact`, `pattern`, `lesson`, `warning`, or `context` (default: `fact`)
197
-
198
- #### `memory_update`
199
-
200
- Update an existing fragment by ID.
201
-
202
- **Parameters:**
203
- - `id` (string, required): Fragment ID
204
- - `title` (string, optional): New title
205
- - `fragment` (string, optional): New text
206
- - `confidence` (number, optional): New confidence 0-1
207
-
208
- #### `memory_feedback`
209
-
210
- Provide feedback on a memory fragment after use. Positive boosts confidence; negative reduces by -0.02.
211
-
212
- **Parameters:**
213
- - `id` (string, required): Fragment ID
214
- - `useful` (boolean, required): `true` if helpful, `false` if not
215
-
216
- #### `memory_forget`
217
-
218
- Remove a memory fragment by ID.
219
-
220
- **Parameters:**
221
- - `id` (string, required): Fragment ID
222
-
223
- #### `memory_merge`
224
-
225
- Merge multiple fragments into one. Relations, guide links, and associations are inherited by the merged fragment.
226
-
227
- **Parameters:**
228
- - `ids` (string[], required): Fragment IDs to merge
229
- - `title` (string, required): Title for merged fragment
230
- - `fragment` (string, required): Merged content
231
- - `project` (string, optional): Project scope
232
-
233
- #### `memory_relate`
234
-
235
- Create a typed relation between two memory fragments. Bidirectional — reverse relation auto-created.
236
-
237
- **Parameters:**
238
- - `sourceId` (string, required): Source fragment ID
239
- - `targetId` (string, required): Target fragment ID
240
- - `type` (string, required): `contradicts`, `supersedes`, `supports`, or `related_to`
241
- - `note` (string, optional): Note explaining the relation
242
-
243
- #### `memory_stats`
244
-
245
- Get memory store statistics.
246
-
247
- **Parameters:**
248
- - `project` (string, optional): Filter by project
249
-
250
- #### `memory_audit`
251
-
252
- Audit memory store for integrity issues.
253
-
254
- ### Guide Tools (8)
255
-
256
- #### `guide_get`
257
-
258
- Get guides with usage statistics, sorted by usage count.
259
-
260
- **Parameters:**
261
- - `category` (string, optional): Filter by category
262
- - `guide` (string, optional): Get detail for specific guide
263
- - `task` (string, optional): Task description to get relevant suggestions
264
-
265
- #### `guide_practice`
266
-
267
- **MANDATORY:** Record guide usage during work.
268
-
269
- **Parameters:**
270
- - `guide` (string, required): Guide name
271
- - `category` (string, required): Category
272
- - `description` (string, optional): Detailed manual/protocols
273
- - `contexts` (string[], required): Contexts where used
274
- - `learnings` (string[], required): New learnings discovered
275
- - `outcome` (string, optional): "success" or "failure"
276
-
277
- #### `guide_create`
278
-
279
- Create a guide with a detailed manual.
280
-
281
- **Parameters:**
282
- - `guide` (string, required): Guide name
283
- - `category` (string, required): Category
284
- - `description` (string, required): Full manual/protocols
285
- - `contexts` (string[], optional): Initial contexts
286
- - `learnings` (string[], optional): Initial learnings
287
-
288
- #### `guide_distill`
289
-
290
- Transform a memory fragment into a guide's learning. Creates bidirectional link (memory ↔ guide).
291
-
292
- **Parameters:**
293
- - `memory_id` (string, required): Memory fragment ID
294
- - `guide` (string, required): Target guide name
295
- - `category` (string, optional): Category (required if creating new guide)
296
-
297
- #### `guide_update`
298
-
299
- Update an existing guide's properties.
300
-
301
- **Parameters:**
302
- - `guide` (string, required): Current guide name
303
- - `new_name` (string, optional): New name
304
- - `category` (string, optional): New category
305
- - `description` (string, optional): New description/manual
306
- - `add_anti_patterns` (string[], optional): Add anti-patterns
307
- - `add_pitfalls` (string[], optional): Add known pitfalls
308
- - `superseded_by` (string, optional): Mark as superseded
309
- - `deprecated` (boolean, optional): Mark as deprecated
310
-
311
- #### `guide_forget`
312
-
313
- Remove a guide.
314
-
315
- **Parameters:**
316
- - `guide` (string, required): Guide name
317
-
318
- #### `guide_merge`
319
-
320
- Merge multiple guides into one. Source memories and validations are inherited.
321
-
322
- **Parameters:**
323
- - `guides` (string[], required): Guide names to merge
324
- - `guide` (string, required): Name for merged guide
325
- - `category` (string, required): Category
326
- - `description` (string, optional): Merged description
327
- - `contexts` (string[], optional): Merged contexts
328
- - `learnings` (string[], optional): Merged learnings
329
-
330
- ### Session Tools (2)
331
-
332
- #### `session_start`
333
-
334
- Start a traced work session. Pre-loads relevant guides and memories.
335
-
336
- **Parameters:**
337
- - `task_type` (string, required): "debugging", "implementation", "refactoring", "testing", "research", "documentation", "optimization", or "other"
338
- - `technologies` (string[], optional): Technologies involved
339
- - `initial_approach` (string, optional): Initial plan
340
-
341
- #### `session_end`
342
-
343
- End the current session. Shows SESSION REVIEW with activity summary and suggestions.
344
-
345
- **Parameters:**
346
- - `outcome` (string, required): "success", "partial", "failure", or "abandoned"
347
- - `final_approach` (string, optional): What approach worked
348
- - `lessons` (string[], optional): What was learned
349
-
350
- #### `session_stats`
351
-
352
- Get virtual session statistics.
353
-
354
- **Parameters:**
355
- - `count` (number, optional): Number of recent sessions (default 10)
356
-
357
- ---
358
-
359
- ## Manual Installation
360
-
361
- ```bash
362
- git clone https://github.com/xenitV1/lemma
363
- cd Lemma
364
- npm install
365
- ```
366
-
367
- ```json
368
- {
369
- "mcpServers": {
370
- "lemma": {
371
- "command": "node",
372
- "args": ["C:\\path\\to\\Lemma\\dist\\index.js"]
373
- }
374
- }
375
- }
376
- ```
377
-
378
- ## Development
379
-
380
- ```bash
381
- npm test # 481 tests
382
- npm run typecheck # TypeScript type checking
383
- npm run build # Compile to dist/
384
- ```
385
-
386
- ### Project Structure
387
-
388
- ```
389
- Lemma/
390
- ├── src/
391
- │ ├── index.ts # MCP server entry point
392
- │ ├── types.ts # Shared TypeScript interfaces (MemoryFragment, Guide, FragmentType...)
393
- │ ├── memory/
394
- │ │ ├── core.ts # Core memory logic, decay, search, dedup, relations, associations
395
- │ │ ├── config.ts # User configuration loader
396
- │ │ ├── seed.ts # Built-in seed knowledge fragments
397
- │ │ └── privacy.ts # Secret scanning and redaction
398
- │ ├── guides/
399
- │ │ ├── core.ts # Core guides logic, fuzzy dedup, source_memories, validated_by
400
- │ │ └── task-map.ts # Task-to-guide mapping
401
- │ ├── server/
402
- │ │ ├── index.ts # Server setup, injection, notifications
403
- │ │ ├── handlers.ts # Tool handlers (21 tools) + response hooks
404
- │ │ ├── tools.ts # Tool definitions
405
- │ │ ├── hooks.ts # Hook system & prompt modifiers
406
- │ │ └── system-prompt.ts # Dynamic system prompt
407
- │ └── sessions/
408
- │ ├── core.ts # Session lifecycle
409
- │ └── virtual.ts # Virtual session tracking
410
- ├── tests/ # 36 test files, 481 tests
411
- ├── docs/ # Research papers and references
412
- ├── package.json
413
- ├── tsconfig.json
414
- ├── CHANGELOG.md
415
- └── README.md
416
- ```
417
-
418
- ## Security
419
-
420
- All data is stored locally in `~/.lemma/`. Nothing is sent to external servers. Secrets are automatically redacted from memory fragments.
421
-
422
- ## License
423
-
424
- MIT License
1
+ <p align="center">
2
+ <img src="assets/logo.png" width="200" alt="Lemma Logo">
3
+ </p>
4
+
5
+ # Lemma Persistent Memory for LLMs via MCP
6
+
7
+ [English](README.md) | [Türkçe](docs/README.tr.md)
8
+
9
+ Lemma is an MCP server that gives LLMs persistent, cross-session memory. Memories are injected automatically into every session — no explicit tool call needed. Knowledge evolves through use: frequently accessed memories strengthen, unused ones fade, and patterns are promoted into reusable skills.
10
+
11
+ ## Quick Start
12
+
13
+ Add Lemma to your MCP client configuration:
14
+
15
+ **Claude Desktop (Windows):** `%APPDATA%\Claude\claude_desktop_config.json`
16
+ **Claude Desktop (macOS):** `~/Library/Application Support/Claude/claude_desktop_config.json`
17
+ **opencode:** `%APPDATA%\opencode\opencode.json`
18
+
19
+ ```json
20
+ {
21
+ "mcpServers": {
22
+ "lemma": {
23
+ "command": "npx",
24
+ "args": ["-y", "lemma-mcp@latest"]
25
+ }
26
+ }
27
+ }
28
+ ```
29
+
30
+ > Using `@latest` ensures npx always fetches the newest version.
31
+
32
+ **Requirements:** Node.js 20.0.0 or higher
33
+
34
+ ## How It Works
35
+
36
+ Memories are injected into tool descriptions via `tools/list`. The LLM starts every session already knowing its most important memories — works on every MCP client.
37
+
38
+ **3-layer injection:**
39
+ - Full content for top memories (token-budgeted)
40
+ - Summary index for remaining memories
41
+ - Active guides with learnings
42
+
43
+ **Memory types:** `fact`, `pattern`, `lesson`, `warning`, `context`
44
+
45
+ **Knowledge pipeline:** Memory (what you know, `memory_add`) ↔ Guide (how you work, `guide_practice`/`guide_distill`)
46
+
47
+ ## Tools (21)
48
+
49
+ ### Memory (11)
50
+
51
+ | Tool | Purpose |
52
+ |------|---------|
53
+ | `memory_read` | Read/search fragments. Summary mode or full detail by ID |
54
+ | `memory_add` | Save findings. Auto-redacts secrets |
55
+ | `memory_update` | Update fragment by ID |
56
+ | `memory_feedback` | Positive/negative feedback, adjusts confidence |
57
+ | `memory_forget` | Delete fragment |
58
+ | `memory_merge` | Merge fragments, inherit relations & guide links |
59
+ | `memory_relate` | Create typed links (`contradicts`, `supersedes`, `supports`, `related_to`) |
60
+ | `memory_stats` | Fragment counts, confidence, project breakdown |
61
+ | `memory_audit` | Integrity check for orphans, duplicates, anomalies |
62
+
63
+ ### Guides (8)
64
+
65
+ | Tool | Purpose |
66
+ |------|---------|
67
+ | `guide_get` | Get guides sorted by usage, filter by category or task |
68
+ | `guide_practice` | Record guide usage. Mandatory during work |
69
+ | `guide_create` | Create guide with manual |
70
+ | `guide_distill` | Transform memory → guide learning (bidirectional link) |
71
+ | `guide_update` | Update guide properties |
72
+ | `guide_forget` | Remove guide |
73
+ | `guide_merge` | Merge guides, inherit source memories |
74
+
75
+ ### Sessions (2)
76
+
77
+ | Tool | Purpose |
78
+ |------|---------|
79
+ | `session_start` | Start traced session, pre-loads relevant context |
80
+ | `session_end` | End session with review and suggestions |
81
+ | `session_stats` | Virtual session statistics |
82
+
83
+ ## Configuration
84
+
85
+ Optional config at `~/.lemma/config.json`:
86
+
87
+ ```json
88
+ {
89
+ "token_budget": {
90
+ "full_content": 5000,
91
+ "summary_index": 1000,
92
+ "guides_detail": 1000
93
+ },
94
+ "injection": {
95
+ "max_full_content_fragments": 15,
96
+ "max_summary_fragments": 30,
97
+ "max_guides": 20
98
+ },
99
+ "virtual_session": {
100
+ "timeout_minutes": 30
101
+ }
102
+ }
103
+ ```
104
+
105
+ ## File Locations
106
+
107
+ | OS | Path |
108
+ |---|---|
109
+ | **Windows** | `C:\Users\{username}\.lemma\` |
110
+ | **macOS/Linux** | `~/.lemma/` |
111
+
112
+ Files: `memory.jsonl`, `guides.jsonl`, `config.json`, `sessions/`, `logs/`, `.bak` backups
113
+
114
+ ## Semantic Search
115
+
116
+ Lemma uses **vector-first semantic search** powered by `@huggingface/transformers` (optionalDependency). When active, all search, dedup, and topic overlap detection runs on cosine similarity instead of keyword matching.
117
+
118
+ **Model:** `Xenova/paraphrase-multilingual-MiniLM-L12-v2`
119
+ - **Size:** ~470 MB (cached at `~/.lemma/models/` after first download)
120
+ - **Dimensions:** 384-dim vectors
121
+ - **Languages:** 50+ languages including Turkish, English, German, French, Spanish, Chinese, Japanese
122
+ - **Why this model:** Optimized for paraphrase detection and cross-lingual similarity. In TR-EN benchmarks, it outperforms `all-MiniLM-L12-v2` by 2-3x on semantic similarity tasks.
123
+
124
+ **Architecture:**
125
+ - `searchAndSortFragments()` — Pure vector search when model ready, Fuse.js fallback when not
126
+ - `findSimilarFragment()` Cosine dedup (threshold 0.85) replaces keyword dedup
127
+ - `findTopicOverlaps()` Cosine range (0.5–0.85) detects related but non-duplicate memories
128
+ - Guide name matching Always uses Fuse.js (keyword-based, embeddings add no value)
129
+
130
+ **Config** (`~/.lemma/config.json`):
131
+ ```json
132
+ {
133
+ "embeddings": {
134
+ "enabled": true,
135
+ "model": "Xenova/paraphrase-multilingual-MiniLM-L12-v2"
136
+ }
137
+ }
138
+ ```
139
+
140
+ Set `"enabled": false` to disable embeddings and use keyword search only. No restart needed — model loads lazily on first search. Startup auto-backfills any fragments missing vectors.
141
+
142
+ ## Security
143
+
144
+ All data is stored locally in `~/.lemma/`. Nothing is sent to external servers. Secrets are automatically redacted from memory fragments (17 regex patterns for API keys, tokens, connection strings).
145
+
146
+ ## Documentation
147
+
148
+ - [Development Guide](docs/development/DEVELOPMENT.md) — Architecture, project structure, testing
149
+ - [Roadmap](docs/development/ROADMAP.md) — v0.9, v0.10, v1.0 plans
150
+ - [Research](docs/research/README.md) — Academic papers that influenced Lemma's design
151
+ - [Changelog](CHANGELOG.md) — Version history
152
+
153
+ ## License
154
+
155
+ MIT
@@ -1 +1 @@
1
- {"version":3,"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AED,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,KAAK,GAAG,IAAI,CA+BnG;AAED,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAevE;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,KAAK,EAAE,EACf,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,GAAE,MAAW,EACxB,WAAW,GAAE,MAAM,EAAO,EAC1B,YAAY,GAAE,MAAM,EAAO,EAC3B,OAAO,GAAE,MAAM,GAAG,IAAW,GAC5B,KAAK,CA+CP;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,KAAK,GAAE,MAAW,GAAG,KAAK,EAAE,CAQzE;AAED,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,EAAE,CAG9E;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAY1D;AA8BD,wBAAgB,aAAa,CAAC,eAAe,EAAE,MAAM,EAAE,cAAc,GAAE,KAAK,EAAO,GAAG,aAAa,CAyGlG;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAsC/D;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,GAAG,MAAM,CAuD7D;AAED,OAAO,EAAE,cAAc,EAAE,CAAC"}
@@ -30,6 +30,7 @@ export function createGuide(guide, category, description = "", contexts = [], le
30
30
  learnings: learnings.map(l => l.trim()).filter(Boolean),
31
31
  success_count: 0,
32
32
  failure_count: 0,
33
+ auto_usage_count: 0,
33
34
  anti_patterns: [],
34
35
  known_pitfalls: [],
35
36
  last_refined: null,
@@ -227,6 +228,8 @@ export function practiceGuide(guides, guideName, category, description = "", new
227
228
  }
228
229
  guide.usage_count += 1;
229
230
  guide.last_used = getToday();
231
+ if (guide.auto_usage_count == null)
232
+ guide.auto_usage_count = 0;
230
233
  logger.flow("guide_practice", "updated", { guide: guideName, usageCount: guide.usage_count });
231
234
  if (!guide.description && description) {
232
235
  guide.description = description.trim();
@@ -258,7 +261,11 @@ export function practiceGuide(guides, guideName, category, description = "", new
258
261
  }
259
262
  export function getTopGuides(guides, limit = 20) {
260
263
  return [...guides]
261
- .sort((a, b) => b.usage_count - a.usage_count)
264
+ .sort((a, b) => {
265
+ const scoreA = (a.usage_count || 0) * 0.7 + (a.auto_usage_count || 0) * 0.3;
266
+ const scoreB = (b.usage_count || 0) * 0.7 + (b.auto_usage_count || 0) * 0.3;
267
+ return scoreB - scoreA;
268
+ })
262
269
  .slice(0, limit);
263
270
  }
264
271
  export function getGuidesByCategory(guides, category) {