@danielsimonjr/memoryjs 1.2.0 → 1.2.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,13 +1,13 @@
1
1
  # MemoryJS
2
2
 
3
- [![Version](https://img.shields.io/badge/version-1.0.0-blue.svg)](https://github.com/danielsimonjr/memoryjs)
3
+ [![Version](https://img.shields.io/badge/version-1.2.0-blue.svg)](https://github.com/danielsimonjr/memoryjs)
4
4
  [![NPM](https://img.shields.io/npm/v/@danielsimonjr/memoryjs.svg)](https://www.npmjs.com/package/@danielsimonjr/memoryjs)
5
5
  [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
6
6
  [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-blue.svg)](https://www.typescriptlang.org/)
7
7
 
8
8
  A **TypeScript knowledge graph library** for managing entities, relations, and observations with **advanced search capabilities**, **hierarchical organization**, and **multiple storage backends**.
9
9
 
10
- > **Core library** powering [@danielsimonjr/memory-mcp](https://www.npmjs.com/package/@danielsimonjr/memory-mcp). Provides 73 TypeScript files, ~29K lines of code, dual storage backends (JSONL/SQLite), and sophisticated search algorithms including BM25, TF-IDF, fuzzy, semantic, and hybrid search.
10
+ > **Core library** powering [@danielsimonjr/memory-mcp](https://www.npmjs.com/package/@danielsimonjr/memory-mcp). Provides **93 TypeScript files**, **~41K lines of code**, dual storage backends (JSONL/SQLite), sophisticated search algorithms (BM25, TF-IDF, fuzzy, semantic, hybrid), and a complete **Agent Memory System** for AI agents.
11
11
 
12
12
  ## Table of Contents
13
13
 
@@ -18,6 +18,7 @@ A **TypeScript knowledge graph library** for managing entities, relations, and o
18
18
  - [Storage Options](#storage-options)
19
19
  - [Search Capabilities](#search-capabilities)
20
20
  - [Graph Algorithms](#graph-algorithms)
21
+ - [Agent Memory System](#agent-memory-system)
21
22
  - [API Reference](#api-reference)
22
23
  - [Configuration](#configuration)
23
24
  - [Development](#development)
@@ -50,14 +51,15 @@ A **TypeScript knowledge graph library** for managing entities, relations, and o
50
51
 
51
52
  | Module | Files | Key Components |
52
53
  |--------|-------|----------------|
54
+ | `agent/` | 19 | AgentMemoryManager, SessionManager, DecayEngine, WorkingMemoryManager |
53
55
  | `core/` | 12 | EntityManager, GraphStorage, SQLiteStorage, TransactionManager |
54
56
  | `search/` | 29 | SearchManager, BM25Search, HybridScorer, VectorStore, QueryPlanner |
55
57
  | `features/` | 9 | IOManager, ArchiveManager, CompressionManager, StreamingExporter |
56
58
  | `utils/` | 18 | BatchProcessor, CompressedCache, WorkerPoolManager, MemoryMonitor |
57
- | `types/` | 2 | Entity, Relation, KnowledgeGraph interfaces |
59
+ | `types/` | 3 | Entity, Relation, AgentEntity, SessionEntity interfaces |
58
60
  | `workers/` | 2 | Levenshtein distance calculations |
59
61
 
60
- **Total:** 73 TypeScript files | ~29,000 lines of code | 558 exports
62
+ **Total:** 93 TypeScript files | ~41,000 lines of code | 657 exports | 91 classes | 216 interfaces
61
63
 
62
64
  ## Installation
63
65
 
@@ -353,6 +355,110 @@ await ctx.graphTraversal.dfs('startNode', (node) => {
353
355
  });
354
356
  ```
355
357
 
358
+ ## Agent Memory System
359
+
360
+ A complete memory system for AI agents with working memory, episodic memory, decay mechanisms, and multi-agent support.
361
+
362
+ ### Key Components
363
+
364
+ | Component | Description |
365
+ |-----------|-------------|
366
+ | **AgentMemoryManager** | Unified facade for all agent memory operations |
367
+ | **SessionManager** | Session lifecycle management |
368
+ | **WorkingMemoryManager** | Short-term memory with promotion to long-term |
369
+ | **EpisodicMemoryManager** | Timeline-based episodic memory |
370
+ | **DecayEngine** | Time-based memory importance decay |
371
+ | **SalienceEngine** | Context-aware memory scoring |
372
+ | **MultiAgentMemoryManager** | Shared memory with visibility controls |
373
+ | **ConflictResolver** | Resolution strategies for concurrent updates |
374
+
375
+ ### Quick Start
376
+
377
+ ```typescript
378
+ import { ManagerContext } from '@danielsimonjr/memoryjs';
379
+
380
+ const ctx = new ManagerContext('./memory.jsonl');
381
+ const agent = ctx.agentMemory();
382
+
383
+ // Start a session
384
+ const session = await agent.startSession({ agentId: 'my-agent' });
385
+
386
+ // Add working memory
387
+ await agent.addWorkingMemory({
388
+ sessionId: session.name,
389
+ content: 'User prefers dark mode',
390
+ importance: 7
391
+ });
392
+
393
+ // Create episodic memory
394
+ await agent.createEpisode('Completed onboarding flow', {
395
+ sessionId: session.name,
396
+ importance: 8
397
+ });
398
+
399
+ // Retrieve context for LLM prompt
400
+ const context = await agent.retrieveForContext({
401
+ maxTokens: 2000,
402
+ includeEpisodic: true
403
+ });
404
+
405
+ // End session
406
+ await agent.endSession(session.name);
407
+ ```
408
+
409
+ ### Memory Types
410
+
411
+ ```typescript
412
+ type MemoryType = 'working' | 'episodic' | 'semantic' | 'procedural';
413
+ ```
414
+
415
+ - **Working Memory**: Short-term, session-scoped memories that may be promoted
416
+ - **Episodic Memory**: Timeline-based event memories with temporal ordering
417
+ - **Semantic Memory**: Long-term factual knowledge
418
+ - **Procedural Memory**: Learned behaviors and patterns
419
+
420
+ ### Decay System
421
+
422
+ Memories naturally decay over time unless reinforced:
423
+
424
+ ```typescript
425
+ // Configure decay behavior
426
+ const agent = ctx.agentMemory({
427
+ decay: {
428
+ halfLifeHours: 168, // 1 week half-life
429
+ minImportance: 0.1 // Never fully forget
430
+ },
431
+ enableAutoDecay: true
432
+ });
433
+
434
+ // Reinforce important memories
435
+ await agent.confirmMemory('memory_name', 0.1); // Boost confidence
436
+ await agent.promoteMemory('memory_name', 'episodic'); // Promote to long-term
437
+ ```
438
+
439
+ ### Multi-Agent Support
440
+
441
+ ```typescript
442
+ // Register agents
443
+ agent.registerAgent('agent_1', {
444
+ name: 'Research Agent',
445
+ type: 'llm',
446
+ trustLevel: 0.8,
447
+ capabilities: ['read', 'write']
448
+ });
449
+
450
+ // Create memories with visibility controls
451
+ await agent.addWorkingMemory({
452
+ sessionId: session.name,
453
+ content: 'Shared insight',
454
+ visibility: 'shared', // 'private' | 'shared' | 'public'
455
+ ownerAgentId: 'agent_1'
456
+ });
457
+
458
+ // Cross-agent search
459
+ const results = await agent.searchCrossAgent('agent_2', 'query');
460
+ ```
461
+
356
462
  ## API Reference
357
463
 
358
464
  ### EntityManager
@@ -472,8 +578,18 @@ npm run typecheck # Type checking without emit
472
578
 
473
579
  ```
474
580
  memoryjs/
475
- ├── src/ # Source (73 TypeScript files)
581
+ ├── src/ # Source (93 TypeScript files)
476
582
  │ ├── index.ts # Entry point
583
+ │ ├── agent/ # Agent Memory System (19 files)
584
+ │ │ ├── AgentMemoryManager.ts # Unified facade
585
+ │ │ ├── SessionManager.ts # Session lifecycle
586
+ │ │ ├── WorkingMemoryManager.ts # Working memory
587
+ │ │ ├── EpisodicMemoryManager.ts # Episodic memory
588
+ │ │ ├── DecayEngine.ts # Memory decay
589
+ │ │ ├── SalienceEngine.ts # Context scoring
590
+ │ │ ├── MultiAgentMemoryManager.ts # Multi-agent support
591
+ │ │ ├── ConflictResolver.ts # Conflict resolution
592
+ │ │ └── ...
477
593
  │ ├── core/ # Core managers (12 files)
478
594
  │ │ ├── ManagerContext.ts # Context holder (lazy init)
479
595
  │ │ ├── EntityManager.ts # Entity CRUD + hierarchy
@@ -497,10 +613,10 @@ memoryjs/
497
613
  │ │ ├── ArchiveManager.ts # Entity archival
498
614
  │ │ ├── CompressionManager.ts # Duplicate detection
499
615
  │ │ └── ...
500
- │ ├── types/ # TypeScript definitions (2 files)
616
+ │ ├── types/ # TypeScript definitions (3 files)
501
617
  │ ├── utils/ # Shared utilities (18 files)
502
618
  │ └── workers/ # Worker pool (2 files)
503
- ├── tests/ # Test suite
619
+ ├── tests/ # Test suite (3600+ tests)
504
620
  │ ├── unit/ # Unit tests
505
621
  │ ├── integration/ # Integration tests
506
622
  │ └── performance/ # Benchmarks
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielsimonjr/memoryjs",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Core knowledge graph library with search, storage, and graph algorithms",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -1,266 +0,0 @@
1
- # @danielsimonjr/memoryjs
2
-
3
- Core knowledge graph library for managing entities, relations, and observations with advanced search capabilities.
4
-
5
- ## Features
6
-
7
- - **Entity Management**: Create, read, update, delete entities with observations
8
- - **Relation Management**: Connect entities with typed relationships
9
- - **Hierarchical Organization**: Parent-child entity nesting
10
- - **Multiple Storage Backends**: JSONL (default) or SQLite
11
- - **Advanced Search**: Basic, ranked (TF-IDF), boolean, fuzzy, semantic, and hybrid search
12
- - **Tag Management**: Tag aliasing, bulk operations
13
- - **Graph Algorithms**: Shortest path, centrality, connected components
14
- - **Import/Export**: JSON, CSV, GraphML formats with compression
15
-
16
- ## Installation
17
-
18
- ```bash
19
- npm install @danielsimonjr/memoryjs
20
- ```
21
-
22
- ## Quick Start
23
-
24
- ```typescript
25
- import { ManagerContext } from '@danielsimonjr/memoryjs';
26
-
27
- // Initialize with JSONL storage (default)
28
- const ctx = new ManagerContext({
29
- storagePath: './memory.jsonl'
30
- });
31
-
32
- // Create entities
33
- await ctx.entityManager.createEntities([
34
- { name: 'TypeScript', entityType: 'language', observations: ['A typed superset of JavaScript'] },
35
- { name: 'Node.js', entityType: 'runtime', observations: ['JavaScript runtime built on V8'] }
36
- ]);
37
-
38
- // Create relations
39
- await ctx.relationManager.createRelations([
40
- { from: 'TypeScript', to: 'Node.js', relationType: 'runs_on' }
41
- ]);
42
-
43
- // Search entities
44
- const results = await ctx.searchManager.search('JavaScript');
45
- ```
46
-
47
- ## Storage Options
48
-
49
- ### JSONL (Default)
50
-
51
- ```typescript
52
- const ctx = new ManagerContext({
53
- storagePath: './memory.jsonl'
54
- });
55
- ```
56
-
57
- ### SQLite
58
-
59
- ```typescript
60
- const ctx = new ManagerContext({
61
- storageType: 'sqlite',
62
- storagePath: './memory.db'
63
- });
64
- ```
65
-
66
- SQLite provides:
67
- - FTS5 full-text search with BM25 ranking
68
- - Referential integrity (ON DELETE CASCADE)
69
- - WAL mode for better concurrency
70
- - ACID transactions
71
-
72
- ## Core Components
73
-
74
- ### ManagerContext
75
-
76
- Central access point for all managers:
77
-
78
- ```typescript
79
- ctx.entityManager // Entity CRUD + hierarchy
80
- ctx.relationManager // Relation management
81
- ctx.searchManager // All search operations
82
- ctx.tagManager // Tag aliases
83
- ctx.ioManager // Import/export/backup
84
- ctx.graphTraversal // Graph algorithms
85
- ctx.semanticSearch // Vector similarity search (optional)
86
- ```
87
-
88
- ### Entity Structure
89
-
90
- ```typescript
91
- interface Entity {
92
- name: string; // Unique identifier
93
- entityType: string; // Classification
94
- observations: string[]; // Facts about the entity
95
- parentId?: string; // For hierarchy
96
- tags?: string[]; // Categories
97
- importance?: number; // 0-10 scale
98
- createdAt?: string; // ISO 8601
99
- lastModified?: string;
100
- }
101
- ```
102
-
103
- ### Relation Structure
104
-
105
- ```typescript
106
- interface Relation {
107
- from: string; // Source entity name
108
- to: string; // Target entity name
109
- relationType: string; // Connection type
110
- }
111
- ```
112
-
113
- ## Search Capabilities
114
-
115
- ### Basic Search
116
-
117
- ```typescript
118
- // Find entities by name or observation content
119
- const results = await ctx.searchManager.search('TypeScript');
120
- ```
121
-
122
- ### Ranked Search (TF-IDF)
123
-
124
- ```typescript
125
- // Get relevance-scored results
126
- const ranked = await ctx.searchManager.searchRanked('JavaScript runtime', { limit: 10 });
127
- ```
128
-
129
- ### Boolean Search
130
-
131
- ```typescript
132
- // AND, OR, NOT operators
133
- const results = await ctx.searchManager.booleanSearch('TypeScript AND runtime');
134
- const excluded = await ctx.searchManager.booleanSearch('JavaScript NOT browser');
135
- ```
136
-
137
- ### Fuzzy Search
138
-
139
- ```typescript
140
- // Typo-tolerant search
141
- const results = await ctx.searchManager.fuzzySearch('Typscript', { threshold: 0.7 });
142
- ```
143
-
144
- ### Hybrid Search
145
-
146
- Combines semantic (vector), lexical (TF-IDF), and symbolic (metadata) signals:
147
-
148
- ```typescript
149
- const results = await ctx.searchManager.hybridSearch('programming concepts', {
150
- weights: { semantic: 0.5, lexical: 0.3, symbolic: 0.2 },
151
- filters: { entityTypes: ['concept'], minImportance: 5 }
152
- });
153
- ```
154
-
155
- ## Graph Algorithms
156
-
157
- ```typescript
158
- // Shortest path between entities
159
- const path = await ctx.graphTraversal.findShortestPath('A', 'Z');
160
-
161
- // All paths up to max depth
162
- const paths = await ctx.graphTraversal.findAllPaths('A', 'Z', { maxDepth: 5 });
163
-
164
- // Centrality analysis
165
- const centrality = await ctx.graphTraversal.getCentrality({ algorithm: 'pagerank' });
166
-
167
- // Connected components
168
- const components = await ctx.graphTraversal.getConnectedComponents();
169
- ```
170
-
171
- ## Import/Export
172
-
173
- ```typescript
174
- // Export to JSON
175
- const json = await ctx.ioManager.exportGraph('json');
176
-
177
- // Export to CSV
178
- const csv = await ctx.ioManager.exportGraph('csv');
179
-
180
- // Export to GraphML (with compression)
181
- await ctx.ioManager.exportGraph('graphml', {
182
- outputPath: './graph.graphml.br',
183
- compress: true
184
- });
185
-
186
- // Import from file
187
- await ctx.ioManager.importGraph('json', jsonData, { mergeStrategy: 'merge' });
188
- ```
189
-
190
- ## Hierarchical Organization
191
-
192
- ```typescript
193
- // Set parent
194
- await ctx.entityManager.setEntityParent('Component', 'Module');
195
-
196
- // Get hierarchy
197
- const children = await ctx.entityManager.getChildren('Module');
198
- const ancestors = await ctx.entityManager.getAncestors('Component');
199
- const subtree = await ctx.entityManager.getSubtree('Module');
200
- ```
201
-
202
- ## Tag Management
203
-
204
- ```typescript
205
- // Add/remove tags
206
- await ctx.entityManager.addTags('Entity1', ['tag1', 'tag2']);
207
- await ctx.entityManager.removeTags('Entity1', ['tag1']);
208
-
209
- // Tag aliases (synonyms)
210
- await ctx.tagManager.addTagAlias('js', 'javascript');
211
-
212
- // Bulk operations
213
- await ctx.entityManager.addTagsToMultipleEntities(['E1', 'E2'], ['shared-tag']);
214
- ```
215
-
216
- ## API Reference
217
-
218
- ### EntityManager
219
-
220
- | Method | Description |
221
- |--------|-------------|
222
- | `createEntities(entities)` | Create multiple entities |
223
- | `deleteEntities(names)` | Delete entities by name |
224
- | `getEntityByName(name)` | Get single entity |
225
- | `addObservations(name, observations)` | Add observations to entity |
226
- | `deleteObservations(name, observations)` | Remove observations |
227
- | `addTags(name, tags)` | Add tags to entity |
228
- | `removeTags(name, tags)` | Remove tags from entity |
229
- | `setImportance(name, score)` | Set importance (0-10) |
230
- | `setEntityParent(name, parentName)` | Set hierarchy parent |
231
- | `getChildren(name)` | Get child entities |
232
- | `getAncestors(name)` | Get ancestor chain |
233
- | `getDescendants(name)` | Get all descendants |
234
-
235
- ### SearchManager
236
-
237
- | Method | Description |
238
- |--------|-------------|
239
- | `search(query, options)` | Basic search |
240
- | `searchRanked(query, options)` | TF-IDF ranked search |
241
- | `booleanSearch(query, options)` | Boolean operators |
242
- | `fuzzySearch(query, options)` | Typo-tolerant |
243
- | `hybridSearch(query, options)` | Multi-signal search |
244
- | `smartSearch(query, options)` | AI-assisted refinement |
245
-
246
- ### IOManager
247
-
248
- | Method | Description |
249
- |--------|-------------|
250
- | `exportGraph(format, options)` | Export to format |
251
- | `importGraph(format, data, options)` | Import from format |
252
- | `createBackup(options)` | Create backup |
253
- | `restoreBackup(path)` | Restore from backup |
254
-
255
- ## Requirements
256
-
257
- - Node.js >= 18.0.0
258
- - TypeScript >= 5.0 (for development)
259
-
260
- ## License
261
-
262
- MIT
263
-
264
- ## Related
265
-
266
- - [@danielsimonjr/memory-mcp](https://github.com/danielsimonjr/memory-mcp) - MCP server built on this library