snow-flow 2.0.3 → 2.0.5
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 +42 -1
- package/dist/memory/hierarchical-memory-system.d.ts +90 -0
- package/dist/memory/hierarchical-memory-system.js +400 -0
- package/dist/memory/index.d.ts +9 -0
- package/dist/memory/index.js +20 -0
- package/dist/memory/mcp-integration-example.d.ts +6 -0
- package/dist/memory/mcp-integration-example.js +281 -0
- package/dist/memory/memory-client.d.ts +199 -0
- package/dist/memory/memory-client.js +364 -0
- package/dist/memory/memory-manager.d.ts +29 -0
- package/dist/memory/memory-manager.js +280 -0
- package/dist/memory/memory-operations.d.ts +179 -0
- package/dist/memory/memory-operations.js +691 -0
- package/dist/memory/memory-system.d.ts +152 -0
- package/dist/memory/memory-system.js +632 -0
- package/dist/memory/memory-test.d.ts +6 -0
- package/dist/memory/memory-test.js +161 -0
- package/dist/memory/servicenow-artifact-indexer.d.ts +119 -0
- package/dist/memory/servicenow-artifact-indexer.js +560 -0
- package/dist/memory/snow-flow-memory-patterns.d.ts +213 -0
- package/dist/memory/snow-flow-memory-patterns.js +200 -0
- package/dist/memory/snow-memory.d.ts +54 -0
- package/dist/memory/snow-memory.js +301 -0
- package/dist/memory/swarm-memory.d.ts +135 -0
- package/dist/memory/swarm-memory.js +378 -0
- package/intelligent-mcp.db-shm +0 -0
- package/intelligent-mcp.db-wal +0 -0
- package/package.json +1 -1
- package/scripts/postinstall.js +30 -0
- package/scripts/update-version.js +31 -0
package/README.md
CHANGED
|
@@ -22,10 +22,51 @@ Every interaction with Snow-Flow provides insights into ServiceNow best practice
|
|
|
22
22
|
### **Real Integration, Real Results**
|
|
23
23
|
Unlike mock tools or simulations, Snow-Flow connects directly to your ServiceNow instance through secure OAuth authentication. Every operation is real, every deployment is functional, and every result is production-ready.
|
|
24
24
|
|
|
25
|
+
## 🔐 ServiceNow API Integration & Security
|
|
26
|
+
|
|
27
|
+
### **Direct ServiceNow API Connection**
|
|
28
|
+
All 100+ MCP tools use **official ServiceNow REST APIs** exclusively:
|
|
29
|
+
- **No third-party services** - Your data stays between you and ServiceNow
|
|
30
|
+
- **Standard OAuth 2.0** - Industry-standard authentication protocol
|
|
31
|
+
- **ServiceNow ACLs respected** - Only access what your ServiceNow user can access
|
|
32
|
+
- **Real-time operations** - Direct API calls, no data caching or storage
|
|
33
|
+
|
|
34
|
+
### **How OAuth Authentication Works**
|
|
35
|
+
```bash
|
|
36
|
+
snow-flow auth login
|
|
37
|
+
# 1. Opens ServiceNow OAuth consent screen in your browser
|
|
38
|
+
# 2. You authenticate with YOUR ServiceNow credentials
|
|
39
|
+
# 3. ServiceNow returns OAuth token directly to Snow-Flow
|
|
40
|
+
# 4. Token stored locally in ~/.snow-flow/auth.json (encrypted)
|
|
41
|
+
# 5. All API calls use this token with proper ServiceNow permissions
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### **Data Privacy & Security**
|
|
45
|
+
- ✅ **Zero data collection** - Snow-Flow doesn't collect or store your ServiceNow data
|
|
46
|
+
- ✅ **Local processing** - All operations happen on your machine
|
|
47
|
+
- ✅ **No external servers** - Direct ServiceNow ↔ Snow-Flow communication only
|
|
48
|
+
- ✅ **Audit compliance** - All actions logged in ServiceNow audit trails
|
|
49
|
+
- ✅ **Role-based access** - Respects your ServiceNow user permissions exactly
|
|
50
|
+
|
|
51
|
+
### **Network Architecture**
|
|
52
|
+
```
|
|
53
|
+
┌─────────────┐ OAuth 2.0 + REST APIs ┌─────────────────┐
|
|
54
|
+
│ Snow-Flow │ ◄─────────────────────────► │ Your ServiceNow │
|
|
55
|
+
│ (Local) │ HTTPS Only │ Instance │
|
|
56
|
+
└─────────────┘ └─────────────────┘
|
|
57
|
+
▲
|
|
58
|
+
│ No external connections
|
|
59
|
+
▼
|
|
60
|
+
┌─────────────┐
|
|
61
|
+
│ Claude Code │ ◄── Local AI processing only
|
|
62
|
+
│ (Local) │
|
|
63
|
+
└─────────────┘
|
|
64
|
+
```
|
|
65
|
+
|
|
25
66
|
## ✨ Core Capabilities
|
|
26
67
|
|
|
27
68
|
### 🤖 **Intelligent Multi-Agent System**
|
|
28
|
-
- **
|
|
69
|
+
- **38 Specialized Agents**: From architects to testers, each agent brings specific expertise
|
|
29
70
|
- **Swarm Coordination**: Agents work together using hierarchical, mesh, or adaptive topologies
|
|
30
71
|
- **Shared Memory**: Persistent knowledge base ensures consistency across all operations
|
|
31
72
|
- **Neural Learning**: Pattern recognition improves suggestions and automation over time
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hierarchical Memory System for Snow-Flow
|
|
3
|
+
* Extends base MemorySystem with ServiceNow-specific patterns
|
|
4
|
+
*/
|
|
5
|
+
import { MemorySystem, MemoryOptions } from './memory-system';
|
|
6
|
+
export interface HierarchicalMemoryEntry {
|
|
7
|
+
key: string;
|
|
8
|
+
value: any;
|
|
9
|
+
namespace: string;
|
|
10
|
+
type: string;
|
|
11
|
+
metadata?: {
|
|
12
|
+
created: string;
|
|
13
|
+
updated: string;
|
|
14
|
+
version: number;
|
|
15
|
+
tags: string[];
|
|
16
|
+
relationships?: Record<string, string[]>;
|
|
17
|
+
dependencies?: Record<string, string[]>;
|
|
18
|
+
};
|
|
19
|
+
ttl?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface MemorySearchOptions {
|
|
22
|
+
namespace?: string;
|
|
23
|
+
type?: string;
|
|
24
|
+
tags?: string[];
|
|
25
|
+
pattern?: string;
|
|
26
|
+
limit?: number;
|
|
27
|
+
includeExpired?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare class HierarchicalMemorySystem extends MemorySystem {
|
|
30
|
+
private namespaceIndex;
|
|
31
|
+
private typeIndex;
|
|
32
|
+
private tagIndex;
|
|
33
|
+
constructor(options: MemoryOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Initialize with enhanced tables for hierarchical storage
|
|
36
|
+
*/
|
|
37
|
+
initialize(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Create additional tables for hierarchical organization
|
|
40
|
+
*/
|
|
41
|
+
private createHierarchicalTables;
|
|
42
|
+
/**
|
|
43
|
+
* Store with hierarchical organization
|
|
44
|
+
*/
|
|
45
|
+
storeHierarchical(entry: Partial<HierarchicalMemoryEntry>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Get with full hierarchical metadata
|
|
48
|
+
*/
|
|
49
|
+
getHierarchical(key: string): Promise<HierarchicalMemoryEntry | null>;
|
|
50
|
+
/**
|
|
51
|
+
* Search with hierarchical patterns
|
|
52
|
+
*/
|
|
53
|
+
search(options: MemorySearchOptions): Promise<HierarchicalMemoryEntry[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Create relationship between entries
|
|
56
|
+
*/
|
|
57
|
+
createRelationship(sourceKey: string, targetKey: string, relationshipType: string, metadata?: any): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Get related entries
|
|
60
|
+
*/
|
|
61
|
+
getRelated(key: string, relationshipType?: string): Promise<HierarchicalMemoryEntry[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Associate memory with agent
|
|
64
|
+
*/
|
|
65
|
+
associateWithAgent(agentId: string, memoryKey: string, accessType: 'read' | 'write' | 'owner'): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Get agent's memory entries
|
|
68
|
+
*/
|
|
69
|
+
getAgentMemory(agentId: string, accessType?: string): Promise<HierarchicalMemoryEntry[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Track access pattern for learning
|
|
72
|
+
*/
|
|
73
|
+
trackAccessPattern(patternType: string, metadata?: any): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Get namespace statistics
|
|
76
|
+
*/
|
|
77
|
+
getNamespaceStats(): Promise<Record<string, number>>;
|
|
78
|
+
/**
|
|
79
|
+
* Helper methods
|
|
80
|
+
*/
|
|
81
|
+
private updateTags;
|
|
82
|
+
private getTags;
|
|
83
|
+
private updateLocalIndexes;
|
|
84
|
+
private buildIndexes;
|
|
85
|
+
/**
|
|
86
|
+
* Cleanup expired entries
|
|
87
|
+
*/
|
|
88
|
+
cleanupExpired(): Promise<number>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=hierarchical-memory-system.d.ts.map
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Hierarchical Memory System for Snow-Flow
|
|
4
|
+
* Extends base MemorySystem with ServiceNow-specific patterns
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HierarchicalMemorySystem = void 0;
|
|
8
|
+
const memory_system_1 = require("./memory-system");
|
|
9
|
+
class HierarchicalMemorySystem extends memory_system_1.MemorySystem {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
super(options);
|
|
12
|
+
this.namespaceIndex = new Map();
|
|
13
|
+
this.typeIndex = new Map();
|
|
14
|
+
this.tagIndex = new Map();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Initialize with enhanced tables for hierarchical storage
|
|
18
|
+
*/
|
|
19
|
+
async initialize() {
|
|
20
|
+
await super.initialize();
|
|
21
|
+
await this.createHierarchicalTables();
|
|
22
|
+
await this.buildIndexes();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Create additional tables for hierarchical organization
|
|
26
|
+
*/
|
|
27
|
+
async createHierarchicalTables() {
|
|
28
|
+
const tables = [
|
|
29
|
+
// Enhanced memory store with namespace and type
|
|
30
|
+
`CREATE TABLE IF NOT EXISTS hierarchical_memory (
|
|
31
|
+
key TEXT PRIMARY KEY,
|
|
32
|
+
namespace TEXT NOT NULL,
|
|
33
|
+
type TEXT NOT NULL,
|
|
34
|
+
value TEXT NOT NULL,
|
|
35
|
+
metadata TEXT,
|
|
36
|
+
ttl INTEGER,
|
|
37
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now') * 1000),
|
|
38
|
+
updated_at INTEGER DEFAULT (strftime('%s', 'now') * 1000),
|
|
39
|
+
expires_at INTEGER,
|
|
40
|
+
version INTEGER DEFAULT 1
|
|
41
|
+
)`,
|
|
42
|
+
// Tag associations
|
|
43
|
+
`CREATE TABLE IF NOT EXISTS memory_tags (
|
|
44
|
+
key TEXT NOT NULL,
|
|
45
|
+
tag TEXT NOT NULL,
|
|
46
|
+
PRIMARY KEY (key, tag),
|
|
47
|
+
FOREIGN KEY (key) REFERENCES hierarchical_memory(key) ON DELETE CASCADE
|
|
48
|
+
)`,
|
|
49
|
+
// Relationships between memory entries
|
|
50
|
+
`CREATE TABLE IF NOT EXISTS memory_relationships (
|
|
51
|
+
source_key TEXT NOT NULL,
|
|
52
|
+
target_key TEXT NOT NULL,
|
|
53
|
+
relationship_type TEXT NOT NULL,
|
|
54
|
+
metadata TEXT,
|
|
55
|
+
created_at INTEGER DEFAULT (strftime('%s', 'now') * 1000),
|
|
56
|
+
PRIMARY KEY (source_key, target_key, relationship_type),
|
|
57
|
+
FOREIGN KEY (source_key) REFERENCES hierarchical_memory(key) ON DELETE CASCADE,
|
|
58
|
+
FOREIGN KEY (target_key) REFERENCES hierarchical_memory(key) ON DELETE CASCADE
|
|
59
|
+
)`,
|
|
60
|
+
// Agent memory associations
|
|
61
|
+
`CREATE TABLE IF NOT EXISTS agent_memory (
|
|
62
|
+
agent_id TEXT NOT NULL,
|
|
63
|
+
memory_key TEXT NOT NULL,
|
|
64
|
+
access_type TEXT NOT NULL, -- 'read', 'write', 'owner'
|
|
65
|
+
accessed_at INTEGER DEFAULT (strftime('%s', 'now') * 1000),
|
|
66
|
+
PRIMARY KEY (agent_id, memory_key),
|
|
67
|
+
FOREIGN KEY (memory_key) REFERENCES hierarchical_memory(key) ON DELETE CASCADE
|
|
68
|
+
)`,
|
|
69
|
+
// Memory access patterns for learning
|
|
70
|
+
`CREATE TABLE IF NOT EXISTS memory_access_patterns (
|
|
71
|
+
pattern_id TEXT PRIMARY KEY,
|
|
72
|
+
pattern_type TEXT NOT NULL,
|
|
73
|
+
frequency INTEGER DEFAULT 1,
|
|
74
|
+
last_accessed INTEGER DEFAULT (strftime('%s', 'now') * 1000),
|
|
75
|
+
metadata TEXT
|
|
76
|
+
)`,
|
|
77
|
+
];
|
|
78
|
+
for (const table of tables) {
|
|
79
|
+
await this.execute(table);
|
|
80
|
+
}
|
|
81
|
+
// Create indexes for performance
|
|
82
|
+
const indexes = [
|
|
83
|
+
'CREATE INDEX IF NOT EXISTS idx_namespace ON hierarchical_memory(namespace)',
|
|
84
|
+
'CREATE INDEX IF NOT EXISTS idx_type ON hierarchical_memory(type)',
|
|
85
|
+
'CREATE INDEX IF NOT EXISTS idx_expires ON hierarchical_memory(expires_at)',
|
|
86
|
+
'CREATE INDEX IF NOT EXISTS idx_tags ON memory_tags(tag)',
|
|
87
|
+
'CREATE INDEX IF NOT EXISTS idx_relationships ON memory_relationships(relationship_type)',
|
|
88
|
+
'CREATE INDEX IF NOT EXISTS idx_agent_memory ON agent_memory(agent_id)',
|
|
89
|
+
];
|
|
90
|
+
for (const index of indexes) {
|
|
91
|
+
await this.execute(index);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Store with hierarchical organization
|
|
96
|
+
*/
|
|
97
|
+
async storeHierarchical(entry) {
|
|
98
|
+
if (!entry.key)
|
|
99
|
+
throw new Error('Key is required');
|
|
100
|
+
// Extract namespace and type from key pattern
|
|
101
|
+
const keyParts = entry.key.split('/');
|
|
102
|
+
const namespace = entry.namespace || keyParts[0] || 'default';
|
|
103
|
+
const type = entry.type || keyParts[1] || 'general';
|
|
104
|
+
const metadata = {
|
|
105
|
+
created: new Date().toISOString(),
|
|
106
|
+
updated: new Date().toISOString(),
|
|
107
|
+
version: 1,
|
|
108
|
+
tags: entry.metadata?.tags || [],
|
|
109
|
+
relationships: entry.metadata?.relationships || {},
|
|
110
|
+
dependencies: entry.metadata?.dependencies || {},
|
|
111
|
+
...entry.metadata,
|
|
112
|
+
};
|
|
113
|
+
const ttl = entry.ttl || 86400000 * 7; // 7 days default
|
|
114
|
+
const expiresAt = Date.now() + ttl;
|
|
115
|
+
// Check if exists for versioning
|
|
116
|
+
const existing = await this.getHierarchical(entry.key);
|
|
117
|
+
if (existing) {
|
|
118
|
+
metadata.version = (existing.metadata?.version || 0) + 1;
|
|
119
|
+
metadata.created = existing.metadata?.created || metadata.created;
|
|
120
|
+
}
|
|
121
|
+
// Store in hierarchical table
|
|
122
|
+
await this.execute(`
|
|
123
|
+
INSERT OR REPLACE INTO hierarchical_memory
|
|
124
|
+
(key, namespace, type, value, metadata, ttl, expires_at, version, updated_at)
|
|
125
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
126
|
+
`, [
|
|
127
|
+
entry.key,
|
|
128
|
+
namespace,
|
|
129
|
+
type,
|
|
130
|
+
JSON.stringify(entry.value),
|
|
131
|
+
JSON.stringify(metadata),
|
|
132
|
+
ttl,
|
|
133
|
+
expiresAt,
|
|
134
|
+
metadata.version,
|
|
135
|
+
Date.now()
|
|
136
|
+
]);
|
|
137
|
+
// Update tags
|
|
138
|
+
if (metadata.tags.length > 0) {
|
|
139
|
+
await this.updateTags(entry.key, metadata.tags);
|
|
140
|
+
}
|
|
141
|
+
// Update indexes
|
|
142
|
+
this.updateLocalIndexes(entry.key, namespace, type, metadata.tags);
|
|
143
|
+
// Store in base system for compatibility
|
|
144
|
+
await super.store(entry.key, entry.value, ttl);
|
|
145
|
+
this.emit('memory:hierarchical:stored', { key: entry.key, namespace, type });
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get with full hierarchical metadata
|
|
149
|
+
*/
|
|
150
|
+
async getHierarchical(key) {
|
|
151
|
+
const result = await this.query(`
|
|
152
|
+
SELECT * FROM hierarchical_memory
|
|
153
|
+
WHERE key = ? AND expires_at > ?
|
|
154
|
+
`, [key, Date.now()]);
|
|
155
|
+
if (!result || result.length === 0)
|
|
156
|
+
return null;
|
|
157
|
+
const row = result[0];
|
|
158
|
+
const tags = await this.getTags(key);
|
|
159
|
+
return {
|
|
160
|
+
key: row.key,
|
|
161
|
+
namespace: row.namespace,
|
|
162
|
+
type: row.type,
|
|
163
|
+
value: JSON.parse(row.value),
|
|
164
|
+
metadata: {
|
|
165
|
+
...JSON.parse(row.metadata || '{}'),
|
|
166
|
+
tags,
|
|
167
|
+
},
|
|
168
|
+
ttl: row.ttl,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Search with hierarchical patterns
|
|
173
|
+
*/
|
|
174
|
+
async search(options) {
|
|
175
|
+
let sql = 'SELECT DISTINCT h.* FROM hierarchical_memory h';
|
|
176
|
+
const params = [];
|
|
177
|
+
const conditions = [];
|
|
178
|
+
// Join with tags if needed
|
|
179
|
+
if (options.tags && options.tags.length > 0) {
|
|
180
|
+
sql += ' INNER JOIN memory_tags t ON h.key = t.key';
|
|
181
|
+
conditions.push(`t.tag IN (${options.tags.map(() => '?').join(',')})`);
|
|
182
|
+
params.push(...options.tags);
|
|
183
|
+
}
|
|
184
|
+
// Add namespace filter
|
|
185
|
+
if (options.namespace) {
|
|
186
|
+
conditions.push('h.namespace = ?');
|
|
187
|
+
params.push(options.namespace);
|
|
188
|
+
}
|
|
189
|
+
// Add type filter
|
|
190
|
+
if (options.type) {
|
|
191
|
+
conditions.push('h.type = ?');
|
|
192
|
+
params.push(options.type);
|
|
193
|
+
}
|
|
194
|
+
// Add pattern matching
|
|
195
|
+
if (options.pattern) {
|
|
196
|
+
conditions.push('h.key LIKE ?');
|
|
197
|
+
params.push(`%${options.pattern}%`);
|
|
198
|
+
}
|
|
199
|
+
// Add expiration filter
|
|
200
|
+
if (!options.includeExpired) {
|
|
201
|
+
conditions.push('h.expires_at > ?');
|
|
202
|
+
params.push(Date.now());
|
|
203
|
+
}
|
|
204
|
+
// Combine conditions
|
|
205
|
+
if (conditions.length > 0) {
|
|
206
|
+
sql += ' WHERE ' + conditions.join(' AND ');
|
|
207
|
+
}
|
|
208
|
+
// Add ordering and limit
|
|
209
|
+
sql += ' ORDER BY h.updated_at DESC';
|
|
210
|
+
if (options.limit) {
|
|
211
|
+
sql += ' LIMIT ?';
|
|
212
|
+
params.push(options.limit);
|
|
213
|
+
}
|
|
214
|
+
const results = await this.query(sql, params);
|
|
215
|
+
// Fetch tags and format results
|
|
216
|
+
const entries = [];
|
|
217
|
+
for (const row of results) {
|
|
218
|
+
const tags = await this.getTags(row.key);
|
|
219
|
+
entries.push({
|
|
220
|
+
key: row.key,
|
|
221
|
+
namespace: row.namespace,
|
|
222
|
+
type: row.type,
|
|
223
|
+
value: JSON.parse(row.value),
|
|
224
|
+
metadata: {
|
|
225
|
+
...JSON.parse(row.metadata || '{}'),
|
|
226
|
+
tags,
|
|
227
|
+
},
|
|
228
|
+
ttl: row.ttl,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return entries;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Create relationship between entries
|
|
235
|
+
*/
|
|
236
|
+
async createRelationship(sourceKey, targetKey, relationshipType, metadata) {
|
|
237
|
+
await this.execute(`
|
|
238
|
+
INSERT OR REPLACE INTO memory_relationships
|
|
239
|
+
(source_key, target_key, relationship_type, metadata)
|
|
240
|
+
VALUES (?, ?, ?, ?)
|
|
241
|
+
`, [sourceKey, targetKey, relationshipType, JSON.stringify(metadata || {})]);
|
|
242
|
+
this.emit('memory:relationship:created', { sourceKey, targetKey, relationshipType });
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Get related entries
|
|
246
|
+
*/
|
|
247
|
+
async getRelated(key, relationshipType) {
|
|
248
|
+
let sql = `
|
|
249
|
+
SELECT DISTINCT h.*
|
|
250
|
+
FROM hierarchical_memory h
|
|
251
|
+
INNER JOIN memory_relationships r ON (h.key = r.target_key OR h.key = r.source_key)
|
|
252
|
+
WHERE (r.source_key = ? OR r.target_key = ?) AND h.key != ?
|
|
253
|
+
`;
|
|
254
|
+
const params = [key, key, key];
|
|
255
|
+
if (relationshipType) {
|
|
256
|
+
sql += ' AND r.relationship_type = ?';
|
|
257
|
+
params.push(relationshipType);
|
|
258
|
+
}
|
|
259
|
+
const results = await this.query(sql, params);
|
|
260
|
+
const entries = [];
|
|
261
|
+
for (const row of results) {
|
|
262
|
+
const entry = await this.getHierarchical(row.key);
|
|
263
|
+
if (entry)
|
|
264
|
+
entries.push(entry);
|
|
265
|
+
}
|
|
266
|
+
return entries;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Associate memory with agent
|
|
270
|
+
*/
|
|
271
|
+
async associateWithAgent(agentId, memoryKey, accessType) {
|
|
272
|
+
await this.execute(`
|
|
273
|
+
INSERT OR REPLACE INTO agent_memory (agent_id, memory_key, access_type)
|
|
274
|
+
VALUES (?, ?, ?)
|
|
275
|
+
`, [agentId, memoryKey, accessType]);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get agent's memory entries
|
|
279
|
+
*/
|
|
280
|
+
async getAgentMemory(agentId, accessType) {
|
|
281
|
+
let sql = `
|
|
282
|
+
SELECT h.* FROM hierarchical_memory h
|
|
283
|
+
INNER JOIN agent_memory a ON h.key = a.memory_key
|
|
284
|
+
WHERE a.agent_id = ?
|
|
285
|
+
`;
|
|
286
|
+
const params = [agentId];
|
|
287
|
+
if (accessType) {
|
|
288
|
+
sql += ' AND a.access_type = ?';
|
|
289
|
+
params.push(accessType);
|
|
290
|
+
}
|
|
291
|
+
const results = await this.query(sql, params);
|
|
292
|
+
const entries = [];
|
|
293
|
+
for (const row of results) {
|
|
294
|
+
const entry = await this.getHierarchical(row.key);
|
|
295
|
+
if (entry)
|
|
296
|
+
entries.push(entry);
|
|
297
|
+
}
|
|
298
|
+
return entries;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Track access pattern for learning
|
|
302
|
+
*/
|
|
303
|
+
async trackAccessPattern(patternType, metadata) {
|
|
304
|
+
const patternId = `${patternType}_${Date.now()}`;
|
|
305
|
+
await this.execute(`
|
|
306
|
+
INSERT INTO memory_access_patterns (pattern_id, pattern_type, metadata)
|
|
307
|
+
VALUES (?, ?, ?)
|
|
308
|
+
ON CONFLICT(pattern_id) DO UPDATE SET
|
|
309
|
+
frequency = frequency + 1,
|
|
310
|
+
last_accessed = strftime('%s', 'now') * 1000
|
|
311
|
+
`, [patternId, patternType, JSON.stringify(metadata || {})]);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get namespace statistics
|
|
315
|
+
*/
|
|
316
|
+
async getNamespaceStats() {
|
|
317
|
+
const results = await this.query(`
|
|
318
|
+
SELECT namespace, COUNT(*) as count
|
|
319
|
+
FROM hierarchical_memory
|
|
320
|
+
WHERE expires_at > ?
|
|
321
|
+
GROUP BY namespace
|
|
322
|
+
`, [Date.now()]);
|
|
323
|
+
const stats = {};
|
|
324
|
+
for (const row of results) {
|
|
325
|
+
stats[row.namespace] = row.count;
|
|
326
|
+
}
|
|
327
|
+
return stats;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Helper methods
|
|
331
|
+
*/
|
|
332
|
+
async updateTags(key, tags) {
|
|
333
|
+
// Remove existing tags
|
|
334
|
+
await this.execute('DELETE FROM memory_tags WHERE key = ?', [key]);
|
|
335
|
+
// Insert new tags
|
|
336
|
+
for (const tag of tags) {
|
|
337
|
+
await this.execute('INSERT INTO memory_tags (key, tag) VALUES (?, ?)', [key, tag]);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
async getTags(key) {
|
|
341
|
+
const results = await this.query('SELECT tag FROM memory_tags WHERE key = ?', [key]);
|
|
342
|
+
return results.map(r => r.tag);
|
|
343
|
+
}
|
|
344
|
+
updateLocalIndexes(key, namespace, type, tags) {
|
|
345
|
+
// Update namespace index
|
|
346
|
+
if (!this.namespaceIndex.has(namespace)) {
|
|
347
|
+
this.namespaceIndex.set(namespace, new Set());
|
|
348
|
+
}
|
|
349
|
+
this.namespaceIndex.get(namespace).add(key);
|
|
350
|
+
// Update type index
|
|
351
|
+
if (!this.typeIndex.has(type)) {
|
|
352
|
+
this.typeIndex.set(type, new Set());
|
|
353
|
+
}
|
|
354
|
+
this.typeIndex.get(type).add(key);
|
|
355
|
+
// Update tag index
|
|
356
|
+
for (const tag of tags) {
|
|
357
|
+
if (!this.tagIndex.has(tag)) {
|
|
358
|
+
this.tagIndex.set(tag, new Set());
|
|
359
|
+
}
|
|
360
|
+
this.tagIndex.get(tag).add(key);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
async buildIndexes() {
|
|
364
|
+
// Build indexes from existing data
|
|
365
|
+
const results = await this.query(`
|
|
366
|
+
SELECT key, namespace, type FROM hierarchical_memory
|
|
367
|
+
WHERE expires_at > ?
|
|
368
|
+
`, [Date.now()]);
|
|
369
|
+
for (const row of results) {
|
|
370
|
+
const tags = await this.getTags(row.key);
|
|
371
|
+
this.updateLocalIndexes(row.key, row.namespace, row.type, tags);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Cleanup expired entries
|
|
376
|
+
*/
|
|
377
|
+
async cleanupExpired() {
|
|
378
|
+
const result = await this.query(`
|
|
379
|
+
DELETE FROM hierarchical_memory
|
|
380
|
+
WHERE expires_at <= ?
|
|
381
|
+
RETURNING key
|
|
382
|
+
`, [Date.now()]);
|
|
383
|
+
// Update local indexes
|
|
384
|
+
for (const row of result) {
|
|
385
|
+
// Remove from indexes
|
|
386
|
+
for (const [namespace, keys] of this.namespaceIndex) {
|
|
387
|
+
keys.delete(row.key);
|
|
388
|
+
}
|
|
389
|
+
for (const [type, keys] of this.typeIndex) {
|
|
390
|
+
keys.delete(row.key);
|
|
391
|
+
}
|
|
392
|
+
for (const [tag, keys] of this.tagIndex) {
|
|
393
|
+
keys.delete(row.key);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return result.length;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
exports.HierarchicalMemorySystem = HierarchicalMemorySystem;
|
|
400
|
+
//# sourceMappingURL=hierarchical-memory-system.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snow-Flow Memory System Exports
|
|
3
|
+
* Centralized exports for the SQLite memory system
|
|
4
|
+
*/
|
|
5
|
+
export { SwarmMemory, SwarmMemoryConfig, AgentCoordination, ServiceNowArtifactRecord, AgentMessage, SharedContext, DeploymentHistory, AgentDependency, PerformanceMetric } from './swarm-memory.js';
|
|
6
|
+
export { MemoryOperations, AgentCoordinationUpdate, ArtifactSearchOptions, MessageSearchOptions, PerformanceQuery } from './memory-operations.js';
|
|
7
|
+
export { MemoryClient, MemoryClientConfig, MemoryStoreOptions, MemoryRetrieveOptions, ArtifactInfo, AgentHandoff, PerformanceTracker } from './memory-client.js';
|
|
8
|
+
export { ServiceNowArtifactIndexer, ServiceNowArtifact, FlowArtifact, WidgetArtifact, IndexedArtifact, ArtifactStructure, ArtifactContext, ArtifactRelationships, ModificationPoint, EditHistory } from './servicenow-artifact-indexer.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Snow-Flow Memory System Exports
|
|
4
|
+
* Centralized exports for the SQLite memory system
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.ServiceNowArtifactIndexer = exports.MemoryClient = exports.MemoryOperations = exports.SwarmMemory = void 0;
|
|
8
|
+
// Core memory system
|
|
9
|
+
var swarm_memory_js_1 = require("./swarm-memory.js");
|
|
10
|
+
Object.defineProperty(exports, "SwarmMemory", { enumerable: true, get: function () { return swarm_memory_js_1.SwarmMemory; } });
|
|
11
|
+
// Memory operations
|
|
12
|
+
var memory_operations_js_1 = require("./memory-operations.js");
|
|
13
|
+
Object.defineProperty(exports, "MemoryOperations", { enumerable: true, get: function () { return memory_operations_js_1.MemoryOperations; } });
|
|
14
|
+
// Memory client API
|
|
15
|
+
var memory_client_js_1 = require("./memory-client.js");
|
|
16
|
+
Object.defineProperty(exports, "MemoryClient", { enumerable: true, get: function () { return memory_client_js_1.MemoryClient; } });
|
|
17
|
+
// Existing artifact indexer (for compatibility)
|
|
18
|
+
var servicenow_artifact_indexer_js_1 = require("./servicenow-artifact-indexer.js");
|
|
19
|
+
Object.defineProperty(exports, "ServiceNowArtifactIndexer", { enumerable: true, get: function () { return servicenow_artifact_indexer_js_1.ServiceNowArtifactIndexer; } });
|
|
20
|
+
//# sourceMappingURL=index.js.map
|