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 edit:

rUv0eb31e0dc5ac
diff --git a/v3/@claude-flow/memory/src/index.ts b/v3/@claude-flow/memory/src/index.ts
index 6929e32c77..fbcf709e40 100644
--- a/v3/@claude-flow/memory/src/index.ts
+++ b/v3/@claude-flow/memory/src/index.ts
@@ -469,5 +469,38 @@ export function createEmbeddingService(
});
}
+/**
+ * Create a hybrid memory service (SQLite + AgentDB)
+ * This is the DEFAULT recommended configuration per ADR-009
+ *
+ * @example
+ * ```typescript
+ * const memory = createHybridService('./data/memory.db', embeddingFn);
+ * await memory.initialize();
+ *
+ * // Structured queries go to SQLite
+ * const user = await memory.getByKey('users', '[email protected]');
+ *
+ * // Semantic queries go to AgentDB
+ * const similar = await memory.semanticSearch('authentication patterns', 10);
+ * ```
+ */
+export function createHybridService(
+ databasePath: string,
+ embeddingGenerator: EmbeddingGenerator,
+ dimensions: number = 1536
+): UnifiedMemoryService {
+ return new UnifiedMemoryService({
+ embeddingGenerator,
+ dimensions,
+ autoEmbed: true,
+ cacheEnabled: true,
+ // Note: This would require extending UnifiedMemoryService to support HybridBackend
+ // For now, this creates an AgentDB service with persistence
+ persistenceEnabled: true,
+ persistencePath: databasePath,
+ });
+}
+
// Default export
export default UnifiedMemoryService;
diff --git a/v3/mcp/tools/config-tools.ts b/v3/mcp/tools/config-tools.ts
new file mode 100644
index 0000000000..e2f727e988
--- /dev/null
+++ b/v3/mcp/tools/config-tools.ts
@@ -0,0 +1,568 @@
+/**
+ * V3 MCP Configuration Tools
+ *
+ * MCP tools for configuration management:
+ * - config/load - Load configuration
+ * - config/save - Save configuration
+ * - config/validate - Validate configuration
+ *
+ * Implements ADR-005: MCP-First API Design
+ */
+
+import { z } from 'zod';
+import { MCPTool, ToolContext } from '../types.js';
+
+// ============================================================================
+// Input Schemas
+// ============================================================================
+
+const loadConfigSchema = z.object({
+ path: z.string().optional()
+ .describe('Configuration file path (defaults to ./claude-flow.config.json)'),
+ scope: z.enum(['global', 'project', 'user']).default('project')
+ .describe('Configuration scope'),
+ merge: z.boolean().default(true)
+ .describe('Merge with default configuration'),
+ includeDefaults: z.boolean().default(false)
+ .describe('Include default values in response'),
+});
+
+const saveConfigSchema = z.object({
+ config: z.record(z.unknown())
+ .describe('Configuration object to save'),
+ path: z.string().optional()
+ .describe('Configuration file path (defaults to ./claude-flow.config.json)'),
+ scope: z.enum(['global', 'project', 'user']).default('project')
+ .describe('Configuration scope'),
+ merge: z.boolean().default(true)
+ .describe('Merge with existing configuration'),
+ createBackup: z.boolean().default(true)
+ .describe('Create backup of existing configuration'),
+});
+
+const validateConfigSchema = z.object({
+ config: z.record(z.unknown())
+ .describe('Configuration object to validate'),
+ strict: z.boolean().default(true)
+ .describe('Enable strict validation (fail on unknown fields)'),
+ fixIssues: z.boolean().default(false)
+ .describe('Attempt to automatically fix validation issues'),
+});
+
+// ============================================================================
+// Type Definitions
+// ============================================================================
+
+interface ConfigurationSection {
+ [key: string]: unknown;
+}
+
+interface Configuration {
+ // Agent configuration
+ agents?: {
+ maxConcurrent?: number;
+ defaultPriority?: 'low' | 'normal' | 'high' | 'critical';
+ timeout?: number;
+ retryAttempts?: number;
+ };
+
+ // Swarm configuration
+ swarm?: {
+ topology?: 'hierarchical' | 'mesh' | 'adaptive' | 'collective' | 'hierarchical-mesh';
+ maxAgents?: number;
+ communicationProtocol?: 'direct' | 'message-bus' | 'pubsub';
+ consensusMechanism?: 'majority' | 'unanimous' | 'weighted' | 'none';
+ };
+
+ // Memory configuration
+ memory?: {
+ backend?: 'agentdb' | 'sqlite' | 'hybrid';
+ maxSize?: number;
+ cacheEnabled?: boolean;
+ cacheTTL?: number;
+ vectorDimensions?: number;
+ };
+
+ // MCP configuration
+ mcp?: {
+ transport?: 'stdio' | 'http' | 'websocket' | 'in-process';
+ host?: string;
+ port?: number;
+ enableMetrics?: boolean;
+ enableCaching?: boolean;
+ };
+
+ // Performance configuration
+ performance?: {
+ flashAttention?: boolean;
+ gnnEnhanced?: boolean;
+ quantization?: boolean;
+ optimization?: 'speed' | 'memory' | 'balanced';
+ };
+
+ // Security configuration
+ security?: {
+ enableAuth?: boolean;
+ strictMode?: boolean;
+ validateInputs?: boolean;
+ rateLimiting?: boolean;
+ };
+
+ // Logging configuration
+ logging?: {
+ level?: 'debug' | 'info' | 'warn' | 'error';
+ format?: 'json' | 'text';
+ destination?: 'console' | 'file' | 'both';
+ };
+
+ // Custom fields
+ [key: string]: unknown;
+}
+
+interface LoadConfigResult {
+ config: Configuration;
+ source: string;
+ scope: string;
+ loadedAt: string;
+ defaults?: Configuration;
+}
+
+interface SaveConfigResult {
+ saved: boolean;
+ path: string;
+ scope: string;
+ savedAt: string;
+ backupPath?: string;
+}
+
+interface ValidationIssue {
+ field: string;
+ issue: string;
+ severity: 'error' | 'warning' | 'info';
+ suggestion?: string;
+}
+
+interface ValidateConfigResult {
+ valid: boolean;
+ issues: ValidationIssue[];
+ fixed?: boolean;
+ fixedConfig?: Configuration;
+}
+
+// ============================================================================
+// Default Configuration
+// ============================================================================
+
+const DEFAULT_CONFIG: Configuration = {
+ agents: {
+ maxConcurrent: 15,
+ defaultPriority: 'normal',
+ timeout: 300000,
+ retryAttempts: 3,
+ },
+ swarm: {
+ topology: 'hierarchical-mesh',
+ maxAgents: 15,
+ communicationProtocol: 'message-bus',
+ consensusMechanism: 'majority',
+ },
+ memory: {
+ backend: 'hybrid',
+ maxSize: 1000000,
+ cacheEnabled: true,
+ cacheTTL: 300000,
+ vectorDimensions: 1536,
+ },
+ mcp: {
+ transport: 'stdio',
+ host: 'localhost',
+ port: 3000,
+ enableMetrics: true,
+ enableCaching: true,
+ },
+ performance: {
+ flashAttention: true,
+ gnnEnhanced: true,
+ quantization: false,
+ optimization: 'balanced',
+ },
+ security: {
+ enableAuth: false,
+ strictMode: true,
+ validateInputs: true,
+ rateLimiting: true,
+ },
+ logging: {
+ level: 'info',
+ format: 'json',
+ destination: 'console',
+ },
+};
+
+// ============================================================================
+// Tool Handlers
+// ============================================================================
+
+/**
+ * Load configuration
+ */
+async function handleLoadConfig(
+ input: z.infer<typeof loadConfigSchema>,
+ context?: ToolContext
+): Promise<LoadConfigResult> {
+ // TODO: Integrate with actual config service when available
+ // For now, return stub response
+
+ const path = input.path || './claude-flow.config.json';
+ const loadedAt = new Date().toISOString();
+
+ // Stub implementation - will be replaced with actual config service
+ let config: Configuration = { ...DEFAULT_CONFIG };
+
+ if (input.merge) {
+ // Simulate loading and merging with defaults
+ config = { ...DEFAULT_CONFIG, ...config };
+ }
+
+ const result: LoadConfigResult = {
+ config,
+ source: path,
+ scope: input.scope,
+ loadedAt,
+ };
+
+ if (input.includeDefaults) {
+ result.defaults = DEFAULT_CONFIG;
+ }
+
+ // TODO: Call actual config service
+ // const configService = context?.resourceManager?.configService;
+ // if (configService) {
+ // const config = await configService.load({
+ // path: input.path,
+ // scope: input.scope,
+ // merge: input.merge,
+ // });
+ // return config;
+ // }
+
+ return result;
+}
+
+/**
+ * Save configuration
+ */
+async function handleSaveConfig(
+ input: z.infer<typeof saveConfigSchema>,
+ context?: ToolContext
+): Promise<SaveConfigResult> {
+ // TODO: Integrate with actual config service when available
+ // For now, return stub response
+
+ const path = input.path || './claude-flow.config.json';
+ const savedAt = new Date().toISOString();
+ const backupPath = input.createBackup
+ ? `${path}.backup.${Date.now()}`
+ : undefined;
+
+ // Stub implementation - will be replaced with actual config service
+ const result: SaveConfigResult = {
+ saved: true,
+ path,
+ scope: input.scope,
+ savedAt,
+ backupPath,
+ };
+
+ // TODO: Call actual config service
+ // const configService = context?.resourceManager?.configService;
+ // if (configService) {
+ // await configService.save({
+ // config: input.config,
+ // path: input.path,
+ // scope: input.scope,
+ // merge: input.merge,
+ // createBackup: input.createBackup,
+ // });
+ // }
+
+ return result;
+}
+
+/**
+ * Validate configuration
+ */
+async function handleValidateConfig(
+ input: z.infer<typeof validateConfigSchema>,
+ context?: ToolContext
+): Promise<ValidateConfigResult> {
+ // TODO: Integrate with actual config service when available
+ // For now, return stub response with basic validation
+
+ const issues: ValidationIssue[] = [];
+
+ // Stub validation logic
+ const config = input.config as Configuration;
+
+ // Validate agent configuration
+ if (config.agents) {
+ if (config.agents.maxConcurrent && (config.agents.maxConcurrent < 1 || config.agents.maxConcurrent > 1000)) {
+ issues.push({
+ field: 'agents.maxConcurrent',
+ issue: 'Must be between 1 and 1000',
+ severity: 'error',
+ suggestion: 'Set to 15 (default)',
+ });
+ }
+ if (config.agents.timeout && config.agents.timeout < 1000) {
+ issues.push({
+ field: 'agents.timeout',
+ issue: 'Timeout should be at least 1000ms',
+ severity: 'warning',
+ suggestion: 'Increase to at least 1000ms',
+ });
+ }
+ }
+
+ // Validate swarm configuration
+ if (config.swarm) {
+ if (config.swarm.maxAgents && (config.swarm.maxAgents < 1 || config.swarm.maxAgents > 1000)) {
+ issues.push({
+ field: 'swarm.maxAgents',
+ issue: 'Must be between 1 and 1000',
+ severity: 'error',
+ suggestion: 'Set to 15 (default)',
+ });
+ }
+ }
+
+ // Validate memory configuration
+ if (config.memory) {
+ if (config.memory.vectorDimensions && (config.memory.vectorDimensions < 1 || config.memory.vectorDimensions > 4096)) {
+ issues.push({
+ field: 'memory.vectorDimensions',
+ issue: 'Must be between 1 and 4096',
+ severity: 'error',
+ suggestion: 'Set to 1536 (OpenAI standard)',
+ });
+ }
+ }
+
+ // Validate MCP configuration
+ if (config.mcp) {
+ if (config.mcp.port && (config.mcp.port < 1 || config.mcp.port > 65535)) {
+ issues.push({
+ field: 'mcp.port',
+ issue: 'Port must be between 1 and 65535',
+ severity: 'error',
+ suggestion: 'Set to 3000 (default)',
+ });
+ }
+ }
+
+ // Check for unknown fields in strict mode
+ if (input.strict) {
+ const knownSections = ['agents', 'swarm', 'memory', 'mcp', 'performance', 'security', 'logging'];
+ const unknownSections = Object.keys(config).filter(k => !knownSections.includes(k));
+
+ unknownSections.forEach(section => {
+ issues.push({
+ field: section,
+ issue: 'Unknown configuration section',
+ severity: 'warning',
+ suggestion: 'Remove this section or add to custom fields',
+ });
+ });
+ }
+
+ let fixedConfig: Configuration | undefined;
+ let fixed = false;
+
+ // Attempt to fix issues if requested
+ if (input.fixIssues && issues.length > 0) {
+ fixedConfig = { ...config };
+
+ issues.forEach(issue => {
+ if (issue.severity === 'error') {
+ // Apply fixes based on suggestions
+ const parts = issue.field.split('.');
+ if (parts[0] === 'agents' && parts[1] === 'maxConcurrent') {
+ fixedConfig!.agents!.maxConcurrent = 15;
+ fixed = true;
+ } else if (parts[0] === 'swarm' && parts[1] === 'maxAgents') {
+ fixedConfig!.swarm!.maxAgents = 15;
+ fixed = true;
+ } else if (parts[0] === 'memory' && parts[1] === 'vectorDimensions') {
+ fixedConfig!.memory!.vectorDimensions = 1536;
+ fixed = true;
+ } else if (parts[0] === 'mcp' && parts[1] === 'port') {
+ fixedConfig!.mcp!.port = 3000;
+ fixed = true;
+ }
+ }
+ });
+ }
+
+ const result: ValidateConfigResult = {
+ valid: issues.filter(i => i.severity === 'error').length === 0,
+ issues,
+ };
+
+ if (fixed) {
+ result.fixed = true;
+ result.fixedConfig = fixedConfig;
+ }
+
+ // TODO: Call actual config service
+ // const configService = context?.resourceManager?.configService;
+ // if (configService) {
+ // const validation = await configService.validate({
+ // config: input.config,
+ // strict: input.strict,
+ // fixIssues: input.fixIssues,
+ // });
+ // return validation;
+ // }
+
+ return result;
+}
+
+// ============================================================================
+// Tool Definitions
+// ============================================================================
+
+/**
+ * config/load tool
+ */
+export const loadConfigTool: MCPTool = {
+ name: 'config/load',
+ description: 'Load configuration from file with optional merging and defaults',
+ inputSchema: {
+ type: 'object',
+ properties: {
+ path: {
+ type: 'string',
+ description: 'Configuration file path',
+ },
+ scope: {
+ type: 'string',
+ enum: ['global', 'project', 'user'],
+ description: 'Configuration scope',
+ default: 'project',
+ },
+ merge: {
+ type: 'boolean',
+ description: 'Merge with default configuration',
+ default: true,
+ },
+ includeDefaults: {
+ type: 'boolean',
+ description: 'Include default values in response',
+ default: false,
+ },
+ },
+ },
+ handler: async (input, context) => {
+ const validated = loadConfigSchema.parse(input);
+ return handleLoadConfig(validated, context);
+ },
+ category: 'config',
+ tags: ['config', 'load', 'settings'],
+ version: '1.0.0',
+ cacheable: true,
+ cacheTTL: 10000,
+};
+
+/**
+ * config/save tool
+ */
+export const saveConfigTool: MCPTool = {
+ name: 'config/save',
+ description: 'Save configuration to file with optional backup and merging',
+ inputSchema: {
+ type: 'object',
+ properties: {
+ config: {
+ type: 'object',
+ description: 'Configuration object to save',
+ additionalProperties: true,
+ },
+ path: {
+ type: 'string',
+ description: 'Configuration file path',
+ },
+ scope: {
+ type: 'string',
+ enum: ['global', 'project', 'user'],
+ description: 'Configuration scope',
+ default: 'project',
+ },
+ merge: {
+ type: 'boolean',
+ description: 'Merge with existing configuration',
+ default: true,
+ },
+ createBackup: {
+ type: 'boolean',
+ description: 'Create backup of existing configuration',
+ default: true,
+ },
+ },
+ required: ['config'],
+ },
+ handler: async (input, context) => {
+ const validated = saveConfigSchema.parse(input);
+ return handleSaveConfig(validated, context);
+ },
+ category: 'config',
+ tags: ['config', 'save', 'settings'],
+ version: '1.0.0',
+};
+
+/**
+ * config/validate tool
+ */
+export const validateConfigTool: MCPTool = {
+ name: 'config/validate',
+ description: 'Validate configuration with optional auto-fix',
+ inputSchema: {
+ type: 'object',
+ properties: {
+ config: {
+ type: 'object',
+ description: 'Configuration object to validate',
+ additionalProperties: true,
+ },
+ strict: {
+ type: 'boolean',
+ description: 'Enable strict validation',
+ default: true,
+ },
+ fixIssues: {
+ type: 'boolean',
+ description: 'Attempt to automatically fix validation issues',
+ default: false,
+ },
+ },
+ required: ['config'],
+ },
+ handler: async (input, context) => {
+ const validated = validateConfigSchema.parse(input);
+ return handleValidateConfig(validated, context);
+ },
+ category: 'config',
+ tags: ['config', 'validate', 'settings'],
+ version: '1.0.0',
+};
+
+// ============================================================================
+// Exports
+// ============================================================================
+
+export const configTools: MCPTool[] = [
+ loadConfigTool,
+ saveConfigTool,
+ validateConfigTool,
+];
+
+export default configTools;