Simplify PR Logic
Analyze first. Do not edit code unless the user explicitly authorizes implementation.
Optimize for the reasoning burden of the complete logic thread, not line count. Prefer fewer concepts,
states, branches, ownership crossings, temporal constraints, and facts held in mind. Generalize only
when doing so collapses genuinely identical policy. Split logic only when the resulting responsibilities
are cohesive and the end-to-end flow becomes easier to reconstruct.
Guardrails
- Anchor every investigation and hypothesis to a concept introduced, changed, or newly exposed by
origin/main...HEAD.
- Follow an anchored thread as far as its behavior requires. Inspect configuration, feature flags,
callers, callees, propagation, state transitions, interfaces, tests, and cleanup even when they are
several dependency edges from the diff.
- Do not turn a thread into an unrestricted architecture or repository review.
- Preserve intended observable behavior and external contracts. Freely challenge private interfaces,
abstractions, module ownership, and control flow.
- Treat a behavior change as a product decision unless the investigation proves a bug.
- Consider a stronger interface only when it reduces caller reasoning and prevents a demonstrated
misuse, invalid state, or ordering hazard on an anchored thread.
- Treat existing abstractions as evidence, not requirements. Preserve earned boundaries, validation,
security, persistence, and test seams when they still carry real responsibilities.
- Exclude formatting, naming nits, lint, generic correctness review, test-coverage commentary,
security review, and unrelated cleanup.
- Preserve user changes. Never stash, discard, reset, or rewrite work to prepare the analysis.
1. Establish The Baseline
- Read the repository instructions and the smallest set of authoritative design, product, and testing
docs needed to interpret the changed code.
- Inspect branch and worktree state.
- Fetch
origin/main. If fetching is unavailable, continue only when origin/main exists and report
that its freshness is unverified.
- Measure ahead/behind state with merge-base semantics. If
HEAD is behind origin/main, stop and
report the exact state. Ask permission before merging origin/main; never merge with a dirty
worktree or resolve conflicts by assumption. After an authorized successful merge, restart the
analysis from the new diff.
- Use
origin/main...HEAD as the PR comparison. Inventory commits, changed paths, renames,
deletions, and the complete diff.
- Inventory staged, unstaged, and untracked files separately. Label them local-only and do not
misrepresent them as part of the PR.
- If there is no PR diff and no relevant local-only work, report that and stop.
When available, inspect the PR description, linked issue or spec, commit messages, tests, contracts,
and repository guidance. Prefer executable contracts and current authoritative docs over stale PR
narrative. Mark intent-dependent hypotheses unresolved when intent remains ambiguous.
2. Map Anchored Logic Threads
For each meaningful changed concept:
- State the apparent intent and observable invariants.
- Trace where input enters, policy is chosen, state changes, data propagates, and output or side
effects leave.
- Identify the modules and interfaces that own each decision.
- Note complexity signals:
- duplicated policy or state
- branching spread across layers
- feature flags or configuration leaking through unrelated modules
- invalid states or call ordering permitted by an interface
- callers assembling knowledge the callee should own
- pass-through layers or abstractions without a meaningful seam
- mixed responsibilities or temporal coupling
- generalized machinery serving only speculative cases
- Record the concrete PR anchor for every location included in the thread.
Do not equate unfamiliarity with complexity. Understand the full thread before proposing a shape.
3. Generate Independent Hypotheses
Use at least three subagents. Keep their contexts independent until critique:
- Start two hypothesis generators concurrently from raw repository evidence:
- Flow generator: simplify control flow, data flow, state, policy propagation, and branching.
- Interface generator: challenge responsibility placement, module boundaries, abstractions,
feature-flag design, invalid states, and misuse-prone interfaces.
- Start one critic concurrently. Give the critic the raw change, relevant repository constraints,
and target threads, but no generated hypotheses. Ask it to independently map invariants, hidden
consumers, boundary responsibilities, and reasons tempting refactors may fail.
- Do not tell any agent the expected answer or another agent's conclusions.
- Require read-only work. Subagents must not edit files.
Require each generator to return only material candidates using this schema:
- title and PR anchor
- current logic thread and reasoning burden
- proposed responsibility, flow, or interface
- concepts, states, branches, or misuse paths removed
- supporting evidence
- strongest disconfirming evidence
- observable invariants and contracts to preserve
- affected neighborhood and likely implementation cost
- confidence
Keep bugs separate from simplification hypotheses.
4. Challenge The Candidates
The parent agent must inspect the evidence directly. Do not accept a hypothesis by vote or copy a
subagent report without verification.
- Deduplicate the generators' candidates and discard style-only or unanchored suggestions.
- Trace callers, implementations, tests, registrations, persistence, configuration, and external
boundaries needed to test each material claim.
- Use focused existing tests or read-only checks when they can prove an invariant or reproduce a
suspected bug. Do not run a broad full suite by default.
- Send the surviving candidate set to the already-grounded critic in a follow-up. Ask it to
disprove each candidate with counterexamples, hidden costs, violated boundaries, ambiguous intent,
or evidence that total-system complexity would increase.
- Re-check disputed evidence yourself and adjudicate from source artifacts. Agreement among agents
is not proof.
Use history or blame only when the current source cannot explain an important constraint. Historical
presence alone does not justify complexity.
5. Classify Hypotheses
Classify each material candidate:
- Accepted: concretely PR-anchored; preserves intended behavior and external contracts; reduces
total conceptual complexity or demonstrated misuse risk; and has bounded, understood costs.
- Rejected: tempting but contradicted by evidence, dependent on speculative generalization, or
likely to move or increase complexity.
- Unresolved: potentially high-leverage but blocked by ambiguous intent or missing evidence.
State exactly what evidence would resolve it.
Rank accepted hypotheses by net leverage: reasoning and misuse reduction relative to implementation
cost and behavioral risk. Omit low-value cleanup.
Classify a discovered bug separately only when there is a concrete failing scenario, violated
invariant, or authoritative contract mismatch. Keep it anchored to the investigated logic thread.
Do not use a bug as permission for a broader sweep.
6. Report
Produce a synthesized report, not raw subagent transcripts.
Scope and evidence
State the base, synchronization and freshness status, commits and files reviewed, local-only work,
anchored threads followed, authoritative evidence used, and focused checks run.
Accepted hypotheses
For each accepted hypothesis, provide:
- Current model: the end-to-end thread and why it is hard to reason about.
- Proposed model: the new responsibility, flow, or interface shape.
- Simplification: the concepts, states, branches, ownership crossings, or misuse paths removed.
- Evidence: support, strongest counterargument, and adjudicated verdict.
- Safety: preserved invariants and contracts, affected neighborhood, risks, and confidence.
- Execution: a small implementation sequence with focused verification points.
Bugs
Report proven bugs separately with the failing scenario or violated invariant. Do not edit unless
authorized.
Unresolved hypotheses
Include only material opportunities and the evidence needed to decide them.
Strongest rejected hypotheses
Briefly explain the most plausible rejected alternatives and the evidence that ruled them out.
If no hypothesis survives critique, say so directly. A well-supported no-change result is preferable
to manufacturing a refactor.
Authorized Follow-Up
If the user explicitly authorizes implementation, change only accepted hypotheses within the agreed
scope. Preserve repository architecture and migration rules, verify each coherent step, and re-read
the final diff for displaced rather than removed complexity. Do not silently implement unresolved or
rejected ideas.
1---2name: simplify-pr-logic3description: Analyze a pull request against origin/main for high-leverage logic simplifications, deeper PR-anchored refactors, clearer module ownership, and interfaces that prevent misuse. Use only when explicitly invoked to generate and adversarially test refactoring hypotheses; do not use for generic code review, correctness, style, lint, security, test coverage, or repository-wide cleanup.4---56# Simplify PR Logic78Analyze first. Do not edit code unless the user explicitly authorizes implementation.910Optimize for the reasoning burden of the complete logic thread, not line count. Prefer fewer concepts,11states, branches, ownership crossings, temporal constraints, and facts held in mind. Generalize only12when doing so collapses genuinely identical policy. Split logic only when the resulting responsibilities13are cohesive and the end-to-end flow becomes easier to reconstruct.1415## Guardrails1617- Anchor every investigation and hypothesis to a concept introduced, changed, or newly exposed by18 `origin/main...HEAD`.19- Follow an anchored thread as far as its behavior requires. Inspect configuration, feature flags,20 callers, callees, propagation, state transitions, interfaces, tests, and cleanup even when they are21 several dependency edges from the diff.22- Do not turn a thread into an unrestricted architecture or repository review.23- Preserve intended observable behavior and external contracts. Freely challenge private interfaces,24 abstractions, module ownership, and control flow.25- Treat a behavior change as a product decision unless the investigation proves a bug.26- Consider a stronger interface only when it reduces caller reasoning and prevents a demonstrated27 misuse, invalid state, or ordering hazard on an anchored thread.28- Treat existing abstractions as evidence, not requirements. Preserve earned boundaries, validation,29 security, persistence, and test seams when they still carry real responsibilities.30- Exclude formatting, naming nits, lint, generic correctness review, test-coverage commentary,31 security review, and unrelated cleanup.32- Preserve user changes. Never stash, discard, reset, or rewrite work to prepare the analysis.3334## 1. Establish The Baseline35361. Read the repository instructions and the smallest set of authoritative design, product, and testing37 docs needed to interpret the changed code.382. Inspect branch and worktree state.393. Fetch `origin/main`. If fetching is unavailable, continue only when `origin/main` exists and report40 that its freshness is unverified.414. Measure ahead/behind state with merge-base semantics. If `HEAD` is behind `origin/main`, stop and42 report the exact state. Ask permission before merging `origin/main`; never merge with a dirty43 worktree or resolve conflicts by assumption. After an authorized successful merge, restart the44 analysis from the new diff.455. Use `origin/main...HEAD` as the PR comparison. Inventory commits, changed paths, renames,46 deletions, and the complete diff.476. Inventory staged, unstaged, and untracked files separately. Label them local-only and do not48 misrepresent them as part of the PR.497. If there is no PR diff and no relevant local-only work, report that and stop.5051When available, inspect the PR description, linked issue or spec, commit messages, tests, contracts,52and repository guidance. Prefer executable contracts and current authoritative docs over stale PR53narrative. Mark intent-dependent hypotheses unresolved when intent remains ambiguous.5455## 2. Map Anchored Logic Threads5657For each meaningful changed concept:58591. State the apparent intent and observable invariants.602. Trace where input enters, policy is chosen, state changes, data propagates, and output or side61 effects leave.623. Identify the modules and interfaces that own each decision.634. Note complexity signals:64 - duplicated policy or state65 - branching spread across layers66 - feature flags or configuration leaking through unrelated modules67 - invalid states or call ordering permitted by an interface68 - callers assembling knowledge the callee should own69 - pass-through layers or abstractions without a meaningful seam70 - mixed responsibilities or temporal coupling71 - generalized machinery serving only speculative cases725. Record the concrete PR anchor for every location included in the thread.7374Do not equate unfamiliarity with complexity. Understand the full thread before proposing a shape.7576## 3. Generate Independent Hypotheses7778Use at least three subagents. Keep their contexts independent until critique:79801. Start two hypothesis generators concurrently from raw repository evidence:81 - **Flow generator:** simplify control flow, data flow, state, policy propagation, and branching.82 - **Interface generator:** challenge responsibility placement, module boundaries, abstractions,83 feature-flag design, invalid states, and misuse-prone interfaces.842. Start one critic concurrently. Give the critic the raw change, relevant repository constraints,85 and target threads, but no generated hypotheses. Ask it to independently map invariants, hidden86 consumers, boundary responsibilities, and reasons tempting refactors may fail.873. Do not tell any agent the expected answer or another agent's conclusions.884. Require read-only work. Subagents must not edit files.8990Require each generator to return only material candidates using this schema:9192- title and PR anchor93- current logic thread and reasoning burden94- proposed responsibility, flow, or interface95- concepts, states, branches, or misuse paths removed96- supporting evidence97- strongest disconfirming evidence98- observable invariants and contracts to preserve99- affected neighborhood and likely implementation cost100- confidence101102Keep bugs separate from simplification hypotheses.103104## 4. Challenge The Candidates105106The parent agent must inspect the evidence directly. Do not accept a hypothesis by vote or copy a107subagent report without verification.1081091. Deduplicate the generators' candidates and discard style-only or unanchored suggestions.1102. Trace callers, implementations, tests, registrations, persistence, configuration, and external111 boundaries needed to test each material claim.1123. Use focused existing tests or read-only checks when they can prove an invariant or reproduce a113 suspected bug. Do not run a broad full suite by default.1144. Send the surviving candidate set to the already-grounded critic in a follow-up. Ask it to115 disprove each candidate with counterexamples, hidden costs, violated boundaries, ambiguous intent,116 or evidence that total-system complexity would increase.1175. Re-check disputed evidence yourself and adjudicate from source artifacts. Agreement among agents118 is not proof.119120Use history or blame only when the current source cannot explain an important constraint. Historical121presence alone does not justify complexity.122123## 5. Classify Hypotheses124125Classify each material candidate:126127- **Accepted:** concretely PR-anchored; preserves intended behavior and external contracts; reduces128 total conceptual complexity or demonstrated misuse risk; and has bounded, understood costs.129- **Rejected:** tempting but contradicted by evidence, dependent on speculative generalization, or130 likely to move or increase complexity.131- **Unresolved:** potentially high-leverage but blocked by ambiguous intent or missing evidence.132 State exactly what evidence would resolve it.133134Rank accepted hypotheses by net leverage: reasoning and misuse reduction relative to implementation135cost and behavioral risk. Omit low-value cleanup.136137Classify a discovered bug separately only when there is a concrete failing scenario, violated138invariant, or authoritative contract mismatch. Keep it anchored to the investigated logic thread.139Do not use a bug as permission for a broader sweep.140141## 6. Report142143Produce a synthesized report, not raw subagent transcripts.144145### Scope and evidence146147State the base, synchronization and freshness status, commits and files reviewed, local-only work,148anchored threads followed, authoritative evidence used, and focused checks run.149150### Accepted hypotheses151152For each accepted hypothesis, provide:1531541. **Current model:** the end-to-end thread and why it is hard to reason about.1552. **Proposed model:** the new responsibility, flow, or interface shape.1563. **Simplification:** the concepts, states, branches, ownership crossings, or misuse paths removed.1574. **Evidence:** support, strongest counterargument, and adjudicated verdict.1585. **Safety:** preserved invariants and contracts, affected neighborhood, risks, and confidence.1596. **Execution:** a small implementation sequence with focused verification points.160161### Bugs162163Report proven bugs separately with the failing scenario or violated invariant. Do not edit unless164authorized.165166### Unresolved hypotheses167168Include only material opportunities and the evidence needed to decide them.169170### Strongest rejected hypotheses171172Briefly explain the most plausible rejected alternatives and the evidence that ruled them out.173174If no hypothesis survives critique, say so directly. A well-supported no-change result is preferable175to manufacturing a refactor.176177## Authorized Follow-Up178179If the user explicitly authorizes implementation, change only accepted hypotheses within the agreed180scope. Preserve repository architecture and migration rules, verify each coherent step, and re-read181the final diff for displaced rather than removed complexity. Do not silently implement unresolved or182rejected ideas.