feat(pst): best-of-N parallel implementation tournament for refactors and extensions#69
Merged
Merged
Conversation
… and extensions Rule 24: spawn 2-5 parallel Sonnet agents (Conservative/Structural/Extract-first strategies) in isolated worktrees, Opus judge picks winner by MAINTAINABILITY.md criteria. /pst:refactor implements the pattern with N scaled to complexity. Trivial: N=1 (no tournament). Moderate: N=3. Complex: N=5. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1
… tournament - Step 5: switch from background to foreground parallel agents so synchronization is implicit (no explicit gate needed before judge) - Each agent returns a structured ---tournament-result--- block with STRATEGY, STATUS, COMMIT_SHA, and full git diff -- no worktree access required after agent completes - Step 6: judge reads diffs from result blocks directly; returns winning letter (A-E) not strategy name; SHA lookup stays in orchestrator - Step 7: cherry-pick by SHA from result blocks, not from judge output; fall back to git apply on conflict - Failed agents emit STATUS: skipped: <reason> so errors surface - Rule 24: trimmed to normative pointer only; impl details live in skill Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1
…protocol - Step 2 Opus was marked 'background', causing Step 3 to run before findings arrived; changed to foreground so smell analysis is complete before gate - N=1 trivial path was undefined; now routes directly to strategy A, no judge - Co-author trailer commit format specified as HEREDOC to preserve blank line - git apply fallback specifies write-to-temp-file via Write tool first - Opus judge schema shows all N strategies, not just A; added instruction to include every strategy that ran - Absent result block (agent crash/overflow) now treated as skipped Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[NUDGE]: for substantive refactors/extensions, spawn 2-5 parallel Sonnet agents with divergent strategies (Conservative, Structural, Extract-first, plus Domain-model and Functional for N=5) in isolated worktrees, then Opus judges picks the winner by MAINTAINABILITY.md criteria/pst:refactorredesigned steps 4-7 to implement the tournament: N scaled to complexity (trivial=1/skip, moderate=3, complex=5), Opus judge scores all N diffs on six MAINTAINABILITY.md dimensions, cherry-picks winner to current branchWhy best-of-N
Refactoring has a genuinely wide solution space -- Conservative and Extract-first approaches can produce dramatically different code that both fix the smell. Running N=3 in parallel costs 3x Sonnet but catches the case where the "obvious" approach produces worse locality than a structural reorganization. Opus judge adds one evaluation pass that costs less than a human review cycle.
Test plan
wc -l skills/pst/SKILL.md= 143[NUDGE]🤖 Generated with Claude Code
https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1