mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-24 06:06:02 +09:00
* feat: native ruvllm + graph-node intelligence backends (ADR-086, ADR-087) Wire @ruvector/ruvllm as intelligence coordinator (SonaCoordinator, ContrastiveTrainer, TrainingPipeline) and @ruvector/graph-node as native graph database for agent relationships and causal edges. - Fix ESM/CJS import: use createRequire pattern for CJS packages - Eager loading of all backends during initialization - Wire into neural status, hooks_intelligence, ruvllm_status CLI/MCP - Auto-trigger background learning on trajectory-end - Auto-save LoRA checkpoints after neural train - Graph-node records agents on spawn, causal edges, swarm teams - Fix community issues #1511, #1509, #1507, #1506, #1505 - Real Product Quantization with k-means trained codebooks - SONA native routing with 5-tier fallback - Embedding fallback transparency warnings - Plugin peer dep fixes (semver ranges, removed phantom deps) 32 test files, 1762 tests passing, 0 regressions. Co-Authored-By: claude-flow <ruv@ruv.net> * chore: release v3.5.74 Co-Authored-By: claude-flow <ruv@ruv.net> * fix: saveCheckpoint verifies file existence, falls through to JS fallback (v3.5.75) ruvllm's TrainingPipeline.saveCheckpoint() is a no-op that writes nothing to disk. Added fs.existsSync check after ruvllm call so the JS JSON fallback activates and writes real checkpoint data (5811 bytes). Co-Authored-By: claude-flow <ruv@ruv.net> * fix: ESM require crashes, cleanup data loss, CLI hang, daemon zombies, memory CWD (#1559, #1557, #1552, #1551, #1562) - Replace bare require() with ESM imports in autopilot-state.ts, commands/autopilot.ts, commands/claims.ts — fixes ReferenceError on clean install (#1559, #1560, #1561, #1563) - Cleanup command no longer deletes entire .claude/ directory — only removes ruflo-owned paths (.claude/helpers/, .claude-flow/, .swarm/, etc.) and surgically strips hooks/claudeFlow from settings.json, preserving Claude Code's agents, skills, settings.local.json (#1557) - Add process.exit(0) after cli.run() resolves — prevents one-shot commands from hanging due to open DB connections/timers (#1552) - Daemon start kills stale daemon processes not tracked by PID file, daemon stop also cleans up zombies via ps lookup (#1551) - Auto-memory bridge respects CLAUDE_FLOW_CWD env var for MCP/Claude Desktop environments (#1562) Co-Authored-By: claude-flow <ruv@ruv.net> --------- Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
173 lines
4.8 KiB
JavaScript
Executable File
173 lines
4.8 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* @claude-flow/cli - CLI Entry Point
|
|
*
|
|
* Claude Flow V3 Command Line Interface
|
|
*
|
|
* Auto-detects MCP mode when stdin is piped and no args provided.
|
|
* This allows: echo '{"jsonrpc":"2.0",...}' | npx @claude-flow/cli
|
|
*/
|
|
|
|
import { randomUUID } from 'crypto';
|
|
|
|
// Suppress noisy [AgentDB Patch] warnings from agentic-flow's runtime patch
|
|
// These are cosmetic — the patch tries to fix agentdb v1.x imports but we use v3
|
|
const _origWarn = console.warn;
|
|
console.warn = (...args) => {
|
|
const msg = String(args[0] ?? '');
|
|
if (msg.includes('[AgentDB Patch]')) return;
|
|
_origWarn.apply(console, args);
|
|
};
|
|
|
|
// Check if we should run in MCP server mode
|
|
// Conditions:
|
|
// 1. stdin is being piped AND no CLI arguments provided (auto-detect)
|
|
// 2. stdin is being piped AND args are "mcp start" (explicit, e.g. npx claude-flow@alpha mcp start)
|
|
const cliArgs = process.argv.slice(2);
|
|
const isExplicitMCP = cliArgs.length >= 1 && cliArgs[0] === 'mcp' && (cliArgs.length === 1 || cliArgs[1] === 'start');
|
|
const isMCPMode = !process.stdin.isTTY && (process.argv.length === 2 || isExplicitMCP);
|
|
|
|
if (isMCPMode) {
|
|
// Run MCP server mode
|
|
const { listMCPTools, callMCPTool, hasTool } = await import('../dist/src/mcp-client.js');
|
|
|
|
const VERSION = '3.0.0';
|
|
const sessionId = `mcp-${Date.now()}-${randomUUID().slice(0, 8)}`;
|
|
|
|
console.error(
|
|
`[${new Date().toISOString()}] INFO [claude-flow-mcp] (${sessionId}) Starting in stdio mode`
|
|
);
|
|
|
|
let buffer = '';
|
|
process.stdin.setEncoding('utf8');
|
|
process.stdin.on('data', async (chunk) => {
|
|
buffer += chunk;
|
|
let lines = buffer.split('\n');
|
|
buffer = lines.pop() || '';
|
|
|
|
for (const line of lines) {
|
|
if (line.trim()) {
|
|
try {
|
|
const message = JSON.parse(line);
|
|
const response = await handleMessage(message);
|
|
if (response) {
|
|
console.log(JSON.stringify(response));
|
|
}
|
|
} catch (error) {
|
|
console.log(JSON.stringify({
|
|
jsonrpc: '2.0',
|
|
id: null,
|
|
error: { code: -32700, message: 'Parse error' },
|
|
}));
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
process.stdin.on('end', () => {
|
|
process.exit(0);
|
|
});
|
|
|
|
async function handleMessage(message) {
|
|
if (!message.method) {
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
error: { code: -32600, message: 'Invalid Request: missing method' },
|
|
};
|
|
}
|
|
|
|
const params = message.params || {};
|
|
|
|
switch (message.method) {
|
|
case 'initialize':
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
result: {
|
|
protocolVersion: '2024-11-05',
|
|
serverInfo: { name: 'claude-flow', version: VERSION },
|
|
capabilities: {
|
|
tools: { listChanged: true },
|
|
resources: { subscribe: true, listChanged: true },
|
|
},
|
|
},
|
|
};
|
|
|
|
case 'tools/list': {
|
|
const tools = listMCPTools();
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
result: {
|
|
tools: tools.map(tool => ({
|
|
name: tool.name,
|
|
description: tool.description,
|
|
inputSchema: tool.inputSchema,
|
|
})),
|
|
},
|
|
};
|
|
}
|
|
|
|
case 'tools/call': {
|
|
const toolName = params.name;
|
|
const toolParams = params.arguments || {};
|
|
|
|
if (!hasTool(toolName)) {
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
error: { code: -32601, message: `Tool not found: ${toolName}` },
|
|
};
|
|
}
|
|
|
|
try {
|
|
const result = await callMCPTool(toolName, toolParams, { sessionId });
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
result: { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] },
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
error: {
|
|
code: -32603,
|
|
message: error instanceof Error ? error.message : 'Tool execution failed',
|
|
},
|
|
};
|
|
}
|
|
}
|
|
|
|
case 'notifications/initialized':
|
|
return null;
|
|
|
|
case 'ping':
|
|
return { jsonrpc: '2.0', id: message.id, result: {} };
|
|
|
|
default:
|
|
return {
|
|
jsonrpc: '2.0',
|
|
id: message.id,
|
|
error: { code: -32601, message: `Method not found: ${message.method}` },
|
|
};
|
|
}
|
|
}
|
|
} else {
|
|
// Run normal CLI mode
|
|
const { CLI } = await import('../dist/src/index.js');
|
|
const cli = new CLI();
|
|
cli.run()
|
|
.then(() => {
|
|
// #1552: Exit cleanly after one-shot commands.
|
|
// Long-running commands (daemon foreground, mcp, status --watch) never resolve,
|
|
// so this only fires for normal CLI commands.
|
|
process.exit(0);
|
|
})
|
|
.catch((error) => {
|
|
console.error('Fatal error:', error.message);
|
|
process.exit(1);
|
|
});
|
|
}
|