Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated

Checkpoint: File edits

rUv020c5fc28c85
diff --git a/v3/@claude-flow/cli/package.json b/v3/@claude-flow/cli/package.json
index e439731432..884c1ce639 100644
--- a/v3/@claude-flow/cli/package.json
+++ b/v3/@claude-flow/cli/package.json
@@ -1,6 +1,6 @@
{
"name": "@claude-flow/cli",
- "version": "3.0.0-alpha.54",
+ "version": "3.0.0-alpha.55",
"type": "module",
"description": "CLI module - command parsing, prompts, output formatting",
"main": "dist/src/index.js",
diff --git a/v3/@claude-flow/cli/src/commands/memory.ts b/v3/@claude-flow/cli/src/commands/memory.ts
index 019958e3f3..9c278a9b6a 100644
--- a/v3/@claude-flow/cli/src/commands/memory.ts
+++ b/v3/@claude-flow/cli/src/commands/memory.ts
@@ -1126,11 +1126,242 @@ const importCommand: Command = {
}
};
+// Init subcommand - initialize memory database using sql.js
+const initMemoryCommand: Command = {
+ name: 'init',
+ description: 'Initialize memory database with sql.js (WASM SQLite)',
+ options: [
+ {
+ name: 'backend',
+ short: 'b',
+ description: 'Backend type: sqlite (default), hybrid, or agentdb',
+ type: 'string',
+ default: 'sqlite'
+ },
+ {
+ name: 'path',
+ short: 'p',
+ description: 'Database path',
+ type: 'string'
+ },
+ {
+ name: 'force',
+ short: 'f',
+ description: 'Overwrite existing database',
+ type: 'boolean',
+ default: false
+ }
+ ],
+ examples: [
+ { command: 'claude-flow memory init', description: 'Initialize default SQLite database' },
+ { command: 'claude-flow memory init -b hybrid', description: 'Initialize hybrid backend' },
+ { command: 'claude-flow memory init -p ./data/memory.db', description: 'Custom path' }
+ ],
+ action: async (ctx: CommandContext): Promise<CommandResult> => {
+ const backend = (ctx.flags.backend as string) || 'sqlite';
+ const customPath = ctx.flags.path as string;
+ const force = ctx.flags.force as boolean;
+
+ const fs = await import('fs');
+ const path = await import('path');
+
+ // Determine database paths
+ const swarmDir = path.join(process.cwd(), '.swarm');
+ const claudeDir = path.join(process.cwd(), '.claude');
+
+ const dbPath = customPath || path.join(swarmDir, 'memory.db');
+ const dbDir = path.dirname(dbPath);
+
+ // Check if already exists
+ if (fs.existsSync(dbPath) && !force) {
+ output.printWarning(`Memory database already exists at ${dbPath}`);
+ output.printInfo('Use --force to reinitialize');
+ return { success: false, exitCode: 1 };
+ }
+
+ output.printInfo(`Initializing ${backend} memory backend...`);
+
+ try {
+ // Create directories
+ if (!fs.existsSync(dbDir)) {
+ fs.mkdirSync(dbDir, { recursive: true });
+ output.writeln(output.dim(` Created directory: ${dbDir}`));
+ }
+
+ // Initialize database using sql.js (WASM SQLite)
+ output.writeln(output.dim(' Using sql.js (WASM SQLite - cross-platform, no native compilation)'));
+
+ // Create basic schema
+ const schema = `
+-- Claude Flow V3 Memory Database
+-- Backend: ${backend}
+-- Created: ${new Date().toISOString()}
+
+-- Core memory entries
+CREATE TABLE IF NOT EXISTS memory_entries (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ key TEXT NOT NULL UNIQUE,
+ value TEXT NOT NULL,
+ namespace TEXT DEFAULT 'default',
+ type TEXT DEFAULT 'text',
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ expires_at DATETIME,
+ metadata TEXT
+);
+
+-- Vector embeddings for semantic search
+CREATE TABLE IF NOT EXISTS vectors (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ entry_id INTEGER REFERENCES memory_entries(id),
+ embedding BLOB NOT NULL,
+ dimension INTEGER NOT NULL,
+ model TEXT DEFAULT 'local',
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+);
+
+-- Patterns for learning
+CREATE TABLE IF NOT EXISTS patterns (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ pattern_type TEXT NOT NULL,
+ pattern_data TEXT NOT NULL,
+ confidence REAL DEFAULT 0.5,
+ usage_count INTEGER DEFAULT 0,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ last_used_at DATETIME
+);
+
+-- Sessions for context persistence
+CREATE TABLE IF NOT EXISTS sessions (
+ id TEXT PRIMARY KEY,
+ state TEXT NOT NULL,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
+ updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
+);
+
+-- Learning trajectories
+CREATE TABLE IF NOT EXISTS trajectories (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ session_id TEXT,
+ action TEXT NOT NULL,
+ outcome TEXT,
+ reward REAL DEFAULT 0,
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP
+);
+
+-- Indexes for performance
+CREATE INDEX IF NOT EXISTS idx_memory_namespace ON memory_entries(namespace);
+CREATE INDEX IF NOT EXISTS idx_memory_key ON memory_entries(key);
+CREATE INDEX IF NOT EXISTS idx_patterns_type ON patterns(pattern_type);
+CREATE INDEX IF NOT EXISTS idx_trajectories_session ON trajectories(session_id);
+
+-- Metadata table
+CREATE TABLE IF NOT EXISTS metadata (
+ key TEXT PRIMARY KEY,
+ value TEXT NOT NULL
+);
+
+INSERT OR REPLACE INTO metadata (key, value) VALUES
+ ('version', '3.0.0'),
+ ('backend', '${backend}'),
+ ('created_at', '${new Date().toISOString()}'),
+ ('sql_js', 'true');
+`;
+
+ // Write schema to temp file for initialization
+ const schemaPath = path.join(dbDir, 'schema.sql');
+ fs.writeFileSync(schemaPath, schema);
+
+ // Create empty database file (sql.js will initialize it on first use)
+ if (force && fs.existsSync(dbPath)) {
+ fs.unlinkSync(dbPath);
+ }
+
+ // Write minimal SQLite header to create valid empty database
+ // sql.js will properly initialize the schema on first connection
+ const sqliteHeader = Buffer.from([
+ 0x53, 0x51, 0x4C, 0x69, 0x74, 0x65, 0x20, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x20, 0x33, 0x00, // "SQLite format 3\0"
+ 0x10, 0x00, // page size: 4096 bytes
+ 0x01, // file format write version
+ 0x01, // file format read version
+ 0x00, // reserved space
+ 0x40, // max embedded payload fraction
+ 0x20, // min embedded payload fraction
+ 0x20, // leaf payload fraction
+ 0x00, 0x00, 0x00, 0x01, // file change counter
+ 0x00, 0x00, 0x00, 0x01, // database size in pages
+ 0x00, 0x00, 0x00, 0x00, // first freelist trunk page
+ 0x00, 0x00, 0x00, 0x00, // total freelist pages
+ 0x00, 0x00, 0x00, 0x01, // schema cookie
+ 0x00, 0x00, 0x00, 0x04, // schema format number
+ 0x00, 0x00, 0x00, 0x00, // default page cache size
+ 0x00, 0x00, 0x00, 0x00, // largest root btree page
+ 0x00, 0x00, 0x00, 0x01, // text encoding (1=UTF-8)
+ 0x00, 0x00, 0x00, 0x00, // user version
+ 0x00, 0x00, 0x00, 0x00, // incremental vacuum mode
+ 0x00, 0x00, 0x00, 0x00, // application id
+ ...Array(20).fill(0x00), // reserved for expansion
+ 0x00, 0x00, 0x00, 0x01, // version-valid-for number
+ 0x00, 0x2E, 0x32, 0x8F, // SQLite version number (3.46.1)
+ ]);
+
+ // Pad to 4096 bytes (one page)
+ const page = Buffer.alloc(4096, 0);
+ sqliteHeader.copy(page);
+ fs.writeFileSync(dbPath, page);
+
+ // Also create in .claude directory for compatibility
+ const claudeDbPath = path.join(claudeDir, 'memory.db');
+ if (!fs.existsSync(claudeDir)) {
+ fs.mkdirSync(claudeDir, { recursive: true });
+ }
+ if (!fs.existsSync(claudeDbPath)) {
+ fs.copyFileSync(dbPath, claudeDbPath);
+ output.writeln(output.dim(` Synced to: ${claudeDbPath}`));
+ }
+
+ output.writeln();
+ output.printSuccess('Memory database initialized');
+ output.writeln();
+
+ output.printTable({
+ columns: [
+ { key: 'property', header: 'Property', width: 15 },
+ { key: 'value', header: 'Value', width: 40 }
+ ],
+ data: [
+ { property: 'Backend', value: backend },
+ { property: 'Path', value: dbPath },
+ { property: 'Engine', value: 'sql.js (WASM SQLite)' },
+ { property: 'Schema', value: schemaPath },
+ { property: 'Tables', value: '6 (memory_entries, vectors, patterns, sessions, trajectories, metadata)' }
+ ]
+ });
+
+ output.writeln();
+ output.printInfo('Ready for use. Store data with: claude-flow memory store -k "key" --value "data"');
+
+ return {
+ success: true,
+ data: {
+ backend,
+ path: dbPath,
+ schemaPath,
+ engine: 'sql.js'
+ }
+ };
+ } catch (error) {
+ output.printError(`Failed to initialize memory: ${error instanceof Error ? error.message : String(error)}`);
+ return { success: false, exitCode: 1 };
+ }
+ }
+};
+
// Main memory command
export const memoryCommand: Command = {
name: 'memory',
description: 'Memory management commands',
- subcommands: [storeCommand, retrieveCommand, searchCommand, listCommand, deleteCommand, statsCommand, configureCommand, cleanupCommand, compressCommand, exportCommand, importCommand],
+ subcommands: [initMemoryCommand, storeCommand, retrieveCommand, searchCommand, listCommand, deleteCommand, statsCommand, configureCommand, cleanupCommand, compressCommand, exportCommand, importCommand],
options: [],
examples: [
{ command: 'claude-flow memory store -k "key" -v "value"', description: 'Store data' },
diff --git a/v3/package-lock.json b/v3/package-lock.json
index 8fc07bab2b..5d7563586c 100644
--- a/v3/package-lock.json
+++ b/v3/package-lock.json
@@ -124,7 +124,7 @@
}
},
"@claude-flow/cli": {
- "version": "3.0.0-alpha.54",
+ "version": "3.0.0-alpha.55",
"dependencies": {
"@claude-flow/shared": "^3.0.0-alpha.1"
},