Files
ruflo/v3/@claude-flow/cli/src/config-adapter.ts
T
ReuvenandRuFlo 1884ed1010 fix(3.7.0-alpha.12): batch resolve issue-fix loop #1839-#1847
Closes #1839, #1840, #1841, #1842, #1843, #1844, #1845, #1846, #1847.

#1839 — bin/cli.js, bin/mcp-server.js, config-adapter.ts: rename
  serverInfo.name 'claude-flow' → 'ruflo' so MCP wire identity matches the
  package name. Live probe of `ruflo mcp start` now returns
  `serverInfo.name="ruflo"` (verified post-build).

#1840 — init/executor.ts: detectExistingRufloMCP() now also walks
  parsed.projects[*].mcpServers.ruflo with normalized path matching
  (lowercase + forward-slash) so `claude mcp add ruflo` registrations
  stored project-scoped in ~/.claude.json are detected and init skips
  writing a duplicate .mcp.json.

#1841 — init/mcp-generator.ts: generated .mcp.json now keys
  `mcpServers.ruflo` instead of legacy `mcpServers['claude-flow']`. The
  printed `claude mcp add` instructions match. Prevents the
  duplicate-tool-prefix problem when init runs over an existing ruflo
  registration.

#1842 — commands/doctor.ts: checkMcpServers() now traverses
  ~/.claude.json.projects[*].mcpServers in addition to top-level
  mcpServers, so doctor stops warning "No MCP config found" when a
  working project-scoped ruflo registration exists.

#1843 — mcp-tools/system-tools.ts: exclude `unknown` from health
  denominator (was dragging the score down even when actionable checks
  were green) and surface as `advisory` count. Add YAML config and
  sql.js/HNSW/.swarm/ruvector memory paths to detection. Local probe:
  4 healthy / 5 actionable = 80% (was 4/8 = 50%) with 3 advisory.

#1844 — services/worker-daemon.ts: WorkerDaemon now reads
  .claude-flow/config.yaml (and .yml) when config.json is absent, with
  lazy `yaml` import so missing dep falls back to a clear warning.
  Adds yaml@^2.8.0 to runtime deps. Logs the chosen source.

#1845 — services/worker-daemon.ts + mcp-tools/hooks-tools.ts: durable
  queue boundary between MCP dispatch and daemon. mcp__hooks_worker-
  dispatch now writes .claude-flow/daemon-queue/<id>.json (the
  process-local Map was invisible to the daemon). The daemon polls this
  directory every 5s, executes triggerWorker(), and moves processed
  entries to .processed/. Adds `mcp-only` status for queue-write
  failures so we never claim `queued` without proof on disk.

#1846 — mcp-tools/memory-tools.ts + commands/memory.ts: feature-detect
  smartSearch on the resolved @claude-flow/memory build. When absent
  (older published memory packages predate the export), fall through to
  plain semantic search with an explicit warning + `smartFallback`
  field on the response, instead of throwing
  `smartSearch is not a function`.

#1847 — mcp-tools/hooks-tools.ts: hooks_pretrain now emits an explicit
  note when a non-empty corpus produces zero patterns, naming the
  supported extraction extensions (.ts/.js/.py/.go/.rs/.java) and
  clarifying that pretrain is a separate axis from live trajectories
  and statusline state. Local probe on a Markdown vault returns the
  new note correctly.

