|
8 | 8 | * node optimize.js init # Initialize with current CLAUDE.md |
9 | 9 | * node optimize.js mutate # Generate new variants |
10 | 10 | * node optimize.js eval [variant] # Run evals on variant(s) |
11 | | - * node optimize.js score # Score all variants in generation |
| 11 | + * node optimize.js score [--auto-apply] # Score all variants in generation |
12 | 12 | * node optimize.js select # Select best, advance generation |
13 | | - * node optimize.js run [generations] # Full optimization loop |
| 13 | + * node optimize.js run [gens] [--auto-apply] # Full optimization loop |
14 | 14 | * node optimize.js status # Show current status |
15 | 15 | * node optimize.js diff [a] [b] # Compare two variants |
| 16 | + * |
| 17 | + * Flags: |
| 18 | + * --auto-apply Apply winning variant to target file automatically |
| 19 | + * --no-cache Bypass eval response cache (force fresh eval) |
| 20 | + * --target <name> Optimize a specific target from config.targets[] |
| 21 | + * --phase <name> Phase-scoped mutation for conductor prompts |
| 22 | + * --auto-phase Auto-detect worst phase from outcomes.jsonl |
16 | 23 | */ |
17 | 24 |
|
18 | 25 | import fs from 'fs'; |
@@ -96,6 +103,10 @@ const phaseIdx = process.argv.indexOf('--phase'); |
96 | 103 | const phaseName = phaseIdx !== -1 ? process.argv[phaseIdx + 1] : null; |
97 | 104 | if (phaseIdx !== -1) process.argv.splice(phaseIdx, 2); |
98 | 105 |
|
| 106 | +// --auto-apply: automatically apply winning variant when threshold is reached |
| 107 | +const autoApply = process.argv.includes('--auto-apply'); |
| 108 | +if (autoApply) process.argv.splice(process.argv.indexOf('--auto-apply'), 1); |
| 109 | + |
99 | 110 | const CONDUCTOR_PROMPTS_DIR = path.join( |
100 | 111 | process.env.HOME || '', |
101 | 112 | '.stackmemory', |
@@ -1630,7 +1641,14 @@ async function run(generations = config.evolution.generations) { |
1630 | 1641 | console.log(`Best variant: ${state.bestVariant}`); |
1631 | 1642 | console.log(`Best score: ${(state.bestScore * 100).toFixed(1)}%`); |
1632 | 1643 | console.log(`Generations: ${state.currentGeneration}`); |
1633 | | - console.log(`\nTo apply: node optimize.js apply`); |
| 1644 | + |
| 1645 | + // Auto-apply winning variant if flag set and improvement found |
| 1646 | + if (autoApply && state.bestVariant !== 'baseline') { |
| 1647 | + console.log(`\n[auto-apply] Deploying ${state.bestVariant} to target...`); |
| 1648 | + await apply(); |
| 1649 | + } else { |
| 1650 | + console.log(`\nTo apply: node optimize.js apply`); |
| 1651 | + } |
1634 | 1652 | } |
1635 | 1653 |
|
1636 | 1654 | /** |
@@ -2031,7 +2049,12 @@ switch (command) { |
2031 | 2049 | break; |
2032 | 2050 | case 'select': |
2033 | 2051 | case 'score': |
2034 | | - scoreAndSelect(); |
| 2052 | + scoreAndSelect().then((best) => { |
| 2053 | + if (autoApply && best && best.variant !== 'baseline') { |
| 2054 | + console.log(`\n[auto-apply] Deploying ${best.variant}...`); |
| 2055 | + return apply(); |
| 2056 | + } |
| 2057 | + }); |
2035 | 2058 | break; |
2036 | 2059 | case 'run': |
2037 | 2060 | run(parseInt(arg1) || config.evolution.generations); |
|
0 commit comments