🌊 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
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
Checkpoint: File edits
rUv1815c63b3949
diff --git a/v3/@claude-flow/cli/src/commands/daemon.ts b/v3/@claude-flow/cli/src/commands/daemon.tsindex cfedd91cdb..dd4665010c 100644--- a/v3/@claude-flow/cli/src/commands/daemon.ts+++ b/v3/@claude-flow/cli/src/commands/daemon.ts@@ -138,44 +138,54 @@ async function startBackgroundDaemon(projectRoot: string, quiet: boolean): Promi// dist/src/commands -> dist/src -> dist -> package root -> bin/cli.jsconst cliPath = join(__dirname, '..', '..', '..', 'bin', 'cli.js');- // Open log file for daemon output- const logFd = fs.openSync(logFile, 'a');-// Verify CLI path existsif (!fs.existsSync(cliPath)) {- fs.closeSync(logFd);output.printError(`CLI not found at: ${cliPath}`);return { success: false, exitCode: 1 };}- // Spawn detached child process running daemon in foreground mode- const child = spawn(- process.execPath,- [cliPath, 'daemon', 'start', '--foreground', '--quiet'],- {- cwd: projectRoot,- detached: true,- stdio: ['ignore', logFd, logFd],- env: { ...process.env, CLAUDE_FLOW_DAEMON: '1' },- }- );-- // Unref so parent can exit- child.unref();+ // Use shell to spawn daemon with proper output redirection+ // This ensures the log file stays open even after parent exits+ const shellCmd = `"${process.execPath}" "${cliPath}" daemon start --foreground --quiet >> "${logFile}" 2>&1 & echo $!`;++ const child = spawn('sh', ['-c', shellCmd], {+ cwd: projectRoot,+ detached: true,+ stdio: ['ignore', 'pipe', 'ignore'],+ env: { ...process.env, CLAUDE_FLOW_DAEMON: '1' },+ });++ // Wait for the PID to be echoed back+ return new Promise((resolve) => {+ let pidStr = '';+ child.stdout?.on('data', (data: Buffer) => {+ pidStr += data.toString();+ });++ child.on('close', () => {+ const pid = parseInt(pidStr.trim(), 10);++ if (isNaN(pid) || pid <= 0) {+ output.printError('Failed to get daemon PID');+ resolve({ success: false, exitCode: 1 });+ return;+ }- // Save PID- fs.writeFileSync(pidFile, String(child.pid));+ // Save PID+ fs.writeFileSync(pidFile, String(pid));- // Note: Do NOT close logFd here - it would kill the child's stdout/stderr- // The fd will be automatically closed when this process exits+ if (!quiet) {+ output.printSuccess(`Daemon started in background (PID: ${pid})`);+ output.printInfo(`Logs: ${logFile}`);+ output.printInfo(`Stop with: claude-flow daemon stop`);+ }- if (!quiet) {- output.printSuccess(`Daemon started in background (PID: ${child.pid})`);- output.printInfo(`Logs: ${logFile}`);- output.printInfo(`Stop with: claude-flow daemon stop`);- }+ resolve({ success: true });+ });- return { success: true };+ // Unref so parent can exit immediately+ child.unref();+ });}// Stop daemon subcommanddiff --git a/v3/@claude-flow/embeddings/src/embedding-service.ts b/v3/@claude-flow/embeddings/src/embedding-service.tsindex 0160488a28..2d69e43114 100644--- a/v3/@claude-flow/embeddings/src/embedding-service.ts+++ b/v3/@claude-flow/embeddings/src/embedding-service.ts@@ -533,6 +533,223 @@ export class MockEmbeddingService extends BaseEmbeddingService {}}+// ============================================================================+// Agentic-Flow Embedding Service+// ============================================================================++/**+ * Agentic-Flow embedding service using OptimizedEmbedder+ *+ * Features:+ * - ONNX-based embeddings with SIMD acceleration+ * - 256-entry LRU cache with FNV-1a hash+ * - 8x loop unrolling for cosine similarity+ * - Pre-allocated buffers (no GC pressure)+ * - 3-4x faster batch processing+ */+export class AgenticFlowEmbeddingService extends BaseEmbeddingService {+ readonly provider: EmbeddingProvider = 'agentic-flow';+ private embedder: any = null;+ private initialized = false;+ private readonly modelId: string;+ private readonly dimensions: number;+ private readonly embedderCacheSize: number;+ private readonly modelDir: string | undefined;+ private readonly autoDownload: boolean;++ constructor(config: AgenticFlowEmbeddingConfig) {+ super(config);+ this.modelId = config.modelId ?? 'all-MiniLM-L6-v2';+ this.dimensions = config.dimensions ?? 384;+ this.embedderCacheSize = config.embedderCacheSize ?? 256;+ this.modelDir = config.modelDir;+ this.autoDownload = config.autoDownload ?? false;+ }++ private async initialize(): Promise<void> {+ if (this.initialized) return;++ try {+ // Try to import from agentic-flow package+ const { getOptimizedEmbedder } = await import('agentic-flow/dist/embeddings/optimized-embedder.js');++ this.embedder = getOptimizedEmbedder({+ modelId: this.modelId,+ dimension: this.dimensions,+ cacheSize: this.embedderCacheSize,+ modelDir: this.modelDir,+ autoDownload: this.autoDownload,+ });++ await this.embedder.init();+ this.initialized = true;+ } catch (error) {+ // Fallback: try node_modules path resolution+ try {+ const path = await import('path');+ const { fileURLToPath } = await import('url');+ const __dirname = path.dirname(fileURLToPath(import.meta.url));++ // Look for agentic-flow in parent node_modules+ const possiblePaths = [+ path.resolve(__dirname, '../../../../node_modules/agentic-flow/dist/embeddings/optimized-embedder.js'),+ path.resolve(__dirname, '../../../../../node_modules/agentic-flow/dist/embeddings/optimized-embedder.js'),+ path.resolve(process.cwd(), 'node_modules/agentic-flow/dist/embeddings/optimized-embedder.js'),+ ];++ let loaded = false;+ for (const modulePath of possiblePaths) {+ try {+ const { getOptimizedEmbedder } = await import(modulePath);+ this.embedder = getOptimizedEmbedder({+ modelId: this.modelId,+ dimension: this.dimensions,+ cacheSize: this.embedderCacheSize,+ modelDir: this.modelDir,+ autoDownload: this.autoDownload,+ });+ await this.embedder.init();+ this.initialized = true;+ loaded = true;+ break;+ } catch {+ continue;+ }+ }++ if (!loaded) {+ throw new Error('Could not find agentic-flow embeddings module');+ }+ } catch (fallbackError) {+ throw new Error(+ `Failed to initialize agentic-flow embeddings: ${error}. ` ++ `Ensure agentic-flow is installed and ONNX model is downloaded: ` ++ `npx agentic-flow@alpha embeddings init`+ );+ }+ }+ }++ async embed(text: string): Promise<EmbeddingResult> {+ await this.initialize();++ // Check our LRU cache first+ const cached = this.cache.get(text);+ if (cached) {+ this.emitEvent({ type: 'cache_hit', text });+ return {+ embedding: cached,+ latencyMs: 0,+ cached: true,+ };+ }++ this.emitEvent({ type: 'embed_start', text });+ const startTime = performance.now();++ try {+ // Use agentic-flow's optimized embedder (has its own internal cache)+ const embedding = await this.embedder.embed(text);++ // Store in our cache as well+ this.cache.set(text, embedding);++ const latencyMs = performance.now() - startTime;+ this.emitEvent({ type: 'embed_complete', text, latencyMs });++ return {+ embedding,+ latencyMs,+ };+ } catch (error) {+ const message = error instanceof Error ? error.message : 'Unknown error';+ this.emitEvent({ type: 'embed_error', text, error: message });+ throw new Error(`Agentic-flow embedding failed: ${message}`);+ }+ }++ async embedBatch(texts: string[]): Promise<BatchEmbeddingResult> {+ await this.initialize();++ this.emitEvent({ type: 'batch_start', count: texts.length });+ const startTime = performance.now();++ // Check cache for each text+ const cached: Array<{ index: number; embedding: Float32Array }> = [];+ const uncached: Array<{ index: number; text: string }> = [];++ texts.forEach((text, index) => {+ const cachedEmbedding = this.cache.get(text);+ if (cachedEmbedding) {+ cached.push({ index, embedding: cachedEmbedding });+ this.emitEvent({ type: 'cache_hit', text });+ } else {+ uncached.push({ index, text });+ }+ });++ // Use optimized batch embedding for uncached texts+ let batchEmbeddings: Float32Array[] = [];+ if (uncached.length > 0) {+ const uncachedTexts = uncached.map(u => u.text);+ batchEmbeddings = await this.embedder.embedBatch(uncachedTexts);++ // Cache results+ uncached.forEach((item, i) => {+ this.cache.set(item.text, batchEmbeddings[i]);+ });+ }++ // Reconstruct result array in original order+ const embeddings: Float32Array[] = new Array(texts.length);+ cached.forEach(c => {+ embeddings[c.index] = c.embedding;+ });+ uncached.forEach((u, i) => {+ embeddings[u.index] = batchEmbeddings[i];+ });++ const totalLatencyMs = performance.now() - startTime;+ this.emitEvent({ type: 'batch_complete', count: texts.length, latencyMs: totalLatencyMs });++ return {+ embeddings,+ totalLatencyMs,+ avgLatencyMs: totalLatencyMs / texts.length,+ cacheStats: {+ hits: cached.length,+ misses: uncached.length,+ },+ };+ }++ /**+ * Get combined cache statistics from both our LRU cache and embedder's internal cache+ */+ override getCacheStats() {+ const baseStats = super.getCacheStats();++ if (this.embedder && this.embedder.getCacheStats) {+ const embedderStats = this.embedder.getCacheStats();+ return {+ size: baseStats.size + embedderStats.size,+ maxSize: baseStats.maxSize + embedderStats.maxSize,+ hitRate: baseStats.hitRate,+ embedderCache: embedderStats,+ };+ }++ return baseStats;+ }++ override async shutdown(): Promise<void> {+ if (this.embedder && this.embedder.clearCache) {+ this.embedder.clearCache();+ }+ await super.shutdown();+ }+}+// ============================================================================// Factory Functions// ============================================================================@@ -548,6 +765,8 @@ export function createEmbeddingService(config: EmbeddingConfig): IEmbeddingServireturn new TransformersEmbeddingService(config as TransformersEmbeddingConfig);case 'mock':return new MockEmbeddingService(config as MockEmbeddingConfig);+ case 'agentic-flow':+ return new AgenticFlowEmbeddingService(config as AgenticFlowEmbeddingConfig);default:console.warn(`Unknown provider, using mock`);return new MockEmbeddingService({ provider: 'mock', dimensions: 384 });