From 864b28b39c1284b7b95cf76bb1fa3a4e5391b036 Mon Sep 17 00:00:00 2001 From: rUv Date: Thu, 7 Aug 2025 13:40:10 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20Checkpoint:=20Edit=20/workspaces?= =?UTF-8?q?/claude-code-flow/benchmark/src/swarm=5Fbenchmark/cli/swe=5Fben?= =?UTF-8?q?ch=5Fcommand.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .claude/checkpoints/1754573928.json | 1 + .claude/checkpoints/1754573930.json | 1 + .../swarm_benchmark/cli/swe_bench_command.py | 177 ++++++++++++++++++ 3 files changed, 179 insertions(+) create mode 100644 .claude/checkpoints/1754573928.json create mode 100644 .claude/checkpoints/1754573930.json create mode 100644 benchmark/src/swarm_benchmark/cli/swe_bench_command.py diff --git a/.claude/checkpoints/1754573928.json b/.claude/checkpoints/1754573928.json new file mode 100644 index 0000000000..b56ba36e23 --- /dev/null +++ b/.claude/checkpoints/1754573928.json @@ -0,0 +1 @@ +{"branch": "checkpoint/pre-edit-20250807-133848", "file": "/workspaces/claude-code-flow/benchmark/src/swarm_benchmark/swe_bench/optimizer.py", "timestamp": "2025-08-07T13:38:48Z", "type": "pre-edit", "original_branch": "swe-bench"} diff --git a/.claude/checkpoints/1754573930.json b/.claude/checkpoints/1754573930.json new file mode 100644 index 0000000000..7e6858d5a0 --- /dev/null +++ b/.claude/checkpoints/1754573930.json @@ -0,0 +1 @@ +{"tag": "checkpoint-20250807-133850", "file": "/workspaces/claude-code-flow/benchmark/src/swarm_benchmark/swe_bench/optimizer.py", "timestamp": "2025-08-07T13:38:50Z", "type": "post-edit", "branch": "swe-bench", "diff_summary": " .claude-flow/metrics/performance.json | 2 +- .claude-flow/metrics/system-metrics.json | 264 +++++ .claude-flow/metrics/task-metrics.json | 6 +- .claude/checkpoints/1754573779.json | 1 + .claude/checkpoints/1754573781.json | 1 + .../src/swarm_benchmark/swe_bench/optimizer.py | 1013 ++++++++++++++++++++ 6 files changed, 1283 insertions(+), 4 deletions(-) "} diff --git a/benchmark/src/swarm_benchmark/cli/swe_bench_command.py b/benchmark/src/swarm_benchmark/cli/swe_bench_command.py new file mode 100644 index 0000000000..836cd57fff --- /dev/null +++ b/benchmark/src/swarm_benchmark/cli/swe_bench_command.py @@ -0,0 +1,177 @@ +"""SWE-Bench CLI command integration.""" + +import click +import asyncio +import json +from pathlib import Path +from typing import Optional + +from ..swe_bench import SWEBenchEngine +from ..core.models import BenchmarkConfig, StrategyType, CoordinationMode + + +@click.group() +@click.pass_context +def swe_bench(ctx): + """Run SWE-Bench software engineering benchmarks.""" + ctx.ensure_object(dict) + + +@swe_bench.command() +@click.option('--categories', '-c', multiple=True, help='Categories to test') +@click.option('--difficulty', '-d', type=click.Choice(['easy', 'medium', 'hard']), help='Difficulty level') +@click.option('--strategy', '-s', type=click.Choice(['development', 'optimization', 'testing', 'analysis']), + default='development', help='Execution strategy') +@click.option('--mode', '-m', type=click.Choice(['hierarchical', 'mesh', 'distributed', 'centralized']), + default='hierarchical', help='Coordination mode') +@click.option('--agents', '-a', type=int, default=5, help='Maximum number of agents') +@click.option('--optimize', '-o', is_flag=True, help='Enable optimization iterations') +@click.option('--iterations', '-i', type=int, default=1, help='Number of iterations') +@click.option('--output', '-o', type=click.Path(), help='Output directory for reports') +@click.pass_context +def run(ctx, categories, difficulty, strategy, mode, agents, optimize, iterations, output): + """Run SWE-Bench benchmark suite.""" + + # Create configuration + config = BenchmarkConfig( + name="SWE-Bench", + description="Software Engineering Benchmark", + strategy=StrategyType[strategy.upper()], + mode=CoordinationMode[mode.upper()], + max_agents=agents, + output_directory=output or "benchmark/swe-bench/reports" + ) + + # Initialize engine + engine = SWEBenchEngine(config) + + # Convert categories tuple to list + category_list = list(categories) if categories else None + + # Run benchmark + click.echo(f"\nšŸš€ Starting SWE-Bench with {iterations} iteration(s)") + click.echo(f" Strategy: {strategy}, Mode: {mode}, Agents: {agents}") + + if category_list: + click.echo(f" Categories: {', '.join(category_list)}") + if difficulty: + click.echo(f" Difficulty: {difficulty}") + + results = asyncio.run(engine.run_swe_benchmark( + categories=category_list, + difficulty=difficulty, + optimize=optimize, + iterations=iterations + )) + + # Display summary + summary = results.get('summary', {}) + final_perf = summary.get('final_performance', {}) + + click.echo("\nšŸ“Š SWE-Bench Results:") + click.echo(f" Success Rate: {final_perf.get('success_rate', 0):.1%}") + click.echo(f" Average Duration: {final_perf.get('average_duration', 0):.2f}s") + click.echo(f" Total Tasks: {final_perf.get('total_tasks', 0)}") + + if optimize and summary.get('improvement'): + imp = summary['improvement'] + click.echo(f"\nšŸ“ˆ Optimization Impact:") + click.echo(f" Success Rate Change: {imp.get('success_rate_change', 0):+.1%}") + click.echo(f" Duration Change: {imp.get('duration_change', 0):+.2f}s") + + click.echo(f"\nāœ… Report saved to {config.output_directory}") + + +@swe_bench.command() +@click.option('--output', '-o', type=click.Path(), help='Output directory') +@click.pass_context +def status(ctx, output): + """Show current SWE-Bench status and recent results.""" + + output_dir = Path(output or "benchmark/swe-bench/reports") + + if not output_dir.exists(): + click.echo("No SWE-Bench results found.") + return + + # Find most recent report + reports = list(output_dir.glob("swe_bench_report_*.json")) + + if not reports: + click.echo("No SWE-Bench reports found.") + return + + latest = max(reports, key=lambda p: p.stat().st_mtime) + + with open(latest) as f: + data = json.load(f) + + click.echo(f"\nšŸ“Š Latest SWE-Bench Results ({latest.name}):") + click.echo(f" Timestamp: {data.get('timestamp', 'Unknown')}") + + summary = data.get('summary', {}) + final_perf = summary.get('final_performance', {}) + + click.echo(f"\n Performance:") + click.echo(f" - Success Rate: {final_perf.get('success_rate', 0):.1%}") + click.echo(f" - Tasks Completed: {final_perf.get('successful_tasks', 0)}/{final_perf.get('total_tasks', 0)}") + click.echo(f" - Average Duration: {final_perf.get('average_duration', 0):.2f}s") + + if summary.get('improvement'): + imp = summary['improvement'] + click.echo(f"\n Optimization Results:") + click.echo(f" - Success Rate Improved: {imp.get('success_rate_change', 0):+.1%}") + click.echo(f" - Speed Change: {imp.get('duration_change', 0):+.2f}s") + click.echo(f" - Optimization Effective: {'āœ…' if imp.get('optimization_effective') else 'āŒ'}") + + +@swe_bench.command() +@click.option('--target-success', '-s', type=float, default=0.8, help='Target success rate') +@click.option('--target-duration', '-d', type=float, default=15.0, help='Target average duration') +@click.option('--max-iterations', '-i', type=int, default=10, help='Maximum optimization iterations') +@click.option('--output', '-o', type=click.Path(), help='Output directory') +@click.pass_context +def optimize(ctx, target_success, target_duration, max_iterations, output): + """Run automated optimization to achieve target metrics.""" + + from ..swe_bench.optimizer import SWEBenchOptimizer + + click.echo(f"\nšŸ”§ Starting SWE-Bench Optimization") + click.echo(f" Target Success Rate: {target_success:.1%}") + click.echo(f" Target Duration: {target_duration}s") + click.echo(f" Max Iterations: {max_iterations}") + + # Initialize optimizer + optimizer = SWEBenchOptimizer() + + # Run auto-tuning + config = optimizer.auto_tune( + target_metrics={ + 'success_rate': target_success, + 'average_duration': target_duration + }, + max_iterations=max_iterations + ) + + click.echo(f"\nāœ… Optimization Complete!") + click.echo(f" Optimal Configuration:") + click.echo(f" - Strategy: {config.strategy.value}") + click.echo(f" - Mode: {config.mode.value}") + click.echo(f" - Max Agents: {config.max_agents}") + click.echo(f" - Task Timeout: {config.task_timeout}s") + + # Save configuration + output_dir = Path(output or "benchmark/swe-bench/configs") + output_dir.mkdir(parents=True, exist_ok=True) + + config_path = output_dir / "optimized_config.json" + with open(config_path, 'w') as f: + json.dump({ + 'strategy': config.strategy.value, + 'mode': config.mode.value, + 'max_agents': config.max_agents, + 'task_timeout': config.task_timeout, + 'max_retries': config.max_retries + }, f, indent=2) + + click.echo(f"\nšŸ’¾ Configuration saved to {config_path}") \ No newline at end of file