Commit 250c351
authored
feat(agent-comparison): add autoresearch optimization review flow (#205)
* feat(agent-comparison): add autoresearch optimization review flow
* feat(autoresearch): migrate SDK to claude -p, add beam search, fix review issues
- Migrate generate_variant.py and improve_description.py from Anthropic SDK
to claude -p subprocess invocation
- Add beam search optimization with configurable width, candidates per parent,
and frontier retention to optimize_loop.py
- Add beam search parameters display and empty-state UX in eval_viewer.html
- Update SKILL.md and optimization-guide.md for beam search documentation
- Migrate skill-eval run_loop and rules-distill to use claude -p
- Add test coverage for beam search, model flag omission, and claude -p flow
Fixes from review:
- Fix misplaced test_writes_pending_json_in_live_mode (back in TestFullPipeline)
- Remove dead round_keeps variable from optimize_loop.py
- Fix timeout mismatch (120s outer vs 300s inner → 360s outer)
- Clarify --max-iterations help text (rounds, not individual iterations)
* fix(review-round-1): address 8 findings from PR review
Critical fixes:
- Temp file collision in beam search: embed iteration_counter in filename
- rules-distill.py: log errors on claude -p failure and JSONDecodeError
- _run_trigger_rate: always print subprocess errors, not just under --verbose
- _generate_variant_output: add cwd and env (strip CLAUDECODE)
Important fixes:
- _find_project_root: warn on silent cwd fallback in generate_variant and improve_description
- improve_description: warn when <new_description> tags not found
- search_strategy: emit "hill_climb" for single-path runs (beam_width=1, candidates=1)
- rules-distill: log exception in broad except clause
* fix(review-round-2): handle JSON parse error in _run_trigger_rate, fix task-file leak
Critical fixes:
- Wrap json.loads in _run_trigger_rate with try/except JSONDecodeError
(exits-0-but-invalid-JSON no longer crashes the entire optimization run)
- Move task_file assignment before json.dump so finally block can always
clean up the temp file on disk
Also: document _run_claude_code soft-fail contract in rules-distill.py
* fix(review-round-3): catch TimeoutExpired, move write_text inside cleanup guard
- Add subprocess.TimeoutExpired to caught exceptions in variant generation
loop (prevents unhandled crash when claude -p hits 360s timeout)
- Move temp_target.write_text() inside try/finally block so partial writes
are cleaned up on disk-full or permission errors
* style: fix import sort order and formatting
- Fix import block ordering in test_eval_compare_optimization.py (ruff I001)
- Fix formatting in test_skill_eval_claude_code.py and eval_compare.py (ruff format)
* feat(adr-132): add behavioral eval mode and creation compliance task set
Add _run_behavioral_eval() to optimize_loop.py that runs
`claude -p "/do {query}"` and checks for ADR artifact creation,
enabling direct testing of /do's creation protocol compliance.
Trigger-rate optimization was proven inapplicable for /do (scored
0.0 across all 32 tasks) because /do is slash-invoked, not
description-discovered. Behavioral eval via headless /do is the
correct approach — confirmed that `claude -p "/do create..."` works
but does NOT produce ADRs, validating the compliance gap.
Changes:
- Add _run_behavioral_eval() with artifact snapshot/diff detection
- Add _is_behavioral_task() for eval_mode detection
- Update _validate_task_set() for behavioral task format
- Wire behavioral path into assess_target()
- Add DO NOT OPTIMIZE markers to /do SKILL.md (Phase 2-5 protected)
- Create 32-task benchmark set (16 positive, 16 negative, 60/40 split)
* feat(adr-133): strengthen Phase 1 creation detection in /do SKILL.md
Add explicit Creation Request Detection block to Phase 1 CLASSIFY,
immediately before the Gate line. The block scans for creation verbs,
domain object targets, and implicit creation patterns, then flags the
request as [CREATION REQUEST DETECTED] so Phase 4 Step 0 is acknowledged
before routing decisions consume model attention.
This is ADR-133 Prong 2, Option A. Moving detection to Phase 1 addresses
the root cause: the creation protocol was buried in Phase 4 where it
competed with agent dispatch instructions and was frequently skipped.
* feat(adr-133): add creation-protocol-enforcer PreToolUse hook
Soft-warns when an Agent dispatch appears to be for a creation task but
no recent .adr-session.json is present (stale = >900s or missing).
Exit 0 only — never blocks. Prong 2 / Option B of ADR-133.
* fix(index): register kotlin, php, and swift agent entries in INDEX.json
Three agents (kotlin-general-engineer, php-general-engineer,
swift-general-engineer) existed on disk but were missing from
agents/INDEX.json, making them invisible to the routing system.
Added all three entries with triggers, pairs_with, complexity, and
category sourced directly from each agent's frontmatter. Also fixes
the pre-existing golang-general-engineer-compact ordering bug as a
side effect of re-sorting the index alphabetically.
* fix(behavioral-eval): raise timeout to 240s, check artifacts after TimeoutExpired
Two fixes to _run_behavioral_eval():
1. Default timeout 120s -> 240s: headless /do creation sessions frequently
exceed 120s when they dispatch agents that write files, create plans, etc.
2. Check artifact glob after TimeoutExpired: the subprocess may have written
artifacts before the timeout fired. The old code set triggered=False on
any timeout, causing false FAIL for tasks that completed their artifact
writes but ran over time.
E2E baseline results (6-task subset, 240s timeout):
- Creation recall: 1/3 (33%) — implicit-create-rails passed (ADR-135 created)
- Non-creation precision: 3/3 (100%)
- build-agent-rust: genuine compliance gap (completed, no ADR)
* fix(review-round-1): address 4 findings from PR review
1. behavioral eval: always print claude exit code (not only in verbose mode)
— silent failures would produce phantom 50% accuracy, corrupting optimization
2. behavioral eval: clean up created artifacts between tasks to prevent
stale before-snapshots in multi-round optimization runs
3. creation-protocol-enforcer: expand keyword set to match SKILL.md vocabulary
— 'build a', 'add new', 'new feature', 'i need a/an', 'we need a/an'
previously covered <50% of the benchmark creation queries
4. SKILL.md Phase 1: move [CREATION REQUEST DETECTED] output to the Gate
condition so LLM cannot proceed to Phase 2 without acknowledging the flag1 parent 3bdf3cd commit 250c351
File tree
19 files changed
+1899
-517
lines changed- agents
- hooks
- scripts
- skill_eval
- tests
- skills
- agent-comparison
- references
- scripts
- do
- skill-creator
- assets
- scripts
- skill-eval
19 files changed
+1899
-517
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
115 | 115 | | |
116 | 116 | | |
117 | 117 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | 118 | | |
136 | 119 | | |
137 | 120 | | |
| |||
151 | 134 | | |
152 | 135 | | |
153 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
174 | 202 | | |
175 | 203 | | |
176 | 204 | | |
| |||
354 | 382 | | |
355 | 383 | | |
356 | 384 | | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
357 | 417 | | |
358 | 418 | | |
359 | 419 | | |
| |||
792 | 852 | | |
793 | 853 | | |
794 | 854 | | |
795 | | - | |
| 855 | + | |
796 | 856 | | |
797 | 857 | | |
798 | 858 | | |
| |||
907 | 967 | | |
908 | 968 | | |
909 | 969 | | |
910 | | - | |
| 970 | + | |
911 | 971 | | |
912 | 972 | | |
913 | 973 | | |
| |||
1083 | 1143 | | |
1084 | 1144 | | |
1085 | 1145 | | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
1086 | 1181 | | |
1087 | 1182 | | |
1088 | 1183 | | |
| |||
1236 | 1331 | | |
1237 | 1332 | | |
1238 | 1333 | | |
1239 | | - | |
| 1334 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
0 commit comments