src/index.ts: pre-existing TS strict-null error in showCommandHelp()
  that was preventing `npm run build` (introduced by #1791.4 / 93b97548e)
  fixed by extracting a non-null `current: Command` local instead of
  reassigning the optional `command`. Unblocks publish + restores the
  integration-docker `npm run build succeeds` test.

Verification:
- 1963 tests pass / 0 fail (was 1962 / 1 due to the index.ts TS error)
- Live MCP probe: serverInfo.name="ruflo" ✅
- Live mcp-generator: emits mcpServers.ruflo ✅
- Live system_health: 80% (4/5 healthy, 3 advisory) ✅
- Live hooks_pretrain on Markdown vault: emits explicit note ✅

Published @claude-flow/cli@3.7.0-alpha.12, claude-flow@3.7.0-alpha.12,
ruflo@3.7.0-alpha.12 with all dist-tags (alpha, latest, v3alpha for
cli/claude-flow; alpha, latest for ruflo).

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-05-08 09:36:58 -04:00

212 lines
5.7 KiB
TypeScript

/**
* Configuration Adapter
* Converts between SystemConfig and V3Config types
*/
import type { SystemConfig } from '@claude-flow/shared';
import type { V3Config } from './types.js';
/**
* Convert SystemConfig to V3Config (CLI-specific format)
*/
export function systemConfigToV3Config(systemConfig: SystemConfig): V3Config {
return {
version: '3.0.0',
projectRoot: systemConfig.orchestrator?.session?.dataDir || process.cwd(),
// Agent configuration
agents: {
defaultType: 'coder',
autoSpawn: false, // Not in SystemConfig
maxConcurrent: systemConfig.orchestrator?.lifecycle?.maxConcurrentAgents ?? 15,
timeout: systemConfig.orchestrator?.lifecycle?.spawnTimeout ?? 300000,
providers: [],
},
// Swarm configuration
swarm: {
topology: normalizeTopology(systemConfig.swarm?.topology),
maxAgents: systemConfig.swarm?.maxAgents ?? 15,
autoScale: systemConfig.swarm?.autoScale?.enabled ?? false,
coordinationStrategy: systemConfig.swarm?.coordination?.consensusRequired ? 'consensus' : 'leader',
healthCheckInterval: systemConfig.swarm?.coordination?.timeoutMs ?? 10000,
},
// Memory configuration
memory: {
backend: normalizeMemoryBackend(systemConfig.memory?.type),
persistPath: systemConfig.memory?.path || './data/memory',
cacheSize: systemConfig.memory?.maxSize ?? 1000000,
enableHNSW: systemConfig.memory?.agentdb?.indexType === 'hnsw',
vectorDimension: systemConfig.memory?.agentdb?.dimensions ?? 384, // Match all-MiniLM-L6-v2 output (#1395 Bug 5)
},
// MCP configuration
mcp: {
serverHost: systemConfig.mcp?.transport?.host || 'localhost',
serverPort: systemConfig.mcp?.transport?.port ?? 3000,
autoStart: false, // Not in SystemConfig
transportType: systemConfig.mcp?.transport?.type || 'stdio',
tools: [], // Not in SystemConfig
},
// CLI preferences
cli: {
colorOutput: true,
interactive: true,
verbosity: 'normal',
outputFormat: 'text',
progressStyle: 'spinner',
},
// Hooks configuration
hooks: {
enabled: false,
autoExecute: false,
hooks: [],
},
};
}
/**
* Convert V3Config to SystemConfig
*/
export function v3ConfigToSystemConfig(v3Config: V3Config): Partial<SystemConfig> {
return {
orchestrator: {
lifecycle: {
maxConcurrentAgents: v3Config.agents.maxConcurrent,
spawnTimeout: v3Config.agents.timeout,
terminateTimeout: 10000,
maxSpawnRetries: 3,
},
session: {
dataDir: v3Config.projectRoot,
persistSessions: true,
sessionRetentionMs: 3600000,
},
health: {
checkInterval: v3Config.swarm.healthCheckInterval,
historyLimit: 100,
degradedThreshold: 1,
unhealthyThreshold: 2,
},
},
swarm: {
topology: denormalizeTopology(v3Config.swarm.topology),
maxAgents: v3Config.swarm.maxAgents,
autoScale: {
enabled: v3Config.swarm.autoScale,
minAgents: 1,
maxAgents: v3Config.swarm.maxAgents,
scaleUpThreshold: 0.8,
scaleDownThreshold: 0.3,
},
coordination: {
consensusRequired: v3Config.swarm.coordinationStrategy === 'consensus',
timeoutMs: v3Config.swarm.healthCheckInterval,
retryPolicy: {
maxRetries: 3,
backoffMs: 500,
},
},
communication: {
protocol: 'events',
batchSize: 10,
flushIntervalMs: 100,
},
},
memory: {
type: denormalizeMemoryBackend(v3Config.memory.backend),
path: v3Config.memory.persistPath,
maxSize: v3Config.memory.cacheSize,
agentdb: {
dimensions: v3Config.memory.vectorDimension,
indexType: v3Config.memory.enableHNSW ? 'hnsw' : 'flat',
efConstruction: 200,
m: 16,
quantization: 'none',
},
},
mcp: {
name: 'ruflo',
version: '3.0.0',
transport: {
type: v3Config.mcp.transportType as 'stdio' | 'http' | 'websocket',
host: v3Config.mcp.serverHost,
port: v3Config.mcp.serverPort,
},
capabilities: {
tools: true,
resources: true,
prompts: true,
logging: true,
},
},
};
}
/**
* Normalize topology from SystemConfig to V3Config
*/
function normalizeTopology(
topology: string | undefined
): 'hierarchical' | 'mesh' | 'ring' | 'star' | 'hybrid' | 'hierarchical-mesh' {
switch (topology) {
case 'hierarchical':
case 'mesh':
case 'ring':
case 'star':
case 'hybrid':
case 'hierarchical-mesh':
return topology;
case 'adaptive':
return 'hybrid';
default:
return 'hierarchical';
}
}
/**
* Denormalize topology from V3Config to SystemConfig
*/
function denormalizeTopology(
topology: 'hierarchical' | 'mesh' | 'ring' | 'star' | 'hybrid' | 'hierarchical-mesh'
): 'hierarchical' | 'mesh' | 'ring' | 'star' | 'adaptive' | 'hierarchical-mesh' {
if (topology === 'hybrid') {
return 'hierarchical-mesh';
}
return topology;
}
/**
* Normalize memory backend from SystemConfig to V3Config
*/
function normalizeMemoryBackend(
backend: string | undefined
): 'memory' | 'sqlite' | 'agentdb' | 'hybrid' {
switch (backend) {
case 'memory':
case 'sqlite':
case 'agentdb':
case 'hybrid':
return backend;
case 'redis':
return 'memory'; // Redis maps to memory for CLI purposes
default:
return 'hybrid';
}
}
/**
* Denormalize memory backend from V3Config to SystemConfig
*/
function denormalizeMemoryBackend(
backend: 'memory' | 'sqlite' | 'agentdb' | 'hybrid'
): 'memory' | 'sqlite' | 'agentdb' | 'hybrid' | 'redis' {
return backend;
}