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 edits

rUv888b6493dc3e
diff --git a/agents/architect.yaml b/agents/architect.yaml
index 1fd87f9407..9d9369f993 100644
--- a/agents/architect.yaml
+++ b/agents/architect.yaml
@@ -8,4 +8,4 @@ capabilities:
optimizations:
- context-caching
- memory-persistence
-createdAt: "2026-02-02T05:09:12.038Z"
+createdAt: "2026-02-02T05:12:43.250Z"
diff --git a/agents/coder.yaml b/agents/coder.yaml
index 28cbc5b0d3..2269634aa0 100644
--- a/agents/coder.yaml
+++ b/agents/coder.yaml
@@ -8,4 +8,4 @@ capabilities:
optimizations:
- flash-attention
- token-reduction
-createdAt: "2026-02-02T05:09:12.038Z"
+createdAt: "2026-02-02T05:12:43.249Z"
diff --git a/agents/reviewer.yaml b/agents/reviewer.yaml
index 4689f8aa0d..52391cd811 100644
--- a/agents/reviewer.yaml
+++ b/agents/reviewer.yaml
@@ -7,4 +7,4 @@ capabilities:
- best-practices
optimizations:
- incremental-analysis
-createdAt: "2026-02-02T05:09:12.038Z"
+createdAt: "2026-02-02T05:12:43.250Z"
diff --git a/agents/security-architect.yaml b/agents/security-architect.yaml
index ba02bf4158..0ee097a11e 100644
--- a/agents/security-architect.yaml
+++ b/agents/security-architect.yaml
@@ -7,4 +7,4 @@ capabilities:
- security-review
optimizations:
- pattern-matching
-createdAt: "2026-02-02T05:09:12.038Z"
+createdAt: "2026-02-02T05:12:43.250Z"
diff --git a/agents/tester.yaml b/agents/tester.yaml
index 76fc3c8e91..568aacdd76 100644
--- a/agents/tester.yaml
+++ b/agents/tester.yaml
@@ -7,4 +7,4 @@ capabilities:
- coverage
optimizations:
- parallel-execution
-createdAt: "2026-02-02T05:09:12.038Z"
+createdAt: "2026-02-02T05:12:43.250Z"
diff --git a/v3/@claude-flow/cli/src/commands/guidance.ts b/v3/@claude-flow/cli/src/commands/guidance.ts
index fd5d4507a0..9069c0f1fe 100644
--- a/v3/@claude-flow/cli/src/commands/guidance.ts
+++ b/v3/@claude-flow/cli/src/commands/guidance.ts
@@ -337,31 +337,241 @@ const statusCommand: Command = {
// optimize subcommand
const optimizeCommand: Command = {
name: 'optimize',
- description: 'Run the optimizer loop to evolve guidance rules based on run history',
+ description: 'Analyze and optimize a CLAUDE.md file for structure, coverage, and enforceability',
options: [
- { name: 'dry-run', type: 'boolean', description: 'Show proposed changes without applying', default: 'false' },
+ { name: 'root', short: 'r', type: 'string', description: 'Root guidance file path', default: './CLAUDE.md' },
+ { name: 'local', short: 'l', type: 'string', description: 'Local overlay file path' },
+ { name: 'apply', short: 'a', type: 'boolean', description: 'Apply optimizations to the file', default: 'false' },
+ { name: 'context-size', short: 's', type: 'string', description: 'Target context size: compact, standard, full', default: 'standard' },
+ { name: 'target-score', type: 'number', description: 'Target composite score (0-100)', default: '90' },
+ { name: 'max-iterations', type: 'number', description: 'Maximum optimization iterations', default: '5' },
{ name: 'json', type: 'boolean', description: 'Output as JSON', default: 'false' },
],
examples: [
- { command: 'claude-flow guidance optimize', description: 'Run optimization cycle' },
- { command: 'claude-flow guidance optimize --dry-run', description: 'Preview proposed changes' },
+ { command: 'claude-flow guidance optimize', description: 'Analyze current CLAUDE.md and show suggestions' },
+ { command: 'claude-flow guidance optimize --apply', description: 'Apply optimizations to CLAUDE.md' },
+ { command: 'claude-flow guidance optimize -s compact --apply', description: 'Optimize for compact context window' },
+ { command: 'claude-flow guidance optimize --target-score 95', description: 'Optimize until score reaches 95' },
],
action: async (ctx: CommandContext): Promise<CommandResult> => {
- const dryRun = ctx.flags['dry-run'] === true;
+ const rootPath = ctx.flags.root as string || './CLAUDE.md';
+ const localPath = ctx.flags.local as string | undefined;
+ const applyChanges = ctx.flags.apply === true;
+ const contextSize = (ctx.flags['context-size'] as string || 'standard') as 'compact' | 'standard' | 'full';
+ const targetScore = parseInt(ctx.flags['target-score'] as string || '90', 10);
+ const maxIterations = parseInt(ctx.flags['max-iterations'] as string || '5', 10);
const jsonOutput = ctx.flags.json === true;
output.writeln();
output.writeln(output.bold('Guidance Optimizer'));
output.writeln(output.dim('─'.repeat(50)));
- if (dryRun) {
- output.writeln(output.yellow('(dry run - no changes will be applied)'));
+ try {
+ const { readFile, writeFile } = await import('node:fs/promises');
+ const { existsSync } = await import('node:fs');
+
+ if (!existsSync(rootPath)) {
+ output.writeln(output.red(`Root guidance file not found: ${rootPath}`));
+ return { success: false, message: `File not found: ${rootPath}` };
+ }
+
+ const rootContent = await readFile(rootPath, 'utf-8');
+ let localContent: string | undefined;
+ if (localPath && existsSync(localPath)) {
+ localContent = await readFile(localPath, 'utf-8');
+ }
+
+ // Step 1: Analyze current state
+ const { analyze, formatReport, optimizeForSize, formatBenchmark } = await import('@claude-flow/guidance/analyzer');
+ const analysis = analyze(rootContent, localContent);
+
+ if (jsonOutput && !applyChanges) {
+ output.writeln(JSON.stringify(analysis, null, 2));
+ return { success: true, data: analysis };
+ }
+
+ // Show current analysis
+ output.writeln(formatReport(analysis));
+ output.writeln();
+
+ if (analysis.compositeScore >= targetScore) {
+ output.writeln(output.green(`Score ${analysis.compositeScore}/100 already meets target ${targetScore}. No optimization needed.`));
+ return { success: true, data: analysis };
+ }
+
+ // Step 2: Run optimization
+ output.writeln(output.dim(`Optimizing (target: ${targetScore}, context: ${contextSize}, max iterations: ${maxIterations})...`));
+
+ const result = optimizeForSize(rootContent, {
+ contextSize,
+ localContent,
+ maxIterations,
+ targetScore,
+ });
+
+ if (jsonOutput) {
+ output.writeln(JSON.stringify({
+ before: analysis,
+ after: result.benchmark.after,
+ delta: result.benchmark.delta,
+ steps: result.appliedSteps,
+ }, null, 2));
+ return { success: true, data: result };
+ }
+
+ // Show benchmark comparison
+ output.writeln();
+ output.writeln(formatBenchmark(result.benchmark));
+ output.writeln();
+
+ if (result.appliedSteps.length > 0) {
+ output.writeln(`Applied ${output.bold(String(result.appliedSteps.length))} optimization steps:`);
+ for (const step of result.appliedSteps) {
+ output.writeln(` ${output.green('+')} ${step}`);
+ }
+ output.writeln();
+ }
+
+ // Step 3: Apply if requested
+ if (applyChanges) {
+ await writeFile(rootPath, result.optimized, 'utf-8');
+ output.writeln(output.green(`Optimized CLAUDE.md written to ${rootPath}`));
+ output.writeln(` Before: ${analysis.compositeScore}/100 (${analysis.grade})`);
+ output.writeln(` After: ${result.benchmark.after.compositeScore}/100 (${result.benchmark.after.grade})`);
+ output.writeln(` Delta: ${result.benchmark.delta >= 0 ? '+' : ''}${result.benchmark.delta}`);
+ } else {
+ output.writeln(output.yellow('Dry run - use --apply to write changes.'));
+ output.writeln(` Projected: ${analysis.compositeScore} → ${result.benchmark.after.compositeScore}/100`);
+ }
+
+ return { success: true, data: result };
+ } catch (error) {
+ const msg = error instanceof Error ? error.message : String(error);
+ output.writeln(output.red(`Optimization failed: ${msg}`));
+ return { success: false, message: msg };
}
+ },
+};
- output.writeln(output.dim('Optimization requires a populated run ledger.'));
- output.writeln(output.dim('Run tasks with guidance tracking enabled first.'));
+// ab-test subcommand
+const abTestCommand: Command = {
+ name: 'ab-test',
+ description: 'Run A/B behavioral comparison between two CLAUDE.md versions',
+ options: [
+ { name: 'config-a', short: 'a', type: 'string', description: 'Path to Config A (baseline CLAUDE.md). Defaults to no guidance.' },
+ { name: 'config-b', short: 'b', type: 'string', description: 'Path to Config B (candidate CLAUDE.md)', default: './CLAUDE.md' },
+ { name: 'tasks', short: 't', type: 'string', description: 'Path to custom task JSON file (array of ABTask objects)' },
+ { name: 'work-dir', short: 'w', type: 'string', description: 'Working directory for test execution' },
+ { name: 'json', type: 'boolean', description: 'Output as JSON', default: 'false' },
+ ],
+ examples: [
+ { command: 'claude-flow guidance ab-test', description: 'Run default A/B test (no guidance vs ./CLAUDE.md)' },
+ { command: 'claude-flow guidance ab-test -a old.md -b new.md', description: 'Compare two CLAUDE.md versions' },
+ { command: 'claude-flow guidance ab-test --tasks custom-tasks.json', description: 'Run with custom test tasks' },
+ { command: 'claude-flow guidance ab-test --json', description: 'Output full report as JSON' },
+ ],
+ action: async (ctx: CommandContext): Promise<CommandResult> => {
+ const configAPath = ctx.flags['config-a'] as string | undefined;
+ const configBPath = ctx.flags['config-b'] as string || './CLAUDE.md';
+ const tasksPath = ctx.flags.tasks as string | undefined;
+ const workDir = ctx.flags['work-dir'] as string | undefined;
+ const jsonOutput = ctx.flags.json === true;
- return { success: true, message: 'Optimizer ready' };
+ output.writeln();
+ output.writeln(output.bold('A/B Behavioral Benchmark'));
+ output.writeln(output.dim('─'.repeat(50)));
+
+ try {
+ const { readFile } = await import('node:fs/promises');
+ const { existsSync } = await import('node:fs');
+ const { abBenchmark, getDefaultABTasks } = await import('@claude-flow/guidance/analyzer');
+
+ // Load Config B (candidate) content
+ if (!existsSync(configBPath)) {
+ output.writeln(output.red(`Config B file not found: ${configBPath}`));
+ return { success: false, message: `File not found: ${configBPath}` };
+ }
+ const configBContent = await readFile(configBPath, 'utf-8');
+
+ // Optionally load Config A for display context
+ let configALabel = 'No control plane (baseline)';
+ if (configAPath) {
+ if (!existsSync(configAPath)) {
+ output.writeln(output.red(`Config A file not found: ${configAPath}`));
+ return { success: false, message: `File not found: ${configAPath}` };
+ }
+ configALabel = configAPath;
+ }
+
+ // Load custom tasks if provided
+ let customTasks: undefined | any[];
+ if (tasksPath) {
+ if (!existsSync(tasksPath)) {
+ output.writeln(output.red(`Tasks file not found: ${tasksPath}`));
+ return { success: false, message: `File not found: ${tasksPath}` };
+ }
+ const tasksJson = await readFile(tasksPath, 'utf-8');
+ customTasks = JSON.parse(tasksJson);
+ output.writeln(` Custom tasks: ${output.bold(String(customTasks!.length))} loaded from ${tasksPath}`);
+ }
+
+ output.writeln(` Config A: ${output.dim(configALabel)}`);
+ output.writeln(` Config B: ${output.dim(configBPath)}`);
+ output.writeln(` Tasks: ${output.dim(customTasks ? `${customTasks.length} custom` : `${getDefaultABTasks().length} default`)}`);
+ output.writeln();
+ output.writeln(output.dim('Running benchmark...'));
+
+ // Run the A/B benchmark
+ const report = await abBenchmark(configBContent, {
+ tasks: customTasks,
+ workDir,
+ });
+
+ if (jsonOutput) {
+ output.writeln(JSON.stringify({
+ configA: { label: configALabel, metrics: report.configA.metrics },
+ configB: { label: configBPath, metrics: report.configB.metrics },
+ compositeDelta: report.compositeDelta,
+ classDeltas: report.classDeltas,
+ categoryShift: report.categoryShift,
+ taskResults: {
+ configA: report.configA.taskResults.map(r => ({
+ taskId: r.taskId, taskClass: r.taskClass, passed: r.passed,
+ violations: r.violations.length, toolCalls: r.toolCalls,
+ })),
+ configB: report.configB.taskResults.map(r => ({
+ taskId: r.taskId, taskClass: r.taskClass, passed: r.passed,
+ violations: r.violations.length, toolCalls: r.toolCalls,
+ })),
+ },
+ }, null, 2));
+ return { success: true, data: report };
+ }
+
+ // Print formatted report
+ output.writeln(report.report);
+ output.writeln();
+
+ // Summary verdict
+ const delta = report.compositeDelta;
+ if (delta > 0.05) {
+ output.writeln(output.green(`Config B is better (+${delta} composite delta)`));
+ } else if (delta < -0.05) {
+ output.writeln(output.red(`Config B is worse (${delta} composite delta)`));
+ } else {
+ output.writeln(output.yellow(`No significant difference (${delta} composite delta)`));
+ }
+
+ if (report.categoryShift) {
+ output.writeln(output.green('Category shift detected: 3+ task classes improved by 20%+'));
+ }
+
+ return { success: true, data: report };
+ } catch (error) {
+ const msg = error instanceof Error ? error.message : String(error);
+ output.writeln(output.red(`A/B benchmark failed: ${msg}`));
+ return { success: false, message: msg };
+ }
},
};