claude-flow 2.0.0-alpha.30 → 2.0.0-alpha.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-flow",
3
- "version": "2.0.0-alpha.30",
3
+ "version": "2.0.0-alpha.32",
4
4
  "description": "Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)",
5
5
  "main": "cli.mjs",
6
6
  "bin": {
@@ -168,103 +168,147 @@ function applyBasicIndexes(db) {
168
168
  // First ensure all required columns exist
169
169
  ensureRequiredColumns(db);
170
170
 
171
- const indexes = [
172
- // Swarms indexes
173
- 'CREATE INDEX IF NOT EXISTS idx_swarms_status ON swarms(status)',
174
- 'CREATE INDEX IF NOT EXISTS idx_swarms_created ON swarms(created_at)',
175
-
176
- // Agents indexes
177
- 'CREATE INDEX IF NOT EXISTS idx_agents_swarm ON agents(swarm_id)',
178
- 'CREATE INDEX IF NOT EXISTS idx_agents_type ON agents(type)',
179
- 'CREATE INDEX IF NOT EXISTS idx_agents_status ON agents(status)',
180
-
181
- // Tasks indexes
182
- 'CREATE INDEX IF NOT EXISTS idx_tasks_swarm ON tasks(swarm_id)',
183
- 'CREATE INDEX IF NOT EXISTS idx_tasks_agent ON tasks(agent_id)',
184
- 'CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status)',
185
- 'CREATE INDEX IF NOT EXISTS idx_tasks_priority ON tasks(priority DESC)',
186
-
187
- // Memory indexes
188
- 'CREATE INDEX IF NOT EXISTS idx_memory_swarm ON collective_memory(swarm_id)',
189
- 'CREATE INDEX IF NOT EXISTS idx_memory_key ON collective_memory(key)',
190
- 'CREATE INDEX IF NOT EXISTS idx_memory_type ON collective_memory(type)',
191
-
192
- // Consensus indexes
193
- 'CREATE INDEX IF NOT EXISTS idx_consensus_swarm ON consensus_decisions(swarm_id)',
194
- 'CREATE INDEX IF NOT EXISTS idx_consensus_created ON consensus_decisions(created_at)'
195
- ];
196
-
197
- indexes.forEach(sql => db.exec(sql));
171
+ // Check which tables exist before creating indexes
172
+ const tables = db.prepare(`
173
+ SELECT name FROM sqlite_master
174
+ WHERE type='table' AND name NOT LIKE 'sqlite_%'
175
+ `).all().map(row => row.name);
176
+
177
+ const tableSet = new Set(tables);
178
+
179
+ const indexes = [];
180
+
181
+ // Only create indexes for tables that exist
182
+ if (tableSet.has('swarms')) {
183
+ indexes.push(
184
+ 'CREATE INDEX IF NOT EXISTS idx_swarms_status ON swarms(status)',
185
+ 'CREATE INDEX IF NOT EXISTS idx_swarms_created ON swarms(created_at)'
186
+ );
187
+ }
188
+
189
+ if (tableSet.has('agents')) {
190
+ indexes.push(
191
+ 'CREATE INDEX IF NOT EXISTS idx_agents_swarm ON agents(swarm_id)',
192
+ 'CREATE INDEX IF NOT EXISTS idx_agents_type ON agents(type)',
193
+ 'CREATE INDEX IF NOT EXISTS idx_agents_status ON agents(status)'
194
+ );
195
+ }
196
+
197
+ if (tableSet.has('tasks')) {
198
+ indexes.push(
199
+ 'CREATE INDEX IF NOT EXISTS idx_tasks_swarm ON tasks(swarm_id)',
200
+ 'CREATE INDEX IF NOT EXISTS idx_tasks_agent ON tasks(agent_id)',
201
+ 'CREATE INDEX IF NOT EXISTS idx_tasks_status ON tasks(status)',
202
+ 'CREATE INDEX IF NOT EXISTS idx_tasks_priority ON tasks(priority DESC)'
203
+ );
204
+ }
205
+
206
+ if (tableSet.has('collective_memory')) {
207
+ indexes.push(
208
+ 'CREATE INDEX IF NOT EXISTS idx_memory_swarm ON collective_memory(swarm_id)',
209
+ 'CREATE INDEX IF NOT EXISTS idx_memory_key ON collective_memory(key)',
210
+ 'CREATE INDEX IF NOT EXISTS idx_memory_type ON collective_memory(type)'
211
+ );
212
+ }
213
+
214
+ if (tableSet.has('consensus_decisions')) {
215
+ indexes.push(
216
+ 'CREATE INDEX IF NOT EXISTS idx_consensus_swarm ON consensus_decisions(swarm_id)',
217
+ 'CREATE INDEX IF NOT EXISTS idx_consensus_created ON consensus_decisions(created_at)'
218
+ );
219
+ }
220
+
221
+ indexes.forEach(sql => {
222
+ try {
223
+ db.exec(sql);
224
+ } catch (error) {
225
+ console.warn(`Warning: Could not create index: ${error.message}`);
226
+ }
227
+ });
198
228
  }
199
229
 
200
230
  /**
201
231
  * Ensure all required columns exist
202
232
  */
203
233
  function ensureRequiredColumns(db) {
204
- // Check and add priority column to tasks table
205
- const hasPriority = db.prepare(`
206
- SELECT COUNT(*) as count FROM pragma_table_info('tasks')
207
- WHERE name = 'priority'
208
- `).get();
234
+ // First check which tables exist
235
+ const tables = db.prepare(`
236
+ SELECT name FROM sqlite_master
237
+ WHERE type='table' AND name NOT LIKE 'sqlite_%'
238
+ `).all().map(row => row.name);
209
239
 
210
- if (!hasPriority || hasPriority.count === 0) {
211
- try {
212
- db.exec('ALTER TABLE tasks ADD COLUMN priority INTEGER DEFAULT 5');
213
- console.log('Added missing priority column to tasks table');
214
- } catch (error) {
215
- if (!error.message.includes('duplicate column')) {
216
- throw error;
240
+ const tableSet = new Set(tables);
241
+
242
+ // Only check columns for tables that exist
243
+ if (tableSet.has('tasks')) {
244
+ // Check and add priority column to tasks table
245
+ const hasPriority = db.prepare(`
246
+ SELECT COUNT(*) as count FROM pragma_table_info('tasks')
247
+ WHERE name = 'priority'
248
+ `).get();
249
+
250
+ if (!hasPriority || hasPriority.count === 0) {
251
+ try {
252
+ db.exec('ALTER TABLE tasks ADD COLUMN priority INTEGER DEFAULT 5');
253
+ console.log('Added missing priority column to tasks table');
254
+ } catch (error) {
255
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
256
+ throw error;
257
+ }
217
258
  }
218
259
  }
219
- }
220
260
 
221
- // Check and add completed_at column to tasks table
222
- const hasCompletedAt = db.prepare(`
223
- SELECT COUNT(*) as count FROM pragma_table_info('tasks')
224
- WHERE name = 'completed_at'
225
- `).get();
226
-
227
- if (!hasCompletedAt || hasCompletedAt.count === 0) {
228
- try {
229
- db.exec('ALTER TABLE tasks ADD COLUMN completed_at DATETIME');
230
- console.log('Added missing completed_at column to tasks table');
231
- } catch (error) {
232
- if (!error.message.includes('duplicate column')) {
233
- throw error;
261
+ // Check and add completed_at column to tasks table
262
+ const hasCompletedAt = db.prepare(`
263
+ SELECT COUNT(*) as count FROM pragma_table_info('tasks')
264
+ WHERE name = 'completed_at'
265
+ `).get();
266
+
267
+ if (!hasCompletedAt || hasCompletedAt.count === 0) {
268
+ try {
269
+ db.exec('ALTER TABLE tasks ADD COLUMN completed_at DATETIME');
270
+ console.log('Added missing completed_at column to tasks table');
271
+ } catch (error) {
272
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
273
+ throw error;
274
+ }
234
275
  }
235
276
  }
236
- }
237
-
238
- // Check and add result column to tasks table
239
- const hasResult = db.prepare(`
240
- SELECT COUNT(*) as count FROM pragma_table_info('tasks')
241
- WHERE name = 'result'
242
- `).get();
243
-
244
- if (!hasResult || hasResult.count === 0) {
245
- try {
246
- db.exec('ALTER TABLE tasks ADD COLUMN result TEXT');
247
- console.log('Added missing result column to tasks table');
248
- } catch (error) {
249
- if (!error.message.includes('duplicate column')) {
250
- throw error;
277
+
278
+ // Check and add result column to tasks table
279
+ const hasResult = db.prepare(`
280
+ SELECT COUNT(*) as count FROM pragma_table_info('tasks')
281
+ WHERE name = 'result'
282
+ `).get();
283
+
284
+ if (!hasResult || hasResult.count === 0) {
285
+ try {
286
+ db.exec('ALTER TABLE tasks ADD COLUMN result TEXT');
287
+ console.log('Added missing result column to tasks table');
288
+ } catch (error) {
289
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
290
+ throw error;
291
+ }
251
292
  }
252
293
  }
253
294
  }
254
295
 
255
- // Check and add updated_at column to swarms table
256
- const hasUpdatedAt = db.prepare(`
257
- SELECT COUNT(*) as count FROM pragma_table_info('swarms')
258
- WHERE name = 'updated_at'
259
- `).get();
260
296
 
261
- if (!hasUpdatedAt || hasUpdatedAt.count === 0) {
262
- try {
263
- db.exec('ALTER TABLE swarms ADD COLUMN updated_at DATETIME DEFAULT CURRENT_TIMESTAMP');
264
- console.log('Added missing updated_at column to swarms table');
265
- } catch (error) {
266
- if (!error.message.includes('duplicate column')) {
267
- throw error;
297
+ if (tableSet.has('swarms')) {
298
+ // Check and add updated_at column to swarms table
299
+ const hasUpdatedAt = db.prepare(`
300
+ SELECT COUNT(*) as count FROM pragma_table_info('swarms')
301
+ WHERE name = 'updated_at'
302
+ `).get();
303
+
304
+ if (!hasUpdatedAt || hasUpdatedAt.count === 0) {
305
+ try {
306
+ db.exec('ALTER TABLE swarms ADD COLUMN updated_at DATETIME');
307
+ console.log('Added missing updated_at column to swarms table');
308
+ } catch (error) {
309
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
310
+ throw error;
311
+ }
268
312
  }
269
313
  }
270
314
  }
@@ -274,22 +318,50 @@ function ensureRequiredColumns(db) {
274
318
  * Apply advanced performance indexes
275
319
  */
276
320
  function applyAdvancedIndexes(db) {
277
- const indexes = [
278
- // Composite indexes for common queries
279
- 'CREATE INDEX IF NOT EXISTS idx_tasks_swarm_status ON tasks(swarm_id, status)',
280
- 'CREATE INDEX IF NOT EXISTS idx_agents_swarm_type ON agents(swarm_id, type)',
281
- 'CREATE INDEX IF NOT EXISTS idx_memory_swarm_key ON collective_memory(swarm_id, key)',
282
-
283
- // Covering indexes for frequently accessed data
284
- 'CREATE INDEX IF NOT EXISTS idx_tasks_full ON tasks(swarm_id, agent_id, status, priority)',
285
- 'CREATE INDEX IF NOT EXISTS idx_agents_full ON agents(swarm_id, type, status, role)',
286
-
287
- // Partial indexes for active records
288
- "CREATE INDEX IF NOT EXISTS idx_swarms_active ON swarms(id, name) WHERE status = 'active'",
289
- "CREATE INDEX IF NOT EXISTS idx_tasks_pending ON tasks(swarm_id, priority) WHERE status = 'pending'"
290
- ];
291
-
292
- indexes.forEach(sql => db.exec(sql));
321
+ // Check which tables exist
322
+ const tables = db.prepare(`
323
+ SELECT name FROM sqlite_master
324
+ WHERE type='table' AND name NOT LIKE 'sqlite_%'
325
+ `).all().map(row => row.name);
326
+
327
+ const tableSet = new Set(tables);
328
+ const indexes = [];
329
+
330
+ // Composite indexes for common queries
331
+ if (tableSet.has('tasks')) {
332
+ indexes.push(
333
+ 'CREATE INDEX IF NOT EXISTS idx_tasks_swarm_status ON tasks(swarm_id, status)',
334
+ 'CREATE INDEX IF NOT EXISTS idx_tasks_full ON tasks(swarm_id, agent_id, status, priority)',
335
+ "CREATE INDEX IF NOT EXISTS idx_tasks_pending ON tasks(swarm_id, priority) WHERE status = 'pending'"
336
+ );
337
+ }
338
+
339
+ if (tableSet.has('agents')) {
340
+ indexes.push(
341
+ 'CREATE INDEX IF NOT EXISTS idx_agents_swarm_type ON agents(swarm_id, type)',
342
+ 'CREATE INDEX IF NOT EXISTS idx_agents_full ON agents(swarm_id, type, status, role)'
343
+ );
344
+ }
345
+
346
+ if (tableSet.has('collective_memory')) {
347
+ indexes.push(
348
+ 'CREATE INDEX IF NOT EXISTS idx_memory_swarm_key ON collective_memory(swarm_id, key)'
349
+ );
350
+ }
351
+
352
+ if (tableSet.has('swarms')) {
353
+ indexes.push(
354
+ "CREATE INDEX IF NOT EXISTS idx_swarms_active ON swarms(id, name) WHERE status = 'active'"
355
+ );
356
+ }
357
+
358
+ indexes.forEach(sql => {
359
+ try {
360
+ db.exec(sql);
361
+ } catch (error) {
362
+ console.warn(`Warning: Could not create index: ${error.message}`);
363
+ }
364
+ });
293
365
  }
294
366
 
295
367
  /**
@@ -344,6 +416,17 @@ function addPerformanceTracking(db) {
344
416
  * Add memory optimization features
345
417
  */
346
418
  function addMemoryOptimization(db) {
419
+ // Check if collective_memory table exists
420
+ const tables = db.prepare(`
421
+ SELECT name FROM sqlite_master
422
+ WHERE type='table' AND name = 'collective_memory'
423
+ `).all();
424
+
425
+ if (tables.length === 0) {
426
+ console.log('collective_memory table does not exist, skipping memory optimization');
427
+ return;
428
+ }
429
+
347
430
  // Check and add access_count column
348
431
  const hasAccessCount = db.prepare(`
349
432
  SELECT COUNT(*) as count FROM pragma_table_info('collective_memory')
@@ -358,7 +441,7 @@ function addMemoryOptimization(db) {
358
441
  `);
359
442
  console.log('Added access_count column to collective_memory table');
360
443
  } catch (error) {
361
- if (!error.message.includes('duplicate column')) {
444
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
362
445
  throw error;
363
446
  }
364
447
  }
@@ -374,11 +457,11 @@ function addMemoryOptimization(db) {
374
457
  try {
375
458
  db.exec(`
376
459
  ALTER TABLE collective_memory
377
- ADD COLUMN accessed_at DATETIME DEFAULT CURRENT_TIMESTAMP
460
+ ADD COLUMN accessed_at DATETIME
378
461
  `);
379
462
  console.log('Added accessed_at column to collective_memory table');
380
463
  } catch (error) {
381
- if (!error.message.includes('duplicate column')) {
464
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
382
465
  throw error;
383
466
  }
384
467
  }
@@ -397,7 +480,7 @@ function addMemoryOptimization(db) {
397
480
  ADD COLUMN compressed INTEGER DEFAULT 0
398
481
  `);
399
482
  } catch (error) {
400
- if (!error.message.includes('duplicate column')) {
483
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
401
484
  throw error;
402
485
  }
403
486
  }
@@ -415,7 +498,7 @@ function addMemoryOptimization(db) {
415
498
  ADD COLUMN size INTEGER DEFAULT 0
416
499
  `);
417
500
  } catch (error) {
418
- if (!error.message.includes('duplicate column')) {
501
+ if (!error.message.includes('duplicate column') && !error.message.includes('no such table')) {
419
502
  throw error;
420
503
  }
421
504
  }
@@ -157,6 +157,10 @@ async function initHiveMind(flags) {
157
157
  confidence REAL DEFAULT 1.0,
158
158
  created_by TEXT,
159
159
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
160
+ accessed_at DATETIME,
161
+ access_count INTEGER DEFAULT 0,
162
+ compressed INTEGER DEFAULT 0,
163
+ size INTEGER DEFAULT 0,
160
164
  FOREIGN KEY (swarm_id) REFERENCES swarms(id)
161
165
  );
162
166
 
@@ -427,7 +431,8 @@ async function spawnSwarm(args, flags) {
427
431
  objective TEXT,
428
432
  queen_type TEXT,
429
433
  status TEXT DEFAULT 'active',
430
- created_at DATETIME DEFAULT CURRENT_TIMESTAMP
434
+ created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
435
+ updated_at DATETIME
431
436
  );
432
437
 
433
438
  CREATE TABLE IF NOT EXISTS agents (
@@ -448,8 +453,10 @@ async function spawnSwarm(args, flags) {
448
453
  agent_id TEXT,
449
454
  description TEXT,
450
455
  status TEXT DEFAULT 'pending',
456
+ priority INTEGER DEFAULT 5,
451
457
  result TEXT,
452
458
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
459
+ completed_at DATETIME,
453
460
  FOREIGN KEY (swarm_id) REFERENCES swarms(id),
454
461
  FOREIGN KEY (agent_id) REFERENCES agents(id)
455
462
  );