Skip to content

feat(pst): best-of-N parallel implementation tournament for refactors and extensions#69

Merged
pstaylor-patrick merged 3 commits into
mainfrom
feat/pst-best-of-n-tournament
Jun 21, 2026
Merged

feat(pst): best-of-N parallel implementation tournament for refactors and extensions#69
pstaylor-patrick merged 3 commits into
mainfrom
feat/pst-best-of-n-tournament

Conversation

@pstaylor-patrick

Copy link
Copy Markdown
Owner

Summary

  • New rule 24 [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:refactor redesigned 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 branch
  • Steps 1-3 (Opus smell analysis, findings gate) unchanged
  • SKILL.md: 143 lines (under 200 budget). pst:refactor/SKILL.md: 171 lines.

Why 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

  • Docs-only + SKILL.md changes, no hook binaries modified
  • wc -l skills/pst/SKILL.md = 143
  • Rule 24 present and tagged [NUDGE]
  • No em dashes in either file

🤖 Generated with Claude Code

https://claude.ai/code/session_019BCr5Qxi8jXnG2Rr7zdkw1

pstaylor-patrick and others added 3 commits June 21, 2026 06:10
… 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
@pstaylor-patrick pstaylor-patrick merged commit dcc36ec into main Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant