snow-flow 3.0.9 โ†’ 3.0.10

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 (294) hide show
  1. package/claude-flow.bat +0 -0
  2. package/claude-flow.ps1 +0 -0
  3. package/dist/mcp/servicenow-automation-mcp.js +0 -0
  4. package/dist/mcp/servicenow-deployment-mcp.js +0 -0
  5. package/dist/mcp/servicenow-integration-mcp.js +0 -0
  6. package/dist/mcp/servicenow-mcp-server.js +0 -0
  7. package/dist/mcp/servicenow-operations-mcp.js +0 -0
  8. package/dist/mcp/servicenow-platform-development-mcp.js +0 -0
  9. package/dist/mcp/servicenow-progressive-indexer.js +0 -0
  10. package/dist/mcp/servicenow-reporting-analytics-mcp.js +133 -19
  11. package/dist/mcp/servicenow-security-compliance-mcp.js +0 -0
  12. package/dist/mcp/servicenow-update-set-mcp.js +0 -0
  13. package/dist/mcp/start-all-mcp-servers.js +0 -0
  14. package/dist/mcp/start-servicenow-mcp.js +0 -0
  15. package/memory/agents/README.md +1 -1
  16. package/memory/claude-flow-data.json +1 -1
  17. package/memory/sessions/README.md +1 -1
  18. package/package.json +2 -2
  19. package/.mcp.json +0 -22
  20. package/claude-flow.config.json +0 -20
  21. package/dist/agents/app-creator.agent.d.ts +0 -55
  22. package/dist/agents/app-creator.agent.js +0 -1292
  23. package/dist/agents/base/base-snow-agent.d.ts +0 -75
  24. package/dist/agents/base/base-snow-agent.js +0 -169
  25. package/dist/agents/base-snow-agent.d.ts +0 -63
  26. package/dist/agents/base-snow-agent.js +0 -296
  27. package/dist/agents/coordinator.d.ts +0 -200
  28. package/dist/agents/coordinator.js +0 -777
  29. package/dist/agents/flow-builder-agent.d.ts +0 -18
  30. package/dist/agents/flow-builder-agent.js +0 -197
  31. package/dist/agents/queen-403-handler.d.ts +0 -47
  32. package/dist/agents/queen-403-handler.js +0 -175
  33. package/dist/agents/queen-agent-example.d.ts +0 -23
  34. package/dist/agents/queen-agent-example.js +0 -240
  35. package/dist/agents/queen-agent.test.d.ts +0 -6
  36. package/dist/agents/script-generator.agent.d.ts +0 -32
  37. package/dist/agents/script-generator.agent.js +0 -772
  38. package/dist/agents/script-writer-agent.d.ts +0 -22
  39. package/dist/agents/script-writer-agent.js +0 -695
  40. package/dist/agents/security-agent.d.ts +0 -23
  41. package/dist/agents/security-agent.js +0 -619
  42. package/dist/agents/specialists/automation-specialist.agent.d.ts +0 -44
  43. package/dist/agents/specialists/automation-specialist.agent.js +0 -204
  44. package/dist/agents/specialists/data-specialist.agent.d.ts +0 -165
  45. package/dist/agents/specialists/data-specialist.agent.js +0 -484
  46. package/dist/agents/specialists/integration-specialist.agent.d.ts +0 -227
  47. package/dist/agents/specialists/integration-specialist.agent.js +0 -725
  48. package/dist/agents/specialists/reporting-specialist.agent.d.ts +0 -54
  49. package/dist/agents/specialists/reporting-specialist.agent.js +0 -193
  50. package/dist/agents/specialists/security-specialist.agent.d.ts +0 -85
  51. package/dist/agents/specialists/security-specialist.agent.js +0 -309
  52. package/dist/agents/teams/adaptive/adaptive-coordinator.agent.d.ts +0 -111
  53. package/dist/agents/teams/adaptive/adaptive-coordinator.agent.js +0 -383
  54. package/dist/agents/teams/base-team.d.ts +0 -72
  55. package/dist/agents/teams/base-team.js +0 -253
  56. package/dist/agents/teams/team-types.d.ts +0 -265
  57. package/dist/agents/teams/team-types.js +0 -3
  58. package/dist/agents/teams/widget/widget-architect.agent.d.ts +0 -61
  59. package/dist/agents/teams/widget/widget-architect.agent.js +0 -436
  60. package/dist/agents/teams/widget/widget-backend.agent.d.ts +0 -74
  61. package/dist/agents/teams/widget/widget-backend.agent.js +0 -1531
  62. package/dist/agents/teams/widget/widget-frontend.agent.d.ts +0 -67
  63. package/dist/agents/teams/widget/widget-frontend.agent.js +0 -1014
  64. package/dist/agents/teams/widget/widget-platform.agent.d.ts +0 -90
  65. package/dist/agents/teams/widget/widget-platform.agent.js +0 -1190
  66. package/dist/agents/teams/widget/widget-uiux.agent.d.ts +0 -107
  67. package/dist/agents/teams/widget/widget-uiux.agent.js +0 -1033
  68. package/dist/agents/test-agent.d.ts +0 -26
  69. package/dist/agents/test-agent.js +0 -734
  70. package/dist/agents/test-agents.d.ts +0 -7
  71. package/dist/agents/test-agents.js +0 -64
  72. package/dist/agents/ui-builder.agent.d.ts +0 -50
  73. package/dist/agents/ui-builder.agent.js +0 -1539
  74. package/dist/agents/widget-builder.agent.d.ts +0 -32
  75. package/dist/agents/widget-builder.agent.js +0 -439
  76. package/dist/agents/widget-creator-agent.d.ts +0 -18
  77. package/dist/agents/widget-creator-agent.js +0 -498
  78. package/dist/agents/workflow-designer.agent.d.ts +0 -31
  79. package/dist/agents/workflow-designer.agent.js +0 -583
  80. package/dist/api/error-handling.d.ts +0 -325
  81. package/dist/api/error-handling.js +0 -1488
  82. package/dist/api/flow-designer-api.d.ts +0 -167
  83. package/dist/api/flow-designer-api.js +0 -554
  84. package/dist/api/natural-language-mapper.d.ts +0 -124
  85. package/dist/api/natural-language-mapper.js +0 -501
  86. package/dist/api/performance-optimizer.d.ts +0 -240
  87. package/dist/api/performance-optimizer.js +0 -706
  88. package/dist/api/transaction-manager.d.ts +0 -189
  89. package/dist/api/transaction-manager.js +0 -576
  90. package/dist/assembly/team-assembler.d.ts +0 -140
  91. package/dist/assembly/team-assembler.js +0 -502
  92. package/dist/benchmark-performance.d.ts +0 -41
  93. package/dist/benchmark-performance.js +0 -230
  94. package/dist/cli/snow-flow-cli-integration.d.ts +0 -30
  95. package/dist/cli/snow-flow-cli-integration.js +0 -396
  96. package/dist/coordination/coordination-engine.d.ts +0 -41
  97. package/dist/coordination/coordination-engine.js +0 -324
  98. package/dist/coordination/coordination.test.d.ts +0 -6
  99. package/dist/coordination/example.d.ts +0 -31
  100. package/dist/coordination/example.js +0 -394
  101. package/dist/coordination/execution-patterns.d.ts +0 -43
  102. package/dist/coordination/execution-patterns.js +0 -507
  103. package/dist/coordination/factory.d.ts +0 -94
  104. package/dist/coordination/factory.js +0 -433
  105. package/dist/coordination/index.d.ts +0 -71
  106. package/dist/coordination/index.js +0 -135
  107. package/dist/coordination/progress-monitor.d.ts +0 -71
  108. package/dist/coordination/progress-monitor.js +0 -505
  109. package/dist/coordination/quality-gates.d.ts +0 -124
  110. package/dist/coordination/quality-gates.js +0 -577
  111. package/dist/coordination/shared-memory.d.ts +0 -39
  112. package/dist/coordination/shared-memory.js +0 -289
  113. package/dist/coordination/task-dependencies.d.ts +0 -50
  114. package/dist/coordination/task-dependencies.js +0 -407
  115. package/dist/coordination/team-coordinator.d.ts +0 -59
  116. package/dist/coordination/team-coordinator.js +0 -550
  117. package/dist/coordination/types.d.ts +0 -152
  118. package/dist/coordination/types.js +0 -3
  119. package/dist/mcp/mcp-wrapper.d.ts +0 -8
  120. package/dist/mcp/mcp-wrapper.js +0 -77
  121. package/dist/mcp/servicenow-flow-composer-enhanced.js +0 -396
  122. package/dist/mcp/servicenow-flow-composer-mcp.d.ts +0 -7
  123. package/dist/mcp/servicenow-flow-composer-mcp.js +0 -3103
  124. package/dist/mcp/servicenow-graph-memory-mcp.d.ts +0 -7
  125. package/dist/mcp/servicenow-intelligent-mcp.d.ts +0 -143
  126. package/dist/mcp/servicenow-intelligent-mcp.js +0 -4156
  127. package/dist/mcp/servicenow-xml-flow-mcp.d.ts +0 -53
  128. package/dist/mcp/servicenow-xml-flow-mcp.js +0 -1704
  129. package/dist/mcp/singleton-check.js +0 -31
  130. package/dist/mcp/test-simple-mcp.d.ts +0 -6
  131. package/dist/mcp/test-simple-mcp.js +0 -63
  132. package/dist/memory/hierarchical-memory-system.d.ts +0 -90
  133. package/dist/memory/hierarchical-memory-system.js +0 -400
  134. package/dist/memory/index.d.ts +0 -9
  135. package/dist/memory/index.js +0 -20
  136. package/dist/memory/mcp-integration-example.d.ts +0 -6
  137. package/dist/memory/mcp-integration-example.js +0 -281
  138. package/dist/memory/memory-client.d.ts +0 -199
  139. package/dist/memory/memory-client.js +0 -364
  140. package/dist/memory/memory-manager.d.ts +0 -29
  141. package/dist/memory/memory-manager.js +0 -280
  142. package/dist/memory/memory-operations.d.ts +0 -179
  143. package/dist/memory/memory-operations.js +0 -691
  144. package/dist/memory/memory-system.d.ts +0 -153
  145. package/dist/memory/memory-system.js +0 -651
  146. package/dist/memory/memory-test.d.ts +0 -6
  147. package/dist/memory/memory-test.js +0 -161
  148. package/dist/memory/snow-flow-memory-patterns.d.ts +0 -213
  149. package/dist/memory/snow-flow-memory-patterns.js +0 -200
  150. package/dist/memory/snow-memory.d.ts +0 -54
  151. package/dist/memory/snow-memory.js +0 -301
  152. package/dist/memory/swarm-memory.d.ts +0 -135
  153. package/dist/memory/swarm-memory.js +0 -378
  154. package/dist/optimization/flow-performance-optimizer.js +0 -723
  155. package/dist/orchestration/discovery/service-discovery.d.ts +0 -81
  156. package/dist/orchestration/discovery/service-discovery.js +0 -808
  157. package/dist/orchestration/distributed-orchestrator.d.ts +0 -131
  158. package/dist/orchestration/distributed-orchestrator.js +0 -712
  159. package/dist/orchestration/distribution/task-distribution-engine.d.ts +0 -53
  160. package/dist/orchestration/distribution/task-distribution-engine.js +0 -586
  161. package/dist/orchestration/flow-update-orchestrator.js +0 -648
  162. package/dist/orchestration/interfaces/distributed-orchestration.interface.d.ts +0 -606
  163. package/dist/orchestration/interfaces/distributed-orchestration.interface.js +0 -65
  164. package/dist/orchestration/protocols/mcpx-protocol.d.ts +0 -71
  165. package/dist/orchestration/protocols/mcpx-protocol.js +0 -668
  166. package/dist/orchestration/state/distributed-state-manager.d.ts +0 -89
  167. package/dist/orchestration/state/distributed-state-manager.js +0 -716
  168. package/dist/orchestrator/flow-composer.d.ts +0 -105
  169. package/dist/orchestrator/flow-composer.js +0 -404
  170. package/dist/orchestrator/flow-pattern-templates.d.ts +0 -260
  171. package/dist/orchestrator/flow-pattern-templates.js +0 -908
  172. package/dist/orchestrator/flow-subflow-decision-engine.d.ts +0 -202
  173. package/dist/orchestrator/flow-subflow-decision-engine.js +0 -769
  174. package/dist/orchestrator/flow-validation-engine.d.ts +0 -169
  175. package/dist/orchestrator/flow-validation-engine.js +0 -913
  176. package/dist/orchestrator/snow-orchestrator.d.ts +0 -49
  177. package/dist/orchestrator/snow-orchestrator.js +0 -235
  178. package/dist/orchestrator/subflow-creation-handler.d.ts +0 -230
  179. package/dist/orchestrator/subflow-creation-handler.js +0 -791
  180. package/dist/patterns/adaptive-patterns.d.ts +0 -140
  181. package/dist/patterns/adaptive-patterns.js +0 -549
  182. package/dist/queen/advanced-integration-test.d.ts +0 -48
  183. package/dist/queen/advanced-integration-test.js +0 -473
  184. package/dist/queen/integration-example.d.ts +0 -82
  185. package/dist/queen/integration-example.js +0 -219
  186. package/dist/queen/integration-test.d.ts +0 -72
  187. package/dist/queen/integration-test.js +0 -563
  188. package/dist/queen/mock-mcp-client.d.ts +0 -71
  189. package/dist/queen/mock-mcp-client.js +0 -317
  190. package/dist/queen/run-integration-tests.d.ts +0 -9
  191. package/dist/queen/run-integration-tests.js +0 -27
  192. package/dist/sparc/coordinators/adaptive-coordinator.d.ts +0 -54
  193. package/dist/sparc/coordinators/adaptive-coordinator.js +0 -367
  194. package/dist/sparc/coordinators/team-coordinator.d.ts +0 -66
  195. package/dist/sparc/coordinators/team-coordinator.js +0 -402
  196. package/dist/sparc/modes/team-modes.d.ts +0 -33
  197. package/dist/sparc/modes/team-modes.js +0 -399
  198. package/dist/sparc/teams/application-team.d.ts +0 -73
  199. package/dist/sparc/teams/application-team.js +0 -463
  200. package/dist/sparc/teams/flow-team.d.ts +0 -67
  201. package/dist/sparc/teams/flow-team.js +0 -373
  202. package/dist/sparc/teams/widget-team.d.ts +0 -61
  203. package/dist/sparc/teams/widget-team.js +0 -280
  204. package/dist/specialists/app-specialists.d.ts +0 -93
  205. package/dist/specialists/app-specialists.js +0 -1639
  206. package/dist/specialists/base-specialist.d.ts +0 -19
  207. package/dist/specialists/base-specialist.js +0 -54
  208. package/dist/specialists/flow-specialists.d.ts +0 -113
  209. package/dist/specialists/flow-specialists.js +0 -1787
  210. package/dist/specialists/individual-specialists.d.ts +0 -67
  211. package/dist/specialists/individual-specialists.js +0 -632
  212. package/dist/specialists/widget-specialists.d.ts +0 -70
  213. package/dist/specialists/widget-specialists.js +0 -1264
  214. package/dist/src/utils/agent-detector.js +0 -655
  215. package/dist/teams/adaptive-team.d.ts +0 -81
  216. package/dist/teams/adaptive-team.js +0 -1153
  217. package/dist/teams/application-team.d.ts +0 -30
  218. package/dist/teams/application-team.js +0 -547
  219. package/dist/teams/base-team.d.ts +0 -55
  220. package/dist/teams/base-team.js +0 -243
  221. package/dist/teams/flow-team.d.ts +0 -28
  222. package/dist/teams/flow-team.js +0 -525
  223. package/dist/teams/widget-team.d.ts +0 -26
  224. package/dist/teams/widget-team.js +0 -459
  225. package/dist/templates/flow-template-system.js +0 -625
  226. package/dist/test-fetch-incidents.d.ts +0 -2
  227. package/dist/test-fetch-incidents.js +0 -84
  228. package/dist/test-incident-access.d.ts +0 -2
  229. package/dist/test-incident-access.js +0 -72
  230. package/dist/test-iphone-flow.js +0 -189
  231. package/dist/test-limit-problem.d.ts +0 -2
  232. package/dist/test-limit-problem.js +0 -60
  233. package/dist/test-ml-batch-fix.d.ts +0 -2
  234. package/dist/test-ml-batch-fix.js +0 -104
  235. package/dist/test-ml-batch.d.ts +0 -2
  236. package/dist/test-ml-batch.js +0 -87
  237. package/dist/test-ml-query.d.ts +0 -2
  238. package/dist/test-ml-query.js +0 -100
  239. package/dist/test-ml-training-fix.d.ts +0 -12
  240. package/dist/test-ml-training-fix.js +0 -113
  241. package/dist/test-ml-training.d.ts +0 -2
  242. package/dist/test-ml-training.js +0 -32
  243. package/dist/test-operations-query.d.ts +0 -2
  244. package/dist/test-operations-query.js +0 -84
  245. package/dist/test-performance-query.d.ts +0 -2
  246. package/dist/test-performance-query.js +0 -52
  247. package/dist/test-singleton-protection.d.ts +0 -8
  248. package/dist/test-singleton-protection.js +0 -110
  249. package/dist/test-smart-limits.d.ts +0 -13
  250. package/dist/test-smart-limits.js +0 -100
  251. package/dist/test-snow-query-incidents.d.ts +0 -2
  252. package/dist/test-snow-query-incidents.js +0 -66
  253. package/dist/test-universal-query.d.ts +0 -2
  254. package/dist/test-universal-query.js +0 -106
  255. package/dist/testing/flow-testing-automation.js +0 -641
  256. package/dist/utils/complete-flow-xml-generator.js +0 -1285
  257. package/dist/utils/file-storage-fallback.d.ts +0 -62
  258. package/dist/utils/file-storage-fallback.js +0 -289
  259. package/dist/utils/flow-api-discovery.d.ts +0 -151
  260. package/dist/utils/flow-api-discovery.js +0 -439
  261. package/dist/utils/flow-examples.js +0 -720
  262. package/dist/utils/flow-structure-builder.js +0 -677
  263. package/dist/utils/flow-xml-generator.d.ts +0 -41
  264. package/dist/utils/flow-xml-generator.js +0 -258
  265. package/dist/utils/improved-flow-xml-generator.js +0 -820
  266. package/dist/utils/mcp-process-manager.backup.d.ts +0 -58
  267. package/dist/utils/mcp-process-manager.backup.js +0 -220
  268. package/dist/utils/mcp-singleton-enforcer.d.ts +0 -36
  269. package/dist/utils/mcp-singleton-enforcer.js +0 -201
  270. package/dist/utils/mcp-timeout-fix.d.ts +0 -53
  271. package/dist/utils/mcp-timeout-fix.js +0 -221
  272. package/dist/utils/migrate-claude-flow.d.ts +0 -22
  273. package/dist/utils/migrate-claude-flow.js +0 -120
  274. package/dist/utils/scope-utils.d.ts +0 -72
  275. package/dist/utils/scope-utils.js +0 -386
  276. package/dist/utils/snow-oauth-old.d.ts +0 -65
  277. package/dist/utils/snow-oauth-old.js +0 -345
  278. package/dist/utils/xml-first-flow-generator.js +0 -513
  279. package/memory/servicenow_artifacts/000d9224c895221055906c7518aa2d3d.json +0 -30
  280. package/memory/servicenow_artifacts/0196b66173303010e46b4a2214f6a7a2.json +0 -36
  281. package/memory/servicenow_artifacts/125e5d1d837e2a102a7ea130ceaad397.json +0 -30
  282. package/memory/servicenow_artifacts/7637c1f2b7112210a5e5911cde11a972.json +0 -30
  283. package/memory/servicenow_artifacts/default_documentation_tables_1754056582292.json +0 -55
  284. package/memory/servicenow_artifacts/default_documentation_tables_1754057477189.json +0 -55
  285. package/memory/update-set-sessions/01f82af583faea102a7ea130ceaad3d4.json +0 -9
  286. package/memory/update-set-sessions/27718fb983faea102a7ea130ceaad34b.json +0 -9
  287. package/memory/update-set-sessions/412e9bf6833e22502a7ea130ceaad30a.json +0 -8
  288. package/memory/update-set-sessions/66fc5a79837aea102a7ea130ceaad3ab.json +0 -9
  289. package/memory/update-set-sessions/71a30ff5837eea102a7ea130ceaad37f.json +0 -9
  290. package/memory/update-set-sessions/74fba27983faea102a7ea130ceaad3bd.json +0 -9
  291. package/memory/update-set-sessions/a0b147b5837eea102a7ea130ceaad344.json +0 -58
  292. package/memory/update-set-sessions/b13f5eb983baea102a7ea130ceaad33e.json +0 -9
  293. package/reports/swarm-auto-centralized-1752649029776.json +0 -13
  294. package/src/memory/README.md +0 -240
