agentic-flow 1.4.9 → 1.4.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.
@@ -3,14 +3,112 @@
3
3
  * Operates on Claude Flow's memory.db at .swarm/memory.db
4
4
  */
5
5
  import BetterSqlite3 from 'better-sqlite3';
6
- import { existsSync } from 'fs';
7
- import { join } from 'path';
6
+ import { existsSync, mkdirSync } from 'fs';
7
+ import { join, dirname } from 'path';
8
8
  // Simple logger for database operations
9
9
  const logger = {
10
10
  info: (msg, data) => console.log(`[INFO] ${msg}`, data || ''),
11
11
  error: (msg, data) => console.error(`[ERROR] ${msg}`, data || '')
12
12
  };
13
13
  let dbInstance = null;
14
+ /**
15
+ * Run database migrations (create tables)
16
+ */
17
+ export async function runMigrations() {
18
+ const dbPath = process.env.CLAUDE_FLOW_DB_PATH || join(process.cwd(), '.swarm', 'memory.db');
19
+ // Create directory if it doesn't exist
20
+ const dbDir = dirname(dbPath);
21
+ if (!existsSync(dbDir)) {
22
+ mkdirSync(dbDir, { recursive: true });
23
+ logger.info('Created database directory', { path: dbDir });
24
+ }
25
+ // Create database file
26
+ const db = new BetterSqlite3(dbPath);
27
+ db.pragma('journal_mode = WAL');
28
+ db.pragma('foreign_keys = ON');
29
+ // Create tables
30
+ db.exec(`
31
+ CREATE TABLE IF NOT EXISTS patterns (
32
+ id TEXT PRIMARY KEY,
33
+ type TEXT NOT NULL,
34
+ pattern_data TEXT NOT NULL,
35
+ confidence REAL NOT NULL DEFAULT 0.5,
36
+ usage_count INTEGER NOT NULL DEFAULT 0,
37
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
38
+ last_used TEXT
39
+ );
40
+
41
+ CREATE TABLE IF NOT EXISTS pattern_embeddings (
42
+ id TEXT PRIMARY KEY,
43
+ model TEXT NOT NULL,
44
+ dims INTEGER NOT NULL,
45
+ vector BLOB NOT NULL,
46
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
47
+ FOREIGN KEY (id) REFERENCES patterns(id) ON DELETE CASCADE
48
+ );
49
+
50
+ CREATE TABLE IF NOT EXISTS pattern_links (
51
+ src_id TEXT NOT NULL,
52
+ dst_id TEXT NOT NULL,
53
+ relation TEXT NOT NULL,
54
+ weight REAL NOT NULL DEFAULT 1.0,
55
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
56
+ PRIMARY KEY (src_id, dst_id, relation),
57
+ FOREIGN KEY (src_id) REFERENCES patterns(id) ON DELETE CASCADE,
58
+ FOREIGN KEY (dst_id) REFERENCES patterns(id) ON DELETE CASCADE
59
+ );
60
+
61
+ CREATE TABLE IF NOT EXISTS task_trajectories (
62
+ task_id TEXT PRIMARY KEY,
63
+ agent_id TEXT NOT NULL,
64
+ query TEXT NOT NULL,
65
+ trajectory_json TEXT NOT NULL,
66
+ started_at TEXT,
67
+ ended_at TEXT,
68
+ judge_label TEXT,
69
+ judge_conf REAL,
70
+ judge_reasons TEXT,
71
+ matts_run_id TEXT,
72
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
73
+ );
74
+
75
+ CREATE TABLE IF NOT EXISTS matts_runs (
76
+ run_id TEXT PRIMARY KEY,
77
+ task_id TEXT NOT NULL,
78
+ mode TEXT NOT NULL,
79
+ k INTEGER NOT NULL,
80
+ status TEXT NOT NULL,
81
+ summary TEXT,
82
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
83
+ );
84
+
85
+ CREATE TABLE IF NOT EXISTS consolidation_runs (
86
+ run_id TEXT PRIMARY KEY,
87
+ items_processed INTEGER NOT NULL,
88
+ duplicates_found INTEGER NOT NULL,
89
+ contradictions_found INTEGER NOT NULL,
90
+ items_pruned INTEGER NOT NULL,
91
+ duration_ms INTEGER NOT NULL,
92
+ created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
93
+ );
94
+
95
+ CREATE TABLE IF NOT EXISTS metrics_log (
96
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
97
+ metric_name TEXT NOT NULL,
98
+ value REAL NOT NULL,
99
+ timestamp TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
100
+ );
101
+
102
+ CREATE INDEX IF NOT EXISTS idx_patterns_type ON patterns(type);
103
+ CREATE INDEX IF NOT EXISTS idx_patterns_confidence ON patterns(confidence DESC);
104
+ CREATE INDEX IF NOT EXISTS idx_patterns_created_at ON patterns(created_at DESC);
105
+ CREATE INDEX IF NOT EXISTS idx_pattern_links_relation ON pattern_links(relation);
106
+ CREATE INDEX IF NOT EXISTS idx_trajectories_agent ON task_trajectories(agent_id);
107
+ `);
108
+ db.close();
109
+ dbInstance = null; // Reset instance to force reconnection
110
+ logger.info('Database migrations completed', { path: dbPath });
111
+ }
14
112
  /**
15
113
  * Get database connection (singleton)
16
114
  */
@@ -36,6 +36,15 @@ export async function initialize() {
36
36
  console.log(`[ReasoningBank] Database: ${process.env.CLAUDE_FLOW_DB_PATH || '.swarm/memory.db'}`);
37
37
  console.log(`[ReasoningBank] Embeddings: ${config.embeddings.provider}`);
38
38
  console.log(`[ReasoningBank] Retrieval k: ${config.retrieve.k}`);
39
+ // Run migrations to create database and tables
40
+ try {
41
+ await db.runMigrations();
42
+ console.log(`[ReasoningBank] Database migrated successfully`);
43
+ }
44
+ catch (error) {
45
+ console.error('[ReasoningBank] Migration error:', error);
46
+ throw new Error('ReasoningBank initialization failed: could not run migrations');
47
+ }
39
48
  // Check database connection
40
49
  try {
41
50
  const dbConn = db.getDb();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-flow",
3
- "version": "1.4.9",
3
+ "version": "1.4.10",
4
4
  "description": "Production-ready AI agent orchestration platform with 66 specialized agents, 213 MCP tools, ReasoningBank learning memory, and autonomous multi-agent swarms. Built by @ruvnet with Claude Agent SDK, neural networks, memory persistence, GitHub integration, and distributed consensus protocols.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",