23f7624596
ADR-166 MCP Bridge Security Lock / Static-source security lock (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / Compose default binds loopback + Mongo has auth (push) Failing after 2s
CodeQL Advanced / Analyze (rust) (push) Failing after 0s
ADR-166 MCP Bridge Security Lock / plugin-agent-federation bindHost default (push) Failing after 1s
ADR-166 MCP Bridge Security Lock / Runtime behavior — 401 + terminal gate + fail-closed (push) Failing after 4s
business-pods-smoke / smoke (push) Failing after 1s
all-plugins-smoke / smoke-all (push) Failing after 2s
CI/CD Pipeline / Security & Code Quality (push) Failing after 1s
CI/CD Pipeline / Test Suite (ubuntu-latest) (push) Failing after 1s
CI/CD Pipeline / Build & Package (macos-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (ubuntu-latest) (push) Has been skipped
CI/CD Pipeline / Build & Package (windows-latest) (push) Has been skipped
CI/CD Pipeline / Documentation & Examples (push) Failing after 1s
Clone Tracker (14-day rolling) / Snapshot clones for ruflo ecosystem (push) Failing after 1s
CodeQL Advanced / Analyze (actions) (push) Failing after 1s
CodeQL Advanced / Analyze (javascript-typescript) (push) Failing after 1s
federation-peer-rust / stable-noop (push) Failing after 1s
metaharness-ci / score (push) Failing after 1s
metaharness-ci / router-compat (push) Failing after 0s
metaharness-ci / similarity-tests (push) Failing after 0s
no-agentbbs-smoke / smoke-without-agentbbs (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (windows-latest) (push) Has been skipped
codex-integration-audit / Codex integration audit (push) Failing after 1s
helpers-manifest-guard / guard (push) Failing after 1s
🔗 Cross-Agent Integration Tests / 🤝 Agent Coordination Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🧠 Memory Sharing Integration (push) Has been skipped
🔗 Cross-Agent Integration Tests / 🛡️ Fault Tolerance Tests (push) Has been skipped
🔗 Cross-Agent Integration Tests / ⚡ Performance Integration Tests (push) Has been skipped
metaharness-ci / mcp-scan (push) Failing after 1s
metaharness-ci / eject-dryrun (push) Failing after 1s
metaharness-ci / metaharness-real-data (push) Failing after 0s
no-cli-optdep-bloat-2561 / guard (push) Failing after 1s
no-metaharness-smoke / smoke-without-metaharness (push) Failing after 1s
no-phantom-agentic-flow-subpath / guard (push) Failing after 1s
🔄 Automated Rollback Manager / 🚨 Failure Detection (push) Failing after 1s
V3 CI/CD Pipeline / Plugin hooks smoke / ubuntu-latest / Node 22 (push) Failing after 1s
V3 CI/CD Pipeline / ruflo-graph-intelligence build + test smoke (#2044, ADR-123) (push) Failing after 1s
CVE Audit Gate / Audit root (critical-blocking) (push) Failing after 2s
cost-tracker-smoke / smoke (push) Failing after 3s
oia-audit-weekly / audit (push) Failing after 2s
ruflo-agent-smoke / ruflo-agent structural smoke (push) Failing after 1s
📊 Status Badges Update / 📊 Update Status Badges (push) Failing after 1s
V3 CI/CD Pipeline / Static regression guards (#2267 YAML + (push) Failing after 1s
V3 CI/CD Pipeline / Test V3 Packages (push) Failing after 0s
V3 CI/CD Pipeline / agent_execute provider routing smoke (#2042) (push) Failing after 0s
CVE Audit Gate / Audit v3 (critical-blocking) (push) Failing after 1s
federation-peer-rust / stable-native (push) Failing after 2s
🔗 Cross-Agent Integration Tests / 🚀 Integration Test Setup (push) Failing after 2s
neural-trader-smoke / runtime-smoke (push) Failing after 1s
V3 CI/CD Pipeline / Build V3 (macos-latest) (push) Has been skipped
V3 CI/CD Pipeline / Build V3 (ubuntu-latest) (push) Has been skipped
V3 CI/CD Pipeline / Type Check V3 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 24 (push) Failing after 1s
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / ubuntu-latest / Node 22 (push) Failing after 2s
V3 CI/CD Pipeline / browser rvf create flag smoke (#2015) (push) Failing after 0s
V3 CI/CD Pipeline / Dependency review (#2046) (push) Has been skipped
V3 CI/CD Pipeline / Supply-chain audit (#2046) (push) Failing after 0s
V3 CI/CD Pipeline / witness marker drift smoke (#2021) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader portfolio CG smoke (#2068, ADR-126 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / neural-trader backtest signing smoke (#2068, ADR-126 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / kg-extract type-import classification smoke (#2049) (push) Failing after 0s
V3 CI/CD Pipeline / witness verify precondition smoke (#1880) (push) Failing after 2s
V3 CI/CD Pipeline / neural-trader pipeline risk-gate smoke (#2068, ADR-126 Phase 5) (push) Failing after 0s
V3 CI/CD Pipeline / neural-trader feature attribution smoke (#2068, ADR-126 Phase 6) (push) Failing after 0s
V3 CI/CD Pipeline / plugin-registry signature verification smoke (#1922, CWE-347) (push) Failing after 4s
V3 CI/CD Pipeline / memory stats legacy-DB smoke (#2120) (push) Failing after 4s
V3 CI/CD Pipeline / github deprecated actions smoke (#2089, ADR-127 Phase 3) (push) Failing after 1s
V3 CI/CD Pipeline / graph query + pathfinder smoke (ADR-130 P2+P5) (push) Has been skipped
V3 CI/CD Pipeline / graph trajectory hooks smoke (ADR-130 P3) (push) Has been skipped
V3 CI/CD Pipeline / graph plugin adapter smoke (ADR-130 P4) (push) Has been skipped
V3 CI/CD Pipeline / graph benchmark (ADR-130 P6) (push) Has been skipped
V3 CI/CD Pipeline / statusline generator delegation smoke (#2195) (push) Failing after 1s
V3 CI/CD Pipeline / wizard init regression guard (#2206 (push) Failing after 1s
V3 CI/CD Pipeline / memory no-stray-db smoke (ADR-125 P7) (push) Failing after 1s
V3 CI/CD Pipeline / github-safe injection smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github actions pin smoke (#2089, ADR-127 Phase 1) (push) Failing after 1s
V3 CI/CD Pipeline / github attribution opt-in smoke (#2089, ADR-127 Phase 4) (push) Failing after 1s
V3 CI/CD Pipeline / pre-bash hook safety smoke (#2017) (push) Failing after 1s
V3 CI/CD Pipeline / Memory import smoke / ubuntu-latest (push) Failing after 0s
V3 CI/CD Pipeline / MCP protocol smoke / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / ruvllm WASM auto-init smoke (#2086) (push) Failing after 4s
V3 CI/CD Pipeline / MCP paired-tool round-trip smoke (#1889) (push) Failing after 1s
V3 CI/CD Pipeline / Plugin package install-safety (#1902/#1903/#1904) (push) Failing after 1s
V3 CI/CD Pipeline / Tool description discoverability (ADR-112) (push) Failing after 3s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (22) (push) Failing after 1s
V3 CI/CD Pipeline / CLI npx-install smoke (#1147 / (24) (push) Failing after 1s
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / ubuntu-latest (push) Failing after 2s
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / ubuntu-latest (push) Failing after 1s
V3 CI/CD Pipeline / Vector-index dimension audit (#1947) (push) Failing after 0s
V3 CI/CD Pipeline / Hook-command install safety (#1921) (push) Failing after 1s
V3 CI/CD Pipeline / ToolOutputGuardrail smoke (ADR-131, (push) Failing after 1s
V3 CI/CD Pipeline / init-bundle invariants smoke (#2095, ADR-128 Phase 5) (push) Failing after 1s
V3 CI/CD Pipeline / wasm provider bridge smoke (ADR-129 P1) (push) Failing after 2s
V3 CI/CD Pipeline / wasm gallery CRUD smoke (ADR-129 P3) (push) Failing after 1s
V3 CI/CD Pipeline / wasm plugin bridge smoke (ADR-129 P4) (push) Failing after 0s
V3 CI/CD Pipeline / wasm compose smoke (ADR-129 P2) (push) Failing after 4s
V3 CI/CD Pipeline / graph schema smoke (ADR-130 P1) (push) Failing after 0s
Validate Marketplace / validate (push) Failing after 1s
🔍 Verification Pipeline / 🚀 Setup Verification (push) Failing after 1s
🔍 Verification Pipeline / 🛡️ Security Verification (push) Has been skipped
🔍 Verification Pipeline / 📝 Code Quality (push) Has been skipped
🔍 Verification Pipeline / 🧪 Test Verification (${{ matrix.os }}, Node ${{ matrix.node }}) (push) Has been skipped
🔍 Verification Pipeline / 🏗️ Build Verification (push) Has been skipped
🔍 Verification Pipeline / 📚 Documentation Verification (push) Has been skipped
CVE Audit Gate / High-severity report (warn only) (push) Has been cancelled
🔄 Automated Rollback Manager / 🔄 Execute Rollback (push) Has been cancelled
🔄 Automated Rollback Manager / ✅ Post-Rollback Verification (push) Has been cancelled
🔄 Automated Rollback Manager / 📊 Rollback Monitoring (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook execution smoke (#2132) / windows-latest (push) Has been cancelled
🔄 Automated Rollback Manager / ⏳ Manual Rollback Approval (push) Has been cancelled
V3 CI/CD Pipeline / MCP protocol smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Memory import smoke / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows hook shim smoke (#2132) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Windows init hooks smoke (#2132) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / macos-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / ubuntu-latest (push) Has been cancelled
V3 CI/CD Pipeline / Witness verify (signed manifest) / windows-latest (push) Has been cancelled
V3 CI/CD Pipeline / Publish to npm (alpha) (push) Has been cancelled
V3 CI/CD Pipeline / Smoke (no better-sqlite3) / macos-latest / Node 22 (push) Has been cancelled
V3 CI/CD Pipeline / Plugin hooks smoke / macos-latest / Node 22 (push) Has been cancelled
CI/CD Pipeline / Deploy & Release (push) Has been cancelled
CI/CD Pipeline / CI Status (push) Has been cancelled
🔗 Cross-Agent Integration Tests / 📊 Integration Test Report (push) Has been cancelled
🔄 Automated Rollback Manager / 🔍 Pre-Rollback Validation (push) Has been cancelled
🔍 Verification Pipeline / ⚡ Performance Verification (push) Has been cancelled
🔍 Verification Pipeline / 📊 Verification Report (push) Has been cancelled
612 lines
15 KiB
Markdown
612 lines
15 KiB
Markdown
# better-sqlite3 Usage Inventory - Claude-Flow v3
|
|
|
|
**Generated**: 2026-01-03
|
|
**Purpose**: Complete inventory of better-sqlite3 usage across codebase for sql.js migration
|
|
|
|
---
|
|
|
|
## Summary
|
|
|
|
- **Total files**: 17
|
|
- **Direct imports**: 15
|
|
- **Indirect usage**: 2 (patches)
|
|
- **External dependencies**: 2 (agentic-flow, agentdb)
|
|
|
|
---
|
|
|
|
## 1. Core Database Layer
|
|
|
|
### 1.1 Main Abstraction Layer ⭐ (Priority: Critical)
|
|
|
|
**File**: `/home/user/claude-flow/src/memory/sqlite-wrapper.js`
|
|
- **Line**: 14-19 (initialization)
|
|
- **Usage**: Dynamic require/import with error handling
|
|
- **Current features**:
|
|
- Platform detection
|
|
- Auto-rebuild on NODE_MODULE_VERSION mismatch
|
|
- Graceful fallback messaging
|
|
- **Migration**: Add sql.js as alternative provider
|
|
- **Impact**: High - Core abstraction used by all database operations
|
|
|
|
```javascript
|
|
// Lines 14-19
|
|
let Database = null;
|
|
let sqliteAvailable = false;
|
|
let loadError = null;
|
|
let rebuildAttempted = false;
|
|
|
|
// Line 54-66: Loading logic
|
|
async function tryLoadSQLite() {
|
|
try {
|
|
const require = createRequire(import.meta.url);
|
|
Database = require('better-sqlite3');
|
|
sqliteAvailable = true;
|
|
return true;
|
|
} catch (requireErr) {
|
|
// Fallback to ES module import
|
|
// ... error handling
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### 1.2 Database Service
|
|
|
|
**File**: `/home/user/claude-flow/src/api/database-service.ts`
|
|
- **Line**: 559
|
|
- **Usage**: Dynamic import for SQLite initialization
|
|
- **Method**: `initializeSQLite()`
|
|
- **Migration**: Indirect - uses sqlite-wrapper abstractions
|
|
- **Impact**: Medium - API layer uses DatabaseManager
|
|
|
|
```typescript
|
|
// Line 556-570
|
|
private async initializeSQLite(): Promise<void> {
|
|
try {
|
|
// Import better-sqlite3 dynamically
|
|
const Database = (await import('better-sqlite3')).default;
|
|
this.db = new Database(this.config.database);
|
|
|
|
// Enable WAL mode for better concurrency
|
|
this.db.pragma('journal_mode = WAL');
|
|
this.db.pragma('synchronous = NORMAL');
|
|
this.db.pragma('cache_size = 1000');
|
|
this.db.pragma('temp_store = memory');
|
|
} catch (error) {
|
|
throw new DatabaseError('Failed to initialize SQLite', { error });
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### 1.3 Database Manager
|
|
|
|
**File**: `/home/user/claude-flow/src/core/DatabaseManager.ts`
|
|
- **Line**: 197
|
|
- **Usage**: CommonJS require with error recovery
|
|
- **Method**: `SQLiteProvider` constructor
|
|
- **Migration**: Add SqlJsProvider as alternative
|
|
- **Impact**: High - Core persistence layer
|
|
|
|
```typescript
|
|
// Line 189-207
|
|
class SQLiteProvider implements IDatabaseProvider {
|
|
private db: any;
|
|
private dbPath: string;
|
|
|
|
constructor(dbPath: string) {
|
|
this.dbPath = dbPath;
|
|
// Dynamic import to handle optional dependency
|
|
try {
|
|
const Database = require('better-sqlite3'); // Line 197
|
|
this.db = new Database(dbPath);
|
|
} catch (error) {
|
|
// Check for native module version mismatch (NODE_MODULE_VERSION error)
|
|
if (isNativeModuleVersionError(error)) {
|
|
const recoveryMsg = getNativeModuleRecoveryMessage(error);
|
|
throw new NativeModuleError(recoveryMsg, error as Error);
|
|
}
|
|
throw new Error('better-sqlite3 not available. Install with: npm install better-sqlite3');
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### 1.4 Persistence Manager
|
|
|
|
**File**: `/home/user/claude-flow/src/core/persistence.ts`
|
|
- **Line**: 5
|
|
- **Usage**: ES module import (direct)
|
|
- **Type**: TypeScript with full type safety
|
|
- **Migration**: Replace with provider abstraction
|
|
- **Impact**: High - Manages agent/task persistence
|
|
|
|
```typescript
|
|
// Line 1-8
|
|
/**
|
|
* Persistence layer for Claude-Flow using SQLite
|
|
*/
|
|
|
|
import Database from 'better-sqlite3'; // Line 5
|
|
import { join } from 'path';
|
|
import { mkdir } from 'fs/promises';
|
|
```
|
|
|
|
**Methods using better-sqlite3**:
|
|
- `initialize()` - Line 44-53
|
|
- `createTables()` - Line 55-100
|
|
- `saveAgent()` - Line 103-120
|
|
- `getAgent()` - Line 122-139
|
|
- All CRUD operations for agents/tasks
|
|
|
|
---
|
|
|
|
## 2. Memory Backends
|
|
|
|
### 2.1 SQLite Backend
|
|
|
|
**File**: `/home/user/claude-flow/src/memory/backends/sqlite.ts`
|
|
- **Line**: N/A (uses wrapper)
|
|
- **Usage**: Indirect via `sqlite-wrapper.js`
|
|
- **Migration**: Template for sql.js backend
|
|
- **Impact**: Medium - Memory storage layer
|
|
|
|
```typescript
|
|
// Line 32-38: Dynamic import from wrapper
|
|
if (!this.sqliteLoaded) {
|
|
const module = await import('../sqlite-wrapper.js');
|
|
createDatabase = module.createDatabase;
|
|
isSQLiteAvailable = module.isSQLiteAvailable;
|
|
this.sqliteLoaded = true;
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### 2.2 SQLite Store
|
|
|
|
**File**: `/home/user/claude-flow/src/memory/sqlite-store.js`
|
|
- **Line**: 10
|
|
- **Usage**: Import from wrapper
|
|
- **Type**: JavaScript (MCP server)
|
|
- **Migration**: Indirect - uses wrapper
|
|
- **Impact**: Medium - MCP memory persistence
|
|
|
|
```javascript
|
|
// Line 1-12
|
|
import path from 'path';
|
|
import { promises as fs } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
import os from 'os';
|
|
import { createDatabase } from './sqlite-wrapper.js'; // Line 10
|
|
import { getSwarmDir } from '../utils/project-root.js';
|
|
import { sessionSerializer } from './enhanced-session-serializer.js';
|
|
```
|
|
|
|
---
|
|
|
|
## 3. CLI Commands
|
|
|
|
### 3.1 Hive Mind Main
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/hive-mind.js`
|
|
- **Lines**: 38, 46
|
|
- **Usage**: Dual loading (require + dynamic import)
|
|
- **Migration**: Use abstraction layer
|
|
- **Impact**: Low - CLI utility
|
|
|
|
```javascript
|
|
// Line 36-49
|
|
try {
|
|
Database = require('better-sqlite3'); // Line 38
|
|
DatabaseAvailable = true;
|
|
} catch (error) {
|
|
console.warn('⚠️ better-sqlite3 not available, falling back to in-memory storage');
|
|
try {
|
|
// Try ES module import
|
|
const sqlite = await import('better-sqlite3'); // Line 46
|
|
Database = sqlite.default;
|
|
DatabaseAvailable = true;
|
|
} catch (importError) {
|
|
// Fallback handled
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### 3.2 Hive Mind Wizard
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/hive-mind-wizard.js`
|
|
- **Line**: 4
|
|
- **Usage**: Direct require
|
|
- **Migration**: Add try-catch with sql.js fallback
|
|
- **Impact**: Low - Setup wizard
|
|
|
|
```javascript
|
|
// Line 1-10
|
|
const fs = require('fs-extra');
|
|
const path = require('path');
|
|
const Database = require('better-sqlite3'); // Line 4
|
|
const ora = require('ora');
|
|
```
|
|
|
|
---
|
|
|
|
### 3.3 Hive Mind Memory
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/hive-mind/memory.js`
|
|
- **Line**: 7
|
|
- **Usage**: ES module import
|
|
- **Migration**: Use abstraction layer
|
|
- **Impact**: Low - Memory CLI utilities
|
|
|
|
```javascript
|
|
// Line 1-10
|
|
/**
|
|
* Hive Mind Memory Management CLI
|
|
*/
|
|
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import Database from 'better-sqlite3'; // Line 7
|
|
```
|
|
|
|
---
|
|
|
|
### 3.4 Metrics Reader
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/hive-mind/metrics-reader.js`
|
|
- **Line**: 6
|
|
- **Usage**: ES module import
|
|
- **Migration**: Use abstraction layer
|
|
- **Impact**: Low - Metrics utilities
|
|
|
|
```javascript
|
|
// Line 1-10
|
|
/**
|
|
* Hive Mind Metrics Reader
|
|
*/
|
|
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import Database from 'better-sqlite3'; // Line 6
|
|
```
|
|
|
|
---
|
|
|
|
### 3.5 Database Optimizer
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/hive-mind/db-optimizer.js`
|
|
- **Line**: 8
|
|
- **Usage**: ES module import
|
|
- **Migration**: Use abstraction layer
|
|
- **Impact**: Low - Maintenance utilities
|
|
|
|
```javascript
|
|
// Line 1-12
|
|
/**
|
|
* Hive Mind Database Optimizer
|
|
*/
|
|
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import os from 'os';
|
|
import Database from 'better-sqlite3'; // Line 8
|
|
```
|
|
|
|
---
|
|
|
|
### 3.6 MCP Wrapper
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/hive-mind/mcp-wrapper.js`
|
|
- **Line**: 132
|
|
- **Usage**: Type annotation only (JSDoc)
|
|
- **Migration**: Update type annotation
|
|
- **Impact**: None - Type hint only
|
|
|
|
```javascript
|
|
// Line 132
|
|
/** @type {import('better-sqlite3').Database | null} */
|
|
this.db = null;
|
|
```
|
|
|
|
---
|
|
|
|
### 3.7 Hive Mind Init
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/init/hive-mind-init.js`
|
|
- **Lines**: 304, 307
|
|
- **Usage**: Dynamic import with error handling
|
|
- **Migration**: Add sql.js as fallback
|
|
- **Impact**: Medium - Initialization logic
|
|
|
|
```javascript
|
|
// Line 304-315
|
|
// Dynamic import for better-sqlite3 with proper error handling
|
|
let Database;
|
|
try {
|
|
Database = (await import('better-sqlite3')).default; // Line 307
|
|
console.log('✅ Using SQLite for persistent storage');
|
|
} catch (error) {
|
|
console.warn('⚠️ SQLite not available, using in-memory storage');
|
|
console.warn(' Install better-sqlite3 for persistence: npm install better-sqlite3');
|
|
useInMemory = true;
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
### 3.8 Swarm Metrics Integration
|
|
|
|
**File**: `/home/user/claude-flow/src/cli/simple-commands/swarm-metrics-integration.js`
|
|
- **Line**: 8
|
|
- **Usage**: ES module import
|
|
- **Migration**: Use abstraction layer
|
|
- **Impact**: Low - Metrics integration
|
|
|
|
```javascript
|
|
// Line 1-12
|
|
/**
|
|
* Swarm Metrics Integration Service
|
|
*/
|
|
import fs from 'fs-extra';
|
|
import path from 'path';
|
|
import Database from 'better-sqlite3'; // Line 8
|
|
```
|
|
|
|
---
|
|
|
|
## 4. Utilities
|
|
|
|
### 4.1 Error Recovery
|
|
|
|
**File**: `/home/user/claude-flow/src/utils/error-recovery.ts`
|
|
- **Lines**: N/A (reference only)
|
|
- **Usage**: Detects better-sqlite3 errors
|
|
- **Functions**:
|
|
- `isNpmCacheError()` - Line 28-34
|
|
- `isNativeModuleVersionError()` - Line 40-46
|
|
- `getNativeModuleRecoveryMessage()` - Line 52-80
|
|
- `verifyBetterSqlite3()` - Line 267-274
|
|
- **Migration**: Add sql.js error detection
|
|
- **Impact**: High - Error handling infrastructure
|
|
|
|
```typescript
|
|
// Line 28-34
|
|
export function isNpmCacheError(error: any): boolean {
|
|
const errorStr = error?.message || String(error);
|
|
return (
|
|
errorStr.includes('ENOTEMPTY') &&
|
|
(errorStr.includes('npm') || errorStr.includes('npx') || errorStr.includes('_npx'))
|
|
) || errorStr.includes('better-sqlite3'); // Line 33
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 5. Patches & Workarounds
|
|
|
|
### 5.1 Agentic-Flow SQLite Fix
|
|
|
|
**File**: `/home/user/claude-flow/scripts/fix-agentic-flow-sqlite.sh`
|
|
- **Line**: 6, 16, 25-26
|
|
- **Usage**: Patches external dependency
|
|
- **Purpose**: Fixes broken better-sqlite3 import in agentic-flow
|
|
- **Migration**: Keep patch, add documentation
|
|
- **Impact**: Low - External dependency fix
|
|
|
|
```bash
|
|
# Line 6
|
|
QUERIES_FILE="node_modules/agentic-flow/dist/reasoningbank/db/queries.js"
|
|
|
|
# Line 16
|
|
if grep -q "import Database from 'better-sqlite3'" "$QUERIES_FILE"; then
|
|
|
|
# Line 25-26
|
|
sed -i '5s/const BetterSqlite3 = null; \/\/ Not used/import Database from '\''better-sqlite3'\'';/' "$QUERIES_FILE"
|
|
sed -i 's/new BetterSqlite3(/new Database(/g' "$QUERIES_FILE"
|
|
```
|
|
|
|
---
|
|
|
|
### 5.2 Hive Mind Timezone Fix Patch
|
|
|
|
**File**: `/home/user/claude-flow/src/patches/hive-mind-timezone-fix.patch`
|
|
- **Line**: 77
|
|
- **Usage**: Patch file showing better-sqlite3 import
|
|
- **Migration**: Update patch if needed
|
|
- **Impact**: None - Documentation only
|
|
|
|
```diff
|
|
# Line 77
|
|
+ import Database from 'better-sqlite3';
|
|
```
|
|
|
|
---
|
|
|
|
## 6. External Dependencies
|
|
|
|
### 6.1 agentic-flow
|
|
|
|
**Package**: `agentic-flow@^1.9.4`
|
|
- **Status**: Optional dependency
|
|
- **Uses**: better-sqlite3 for ReasoningBank database
|
|
- **File**: `dist/reasoningbank/db/queries.js`
|
|
- **Workaround**: Postinstall patch script
|
|
- **Migration**:
|
|
- Keep as-is (optional dependency)
|
|
- Document feature unavailability without better-sqlite3
|
|
- Future: Consider contributing sql.js support upstream
|
|
|
|
**Impact**: Medium - Disables ReasoningBank features on Windows
|
|
|
|
---
|
|
|
|
### 6.2 agentdb
|
|
|
|
**Package**: `agentdb@^1.6.1`
|
|
- **Status**: Optional dependency
|
|
- **Uses**: better-sqlite3 for vector database
|
|
- **Patch**: `patches/agentdb-fix-imports.patch`
|
|
- **Migration**:
|
|
- Keep as-is (optional dependency)
|
|
- Unlikely to support sql.js (performance requirements)
|
|
- Document vector search unavailability without better-sqlite3
|
|
|
|
**Impact**: Medium - Disables vector search on Windows
|
|
|
|
---
|
|
|
|
## 7. Install Scripts
|
|
|
|
### 7.1 ARM64 Installation Helper
|
|
|
|
**File**: `/home/user/claude-flow/scripts/install-arm64.js`
|
|
- **Lines**: 9, 11
|
|
- **Usage**: Test and rebuild better-sqlite3 on macOS ARM64
|
|
- **Migration**: Add sql.js check as fallback
|
|
- **Impact**: Low - Platform-specific helper
|
|
|
|
```javascript
|
|
// Line 7-16
|
|
async function checkSqliteBindings() {
|
|
try {
|
|
const Database = await import('better-sqlite3'); // Line 9
|
|
const db = new Database.default(':memory:'); // Line 11
|
|
db.close();
|
|
return true;
|
|
} catch (error) {
|
|
// Silently fail - this is expected when better-sqlite3 doesn't compile
|
|
return false;
|
|
}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Migration Priority Matrix
|
|
|
|
### Critical Priority (Week 1)
|
|
1. **sqlite-wrapper.js** - Core abstraction, affects all database operations
|
|
2. **DatabaseManager.ts** - Provider selection logic
|
|
3. **backends/sqlite.ts** - Template for sql.js backend
|
|
|
|
### High Priority (Week 2)
|
|
4. **persistence.ts** - Agent/task persistence
|
|
5. **database-service.ts** - API layer
|
|
6. **error-recovery.ts** - Error handling infrastructure
|
|
|
|
### Medium Priority (Week 3)
|
|
7. **hive-mind-init.js** - Initialization logic
|
|
8. **sqlite-store.js** - MCP memory persistence
|
|
9. All CLI commands (9 files) - Utilities
|
|
|
|
### Low Priority (Week 4)
|
|
10. **Patches** - Update documentation only
|
|
11. **install-arm64.js** - Platform helper
|
|
12. **External dependencies** - Document limitations
|
|
|
|
---
|
|
|
|
## Testing Requirements
|
|
|
|
### Per-File Testing
|
|
Each modified file should have:
|
|
- [ ] Unit tests with sql.js provider
|
|
- [ ] Unit tests with better-sqlite3 provider
|
|
- [ ] Unit tests with JSON fallback
|
|
- [ ] Integration tests for provider switching
|
|
- [ ] Error handling tests
|
|
|
|
### Platform Testing
|
|
- [ ] Windows 10/11 (sql.js primary)
|
|
- [ ] macOS Intel (better-sqlite3 primary)
|
|
- [ ] macOS ARM64 (better-sqlite3 with rebuild)
|
|
- [ ] Linux Ubuntu (better-sqlite3 primary)
|
|
- [ ] Alpine Linux (sql.js fallback)
|
|
- [ ] WSL (mixed environment)
|
|
|
|
---
|
|
|
|
## Estimated Migration Effort
|
|
|
|
| File | Lines to Change | Complexity | Hours |
|
|
|------|----------------|------------|-------|
|
|
| sqlite-wrapper.js | ~100 | High | 8 |
|
|
| DatabaseManager.ts | ~50 | Medium | 4 |
|
|
| backends/sqljs.ts (new) | ~350 | High | 12 |
|
|
| persistence.ts | ~20 | Low | 2 |
|
|
| database-service.ts | ~10 | Low | 1 |
|
|
| error-recovery.ts | ~30 | Medium | 3 |
|
|
| CLI files (9) | ~5 each | Low | 5 |
|
|
| Tests (new) | ~500 | High | 16 |
|
|
| Documentation | N/A | Medium | 8 |
|
|
| **Total** | **~1065** | **-** | **59 hours** |
|
|
|
|
**Estimated timeline**: ~8 working days (1 developer)
|
|
|
|
---
|
|
|
|
## Code Patterns to Replace
|
|
|
|
### Pattern 1: Direct Import
|
|
```javascript
|
|
// Before
|
|
import Database from 'better-sqlite3';
|
|
const db = new Database('path/to/db.sqlite');
|
|
|
|
// After
|
|
import { createDatabase } from './sqlite-wrapper.js';
|
|
const db = await createDatabase('path/to/db.sqlite');
|
|
```
|
|
|
|
### Pattern 2: Dynamic Import
|
|
```javascript
|
|
// Before
|
|
const Database = (await import('better-sqlite3')).default;
|
|
|
|
// After
|
|
const { createDatabase } = await import('./sqlite-wrapper.js');
|
|
const db = await createDatabase(dbPath);
|
|
```
|
|
|
|
### Pattern 3: Require
|
|
```javascript
|
|
// Before
|
|
const Database = require('better-sqlite3');
|
|
|
|
// After
|
|
const { createDatabase } = require('./sqlite-wrapper.js');
|
|
// (or migrate to ESM)
|
|
```
|
|
|
|
---
|
|
|
|
## Validation Checklist
|
|
|
|
### Pre-Migration
|
|
- [ ] All 17 files catalogued
|
|
- [ ] Dependencies mapped
|
|
- [ ] Test coverage baseline established
|
|
- [ ] Performance benchmarks collected
|
|
|
|
### During Migration
|
|
- [ ] sqlite-wrapper.js supports sql.js
|
|
- [ ] Provider selection logic implemented
|
|
- [ ] All files migrated to use abstraction
|
|
- [ ] Tests passing on all platforms
|
|
|
|
### Post-Migration
|
|
- [ ] Windows installation success rate >95%
|
|
- [ ] Performance within 2-5x of better-sqlite3
|
|
- [ ] No regressions on Linux/macOS
|
|
- [ ] Documentation updated
|
|
|
|
---
|
|
|
|
**Document Version**: 1.0
|
|
**Last Updated**: 2026-01-03
|
|
**Status**: Complete inventory for migration planning
|