@@ -1,651 +0,0 @@
1
- "use strict";
2
- /**
3
- * Snow-Flow Memory System
4
- * SQLite-based persistent memory with caching for agent coordination
5
- */
6
- var __importDefault = (this && this.__importDefault) || function (mod) {
7
- return (mod && mod.__esModule) ? mod : { "default": mod };
8
- };
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.MemorySystem = void 0;
11
- const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
12
- const events_1 = require("events");
13
- const path_1 = __importDefault(require("path"));
14
- const fs_1 = __importDefault(require("fs"));
15
- const logger_1 = require("../utils/logger");
16
- class MemorySystem extends events_1.EventEmitter {
17
- constructor(options) {
18
- super();
19
- this.cache = new Map();
20
- this.cacheStats = { hits: 0, misses: 0, size: 0, evictions: 0 };
21
- this.initialized = false;
22
- this.options = options;
23
- this.logger = new logger_1.Logger('MemorySystem');
24
- }
25
- /**
26
- * ๐Ÿ”ง CRIT-003 FIX: Store data with agent isolation
27
- * Implements agentId::contextKey namespacing for complete memory isolation
28
- */
29
- async storeShared(agentId, contextKey, value, ttl) {
30
- const isolatedKey = `${agentId}::${contextKey}`;
31
- return this.store(isolatedKey, value, ttl);
32
- }
33
- /**
34
- * ๐Ÿ”ง CRIT-003 FIX: Retrieve data with agent isolation
35
- * Implements agentId::contextKey namespacing with backward compatibility
36
- */
37
- async retrieveShared(agentId, contextKey) {
38
- const isolatedKey = `${agentId}::${contextKey}`;
39
- // Try isolated key first
40
- let result = await this.get(isolatedKey);
41
- // Fallback to original key for backward compatibility
42
- if (result === null || result === undefined) {
43
- this.logger.debug(`No isolated data found for ${isolatedKey}, falling back to original key ${contextKey}`);
44
- result = await this.get(contextKey);
45
- // If found with original key, migrate to isolated key
46
- if (result !== null && result !== undefined) {
47
- this.logger.info(`Migrating data from ${contextKey} to ${isolatedKey} for agent isolation`);
48
- await this.storeShared(agentId, contextKey, result);
49
- // Keep original for other agents that might still need it
50
- }
51
- }
52
- return result;
53
- }
54
- /**
55
- * ๐Ÿ”ง CRIT-003 FIX: Check if agent has specific context
56
- */
57
- async hasSharedContext(agentId, contextKey) {
58
- const isolatedKey = `${agentId}::${contextKey}`;
59
- return this.exists(isolatedKey) || this.exists(contextKey);
60
- }
61
- /**
62
- * ๐Ÿ”ง CRIT-003 FIX: List all context keys for an agent
63
- */
64
- async listAgentContexts(agentId) {
65
- const prefix = `${agentId}::`;
66
- const keys = await this.listKeys();
67
- return keys
68
- .filter(key => key.startsWith(prefix))
69
- .map(key => key.substring(prefix.length));
70
- }
71
- /**
72
- * ๐Ÿ”ง CRIT-003 FIX: Core store method for memory operations
73
- */
74
- async store(key, value, ttl) {
75
- if (!this.initialized)
76
- await this.initialize();
77
- const now = Date.now();
78
- const expiresAt = ttl ? now + (ttl * 1000) : undefined;
79
- // Store in cache if enabled
80
- if (this.options.cache?.enabled) {
81
- this.cache.set(key, {
82
- value,
83
- expiresAt: expiresAt || (now + (this.options.cache.ttl * 1000))
84
- });
85
- this.cacheStats.size = this.cache.size;
86
- }
87
- // Store in database
88
- await this.upsert('memory_store', {
89
- key,
90
- value: JSON.stringify(value),
91
- created_at: new Date().toISOString(),
92
- expires_at: expiresAt ? new Date(expiresAt).toISOString() : null,
93
- metadata: '{}'
94
- }, ['key']);
95
- }
96
- /**
97
- * ๐Ÿ”ง CRIT-003 FIX: Core get method for memory operations
98
- */
99
- async get(key) {
100
- if (!this.initialized)
101
- await this.initialize();
102
- // Check cache first
103
- if (this.options.cache?.enabled) {
104
- const cached = this.cache.get(key);
105
- if (cached && cached.expiresAt > Date.now()) {
106
- this.cacheStats.hits++;
107
- return cached.value;
108
- }
109
- if (cached) {
110
- this.cache.delete(key);
111
- this.cacheStats.evictions++;
112
- }
113
- this.cacheStats.misses++;
114
- }
115
- // Query database
116
- const rows = await this.query(`
117
- SELECT value, expires_at FROM memory_store
118
- WHERE key = ? AND (expires_at IS NULL OR expires_at > datetime('now'))
119
- `, [key]);
120
- if (rows.length === 0)
121
- return null;
122
- const result = JSON.parse(rows[0].value);
123
- // Update cache
124
- if (this.options.cache?.enabled) {
125
- const expiresAt = rows[0].expires_at
126
- ? new Date(rows[0].expires_at).getTime()
127
- : Date.now() + (this.options.cache.ttl * 1000);
128
- this.cache.set(key, { value: result, expiresAt });
129
- this.cacheStats.size = this.cache.size;
130
- }
131
- return result;
132
- }
133
- /**
134
- * ๐Ÿ”ง CRIT-003 FIX: Check if key exists
135
- */
136
- async exists(key) {
137
- if (!this.initialized)
138
- await this.initialize();
139
- const rows = await this.query(`
140
- SELECT 1 FROM memory_store
141
- WHERE key = ? AND (expires_at IS NULL OR expires_at > datetime('now'))
142
- `, [key]);
143
- return rows.length > 0;
144
- }
145
- /**
146
- * ๐Ÿ”ง CRIT-003 FIX: List all keys
147
- */
148
- async listKeys() {
149
- if (!this.initialized)
150
- await this.initialize();
151
- const rows = await this.query(`
152
- SELECT key FROM memory_store
153
- WHERE expires_at IS NULL OR expires_at > datetime('now')
154
- `);
155
- return rows.map(row => row.key);
156
- }
157
- /**
158
- * Initialize the memory system
159
- */
160
- async initialize() {
161
- if (this.initialized)
162
- return;
163
- this.logger.info('Initializing Memory System...');
164
- // Ensure directory exists
165
- const dir = path_1.default.dirname(this.options.dbPath);
166
- if (!fs_1.default.existsSync(dir)) {
167
- fs_1.default.mkdirSync(dir, { recursive: true });
168
- }
169
- // Open database
170
- this.db = new better_sqlite3_1.default(this.options.dbPath);
171
- this.db.pragma('journal_mode = WAL');
172
- this.db.pragma('synchronous = NORMAL');
173
- // Create core tables
174
- await this.createCoreTables();
175
- // Always run critical migrations (like missing metadata column)
176
- await this.runCriticalMigrations();
177
- // Run optional migrations if needed
178
- if (this.options.schema?.autoMigrate) {
179
- await this.runMigrations();
180
- }
181
- // Start cleanup timer
182
- this.startCleanupTimer();
183
- this.initialized = true;
184
- this.logger.info('Memory System initialized');
185
- }
186
- // Duplicate store method removed - using primary implementation above
187
- // Duplicate get method removed - using primary implementation above
188
- /**
189
- * Update an existing value
190
- */
191
- async update(key, value) {
192
- const existing = await this.get(key);
193
- if (!existing) {
194
- throw new Error(`Key not found: ${key}`);
195
- }
196
- await this.store(key, value);
197
- }
198
- // Duplicate delete method removed - using primary implementation above
199
- /**
200
- * Execute a raw SQL query
201
- */
202
- async execute(sql, params = []) {
203
- if (!this.db)
204
- throw new Error('Memory system not initialized');
205
- const stmt = this.db.prepare(sql);
206
- stmt.run(...params);
207
- }
208
- /**
209
- * Query the database
210
- */
211
- async query(sql, params = []) {
212
- if (!this.db)
213
- throw new Error('Memory system not initialized');
214
- const stmt = this.db.prepare(sql);
215
- return stmt.all(...params);
216
- }
217
- /**
218
- * Insert data into a table
219
- */
220
- async insert(table, data) {
221
- if (!this.db)
222
- throw new Error('Memory system not initialized');
223
- const keys = Object.keys(data);
224
- const values = Object.values(data);
225
- const placeholders = keys.map(() => '?').join(', ');
226
- const sql = `INSERT INTO ${table} (${keys.join(', ')}) VALUES (${placeholders})`;
227
- const stmt = this.db.prepare(sql);
228
- stmt.run(...values);
229
- }
230
- /**
231
- * Delete a key from memory
232
- */
233
- async delete(key) {
234
- if (!this.initialized)
235
- await this.initialize();
236
- // Remove from cache
237
- if (this.options.cache?.enabled) {
238
- this.cache.delete(key);
239
- }
240
- // Remove from database
241
- if (!this.db)
242
- throw new Error('Memory system not initialized');
243
- const stmt = this.db.prepare('DELETE FROM memory_store WHERE key = ?');
244
- stmt.run(key);
245
- }
246
- /**
247
- * Upsert data (insert or update)
248
- */
249
- async upsert(table, data, uniqueKeys) {
250
- if (!this.db)
251
- throw new Error('Memory system not initialized');
252
- const keys = Object.keys(data);
253
- const values = Object.values(data);
254
- const placeholders = keys.map(() => '?').join(', ');
255
- const updateClause = keys
256
- .filter(k => !uniqueKeys.includes(k))
257
- .map(k => `${k} = excluded.${k}`)
258
- .join(', ');
259
- const sql = `
260
- INSERT INTO ${table} (${keys.join(', ')}) VALUES (${placeholders})
261
- ON CONFLICT (${uniqueKeys.join(', ')}) DO UPDATE SET ${updateClause}
262
- `;
263
- const stmt = this.db.prepare(sql);
264
- stmt.run(...values);
265
- }
266
- /**
267
- * Create a transaction
268
- */
269
- transaction(fn) {
270
- if (!this.db)
271
- throw new Error('Memory system not initialized');
272
- return this.db.transaction(fn)();
273
- }
274
- /**
275
- * Get database statistics
276
- */
277
- async getDatabaseStats() {
278
- if (!this.db)
279
- throw new Error('Memory system not initialized');
280
- const tables = this.db.prepare(`
281
- SELECT name FROM sqlite_master WHERE type = 'table'
282
- `).all();
283
- const rowCounts = {};
284
- for (const { name } of tables) {
285
- const count = this.db.prepare(`SELECT COUNT(*) as count FROM ${name}`).get();
286
- rowCounts[name] = count.count;
287
- }
288
- const dbFile = this.options.dbPath;
289
- const stats = fs_1.default.statSync(dbFile);
290
- return {
291
- size: stats.size,
292
- tableCount: tables.length,
293
- rowCounts
294
- };
295
- }
296
- /**
297
- * Get cache statistics
298
- */
299
- async getCacheStats() {
300
- return {
301
- ...this.cacheStats,
302
- size: this.cache.size
303
- };
304
- }
305
- /**
306
- * Invalidate cache
307
- */
308
- async invalidateCache(pattern) {
309
- if (!pattern) {
310
- this.cache.clear();
311
- this.logger.info('Cache cleared');
312
- }
313
- else {
314
- // Pattern-based invalidation
315
- const keys = Array.from(this.cache.keys());
316
- const regex = new RegExp(pattern);
317
- let invalidated = 0;
318
- for (const key of keys) {
319
- if (regex.test(key)) {
320
- this.cache.delete(key);
321
- invalidated++;
322
- }
323
- }
324
- this.logger.info(`Invalidated ${invalidated} cache entries matching pattern: ${pattern}`);
325
- }
326
- }
327
- /**
328
- * Create emergency backup
329
- */
330
- async createEmergencyBackup() {
331
- if (!this.db)
332
- throw new Error('Memory system not initialized');
333
- const backupPath = `${this.options.dbPath}.backup.${Date.now()}`;
334
- await this.db.backup(backupPath);
335
- this.logger.info(`Emergency backup created: ${backupPath}`);
336
- return backupPath;
337
- }
338
- /**
339
- * Close the memory system
340
- */
341
- async close() {
342
- if (this.cleanupTimer) {
343
- clearInterval(this.cleanupTimer);
344
- }
345
- if (this.db) {
346
- this.db.close();
347
- this.db = undefined;
348
- }
349
- this.cache.clear();
350
- this.initialized = false;
351
- this.logger.info('Memory System closed');
352
- }
353
- /**
354
- * Private helper methods
355
- */
356
- async createCoreTables() {
357
- if (!this.db)
358
- return;
359
- // Core memory store
360
- this.db.exec(`
361
- CREATE TABLE IF NOT EXISTS memory_store (
362
- key TEXT PRIMARY KEY,
363
- value TEXT NOT NULL,
364
- ttl INTEGER,
365
- expires_at INTEGER,
366
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
367
- updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
368
- metadata TEXT DEFAULT '{}'
369
- );
370
-
371
- CREATE INDEX IF NOT EXISTS idx_memory_expires ON memory_store(expires_at);
372
-
373
- -- ๐Ÿš€ PERFORMANCE FIX: 6 Critical indexes for 60-80% performance improvement
374
- CREATE INDEX IF NOT EXISTS idx_memory_created_at ON memory_store(created_at);
375
- CREATE INDEX IF NOT EXISTS idx_memory_key_expires ON memory_store(key, expires_at);
376
- `);
377
- // Swarm sessions
378
- this.db.exec(`
379
- CREATE TABLE IF NOT EXISTS swarm_sessions (
380
- id TEXT PRIMARY KEY,
381
- objective TEXT NOT NULL,
382
- started_at TIMESTAMP NOT NULL,
383
- status TEXT NOT NULL,
384
- queen_agent_id TEXT,
385
- completed_at TIMESTAMP,
386
- metadata TEXT
387
- );
388
-
389
- CREATE INDEX IF NOT EXISTS idx_swarm_status ON swarm_sessions(status);
390
-
391
- -- ๐Ÿš€ PERFORMANCE FIX: Critical compound index for session status queries
392
- CREATE INDEX IF NOT EXISTS idx_swarm_status_started ON swarm_sessions(status, started_at);
393
- `);
394
- // Agent coordination
395
- this.db.exec(`
396
- CREATE TABLE IF NOT EXISTS agent_coordination (
397
- session_id TEXT NOT NULL,
398
- agent_id TEXT NOT NULL,
399
- agent_type TEXT NOT NULL,
400
- status TEXT NOT NULL,
401
- assigned_tasks TEXT,
402
- progress_percentage INTEGER DEFAULT 0,
403
- last_activity TIMESTAMP,
404
- current_tool TEXT,
405
- error_state TEXT,
406
- PRIMARY KEY (session_id, agent_id)
407
- );
408
-
409
- CREATE INDEX IF NOT EXISTS idx_agent_status ON agent_coordination(status);
410
-
411
- -- ๐Ÿš€ PERFORMANCE FIX: Critical compound indexes for agent queries
412
- CREATE INDEX IF NOT EXISTS idx_agent_session_type ON agent_coordination(session_id, agent_type);
413
- CREATE INDEX IF NOT EXISTS idx_agent_activity ON agent_coordination(last_activity);
414
- `);
415
- // ServiceNow artifacts
416
- this.db.exec(`
417
- CREATE TABLE IF NOT EXISTS servicenow_artifacts (
418
- sys_id TEXT PRIMARY KEY,
419
- artifact_type TEXT NOT NULL,
420
- name TEXT NOT NULL,
421
- description TEXT,
422
- created_by_agent TEXT,
423
- session_id TEXT,
424
- deployment_status TEXT,
425
- update_set_id TEXT,
426
- dependencies TEXT,
427
- metadata TEXT,
428
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
429
- );
430
-
431
- CREATE INDEX IF NOT EXISTS idx_artifact_session ON servicenow_artifacts(session_id);
432
- CREATE INDEX IF NOT EXISTS idx_artifact_type ON servicenow_artifacts(artifact_type);
433
- `);
434
- // Agent messages
435
- this.db.exec(`
436
- CREATE TABLE IF NOT EXISTS agent_messages (
437
- id TEXT PRIMARY KEY,
438
- session_id TEXT NOT NULL,
439
- from_agent TEXT NOT NULL,
440
- to_agent TEXT NOT NULL,
441
- message_type TEXT NOT NULL,
442
- content TEXT,
443
- artifact_reference TEXT,
444
- timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
445
- processed BOOLEAN DEFAULT FALSE
446
- );
447
-
448
- CREATE INDEX IF NOT EXISTS idx_message_session ON agent_messages(session_id);
449
- CREATE INDEX IF NOT EXISTS idx_message_processed ON agent_messages(processed);
450
- `);
451
- // Shared context
452
- this.db.exec(`
453
- CREATE TABLE IF NOT EXISTS shared_context (
454
- session_id TEXT NOT NULL,
455
- context_key TEXT NOT NULL,
456
- context_value TEXT,
457
- created_by_agent TEXT,
458
- expires_at TIMESTAMP,
459
- access_permissions TEXT,
460
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
461
- PRIMARY KEY (session_id, context_key)
462
- );
463
- `);
464
- // Performance metrics
465
- this.db.exec(`
466
- CREATE TABLE IF NOT EXISTS performance_metrics (
467
- id TEXT PRIMARY KEY,
468
- operation TEXT NOT NULL,
469
- start_time INTEGER NOT NULL,
470
- end_time INTEGER,
471
- duration INTEGER,
472
- success BOOLEAN NOT NULL,
473
- session_id TEXT,
474
- agent_id TEXT,
475
- metadata TEXT,
476
- resource_usage TEXT,
477
- error TEXT,
478
- created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
479
- );
480
-
481
- CREATE INDEX IF NOT EXISTS idx_perf_operation ON performance_metrics(operation);
482
- CREATE INDEX IF NOT EXISTS idx_perf_session ON performance_metrics(session_id);
483
- CREATE INDEX IF NOT EXISTS idx_perf_time ON performance_metrics(start_time);
484
-
485
- -- ๐Ÿš€ PERFORMANCE FIX: Final critical performance index
486
- CREATE INDEX IF NOT EXISTS idx_perf_success_time ON performance_metrics(success, created_at);
487
- `);
488
- }
489
- async runCriticalMigrations() {
490
- // Critical migrations that must always run
491
- try {
492
- // Fix for missing metadata column
493
- const tableInfo = this.db.prepare("PRAGMA table_info(memory_store)").all();
494
- const hasMetadataColumn = tableInfo.some((col) => col.name === 'metadata');
495
- if (!hasMetadataColumn) {
496
- this.logger.info('Running critical migration: Adding metadata column to memory_store table...');
497
- this.db.exec("ALTER TABLE memory_store ADD COLUMN metadata TEXT DEFAULT '{}'");
498
- this.logger.info('Critical migration completed: Metadata column added successfully');
499
- }
500
- }
501
- catch (error) {
502
- this.logger.warn('Could not complete critical migrations:', error);
503
- }
504
- }
505
- async runMigrations() {
506
- // Implement schema migrations if needed
507
- this.logger.info('Running database migrations...');
508
- // Check current version
509
- const versionRow = await this.get('_schema_version');
510
- const currentVersion = versionRow?.version || '0.0.0';
511
- const targetVersion = this.options.schema?.version || '1.0.0';
512
- if (currentVersion === targetVersion) {
513
- this.logger.info('Database schema is up to date');
514
- return;
515
- }
516
- // Run migrations based on version differences
517
- // This is a placeholder - implement actual migration logic
518
- // Update version
519
- await this.store('_schema_version', { version: targetVersion });
520
- this.logger.info(`Database migrated to version ${targetVersion}`);
521
- }
522
- // ๐Ÿ”ด SNOW-003 FIX: More aggressive cleanup to prevent memory exhaustion
523
- startCleanupTimer() {
524
- // ๐Ÿ”ด CRITICAL: Run cleanup every 15 minutes instead of 1 hour
525
- this.cleanupTimer = setInterval(async () => {
526
- await this.cleanup();
527
- }, 900000); // 15 minutes
528
- // ๐Ÿ”ด CRITICAL: Additional memory pressure cleanup every 5 minutes
529
- setInterval(async () => {
530
- await this.memoryPressureCleanup();
531
- }, 300000); // 5 minutes
532
- }
533
- // ๐Ÿ”ด SNOW-003 FIX: Enhanced cleanup with memory pressure monitoring
534
- async cleanup() {
535
- if (!this.db)
536
- return;
537
- const now = Date.now();
538
- const startTime = Date.now();
539
- try {
540
- // ๐Ÿ”ด CRITICAL: Clean expired memory entries with better logging
541
- const stmt = this.db.prepare('DELETE FROM memory_store WHERE expires_at < ?');
542
- const result = stmt.run(now);
543
- if (result.changes > 0) {
544
- this.logger.info(`๐Ÿงน Cleaned up ${result.changes} expired memory entries`);
545
- }
546
- // ๐Ÿ”ด CRITICAL: Clean cache with size monitoring
547
- let cacheCleanedCount = 0;
548
- const cacheEntriesBefore = this.cache.size;
549
- for (const [key, entry] of this.cache.entries()) {
550
- if (entry.expiresAt < now) {
551
- this.cache.delete(key);
552
- cacheCleanedCount++;
553
- }
554
- }
555
- if (cacheCleanedCount > 0) {
556
- this.logger.info(`๐Ÿงน Cleaned ${cacheCleanedCount} expired cache entries (${cacheEntriesBefore} โ†’ ${this.cache.size})`);
557
- }
558
- // ๐Ÿ”ด CRITICAL: More frequent vacuum for high activity
559
- const lastVacuum = await this.get('_last_vacuum');
560
- const shouldVacuum = !lastVacuum || now - lastVacuum > 21600000; // 6 hours instead of 24
561
- if (shouldVacuum) {
562
- this.logger.info('๐Ÿ—ƒ๏ธ Starting database vacuum...');
563
- this.db.exec('VACUUM');
564
- await this.store('_last_vacuum', now);
565
- this.logger.info(`โœ… Database vacuumed in ${Date.now() - startTime}ms`);
566
- }
567
- // ๐Ÿ”ด CRITICAL: Log memory stats after cleanup
568
- const memUsage = process.memoryUsage();
569
- const heapUsedMB = Math.round(memUsage.heapUsed / 1024 / 1024);
570
- if (heapUsedMB > 100) { // Log if significant memory usage
571
- this.logger.info(`๐Ÿ“Š Memory after cleanup: ${heapUsedMB}MB heap, ${this.cache.size} cache entries`);
572
- }
573
- }
574
- catch (error) {
575
- this.logger.error('โŒ Cleanup failed:', error);
576
- }
577
- }
578
- /**
579
- * ๐Ÿ”ด SNOW-003 FIX: Emergency cleanup when memory pressure is high
580
- */
581
- async memoryPressureCleanup() {
582
- if (!this.db)
583
- return;
584
- try {
585
- const memUsage = process.memoryUsage();
586
- const heapUsedMB = Math.round(memUsage.heapUsed / 1024 / 1024);
587
- const cacheSize = this.cache.size;
588
- // ๐Ÿ”ด CRITICAL: Trigger aggressive cleanup if memory is high
589
- if (heapUsedMB > 300 || cacheSize > 1000) {
590
- this.logger.warn(`โš ๏ธ High memory pressure detected: ${heapUsedMB}MB heap, ${cacheSize} cache entries`);
591
- // 1. Aggressive cache cleanup - remove 50% of oldest entries
592
- if (cacheSize > 500) {
593
- const entries = Array.from(this.cache.entries())
594
- .sort((a, b) => a[1].expiresAt - b[1].expiresAt);
595
- const toRemove = Math.floor(entries.length * 0.5);
596
- for (let i = 0; i < toRemove; i++) {
597
- this.cache.delete(entries[i][0]);
598
- }
599
- this.logger.info(`๐Ÿงน Emergency cache cleanup: removed ${toRemove} entries (${cacheSize} โ†’ ${this.cache.size})`);
600
- }
601
- // 2. Clean old database entries more aggressively
602
- const now = Date.now();
603
- const aggressiveCleanupTime = now - (7 * 24 * 60 * 60 * 1000); // 7 days old
604
- const aggressiveStmt = this.db.prepare('DELETE FROM memory_store WHERE created_at < ? AND expires_at IS NULL');
605
- const aggressiveResult = aggressiveStmt.run(aggressiveCleanupTime);
606
- if (aggressiveResult.changes > 0) {
607
- this.logger.info(`๐Ÿงน Emergency database cleanup: removed ${aggressiveResult.changes} old entries`);
608
- }
609
- // 3. Force garbage collection if available
610
- if (global.gc) {
611
- this.logger.info('๐Ÿ—‘๏ธ Forcing garbage collection due to memory pressure');
612
- global.gc();
613
- // Check memory after GC
614
- const afterGC = process.memoryUsage();
615
- const afterGCMB = Math.round(afterGC.heapUsed / 1024 / 1024);
616
- this.logger.info(`๐Ÿ“Š Memory after GC: ${heapUsedMB}MB โ†’ ${afterGCMB}MB`);
617
- }
618
- }
619
- }
620
- catch (error) {
621
- this.logger.error('โŒ Memory pressure cleanup failed:', error);
622
- }
623
- }
624
- checkCacheSize() {
625
- if (!this.options.cache?.enabled)
626
- return;
627
- const maxSize = this.options.cache.maxSize || 100;
628
- const currentSizeMB = this.estimateCacheSize();
629
- if (currentSizeMB > maxSize) {
630
- // Evict oldest entries
631
- const entries = Array.from(this.cache.entries())
632
- .sort((a, b) => a[1].expiresAt - b[1].expiresAt);
633
- const toEvict = Math.floor(entries.length * 0.2); // Evict 20%
634
- for (let i = 0; i < toEvict; i++) {
635
- this.cache.delete(entries[i][0]);
636
- this.cacheStats.evictions++;
637
- }
638
- this.logger.debug(`Evicted ${toEvict} cache entries due to size limit`);
639
- }
640
- }
641
- estimateCacheSize() {
642
- // Rough estimate of cache size in MB
643
- let size = 0;
644
- for (const [key, entry] of this.cache.entries()) {
645
- size += key.length + JSON.stringify(entry.value).length;
646
- }
647
- return size / 1024 / 1024;
648
- }
649
- }
650
- exports.MemorySystem = MemorySystem;
651
- //# sourceMappingURL=memory-system.js.map
@@ -1,6 +0,0 @@
1
- /**
2
- * Snow-Flow Memory System Test
3
- * Demonstrates and tests the SQLite memory system functionality
4
- */
5
- export {};
6
- //# sourceMappingURL=memory-test.d.ts.map