From c6e85f35e82409b1b70981eda70401dc6f23357f Mon Sep 17 00:00:00 2001 From: Daniel Jun Suguimoto Date: Tue, 31 Mar 2026 10:12:28 -0300 Subject: [PATCH] fix: align pr commands with head branch - require switching to the PR head branch before local inspection - store the active branch for review and fix workflows - sync generated opencode command docs with the source templates --- packages/core/commands/pr/fix.md | 17 +++++++++--- packages/core/commands/pr/review.md | 25 ++++++++++++----- packages/core/components/load-pr.md | 2 ++ .../opencode/.opencode/commands/pr/fix.md | 19 ++++++++++--- .../opencode/.opencode/commands/pr/review.md | 27 ++++++++++++++----- 5 files changed, 70 insertions(+), 20 deletions(-) diff --git a/packages/core/commands/pr/fix.md b/packages/core/commands/pr/fix.md index 18c3509..24a97a8 100644 --- a/packages/core/commands/pr/fix.md +++ b/packages/core/commands/pr/fix.md @@ -28,6 +28,16 @@ $ARGUMENTS <%~ include("@load-pr", { ref: "", result: "" }) %> +### Align Local Branch + +- If `` is unavailable, STOP and report that the PR head branch could not be determined +- If `` differs from ``: + - Checkout `` before analyzing repository files or making code changes for this PR + - After checkout, store the active branch as `` + - If checkout fails, STOP and report that the PR branch could not be checked out locally +- Otherwise, store `` as `` +- Do not inspect or modify local code for this PR until `` equals `` + ### Analyze Feedback Separate true course corrections from noise or already-resolved feedback: @@ -42,9 +52,10 @@ Do not blindly follow every suggestion—some may lead you off course. 1. Fix critical navigation issues first 2. Follow existing code patterns and conventions -3. Make focused, minimal changes -4. When maintaining your current heading despite a suggestion, be prepared to explain why -5. Store the modified-file count as `` +3. Use `` as the working branch for every local code read or edit in this command +4. Make focused, minimal changes +5. When maintaining your current heading despite a suggestion, be prepared to explain why +6. Store the modified-file count as `` ### Validate Changes diff --git a/packages/core/commands/pr/review.md b/packages/core/commands/pr/review.md index b8256db..01fbf7e 100644 --- a/packages/core/commands/pr/review.md +++ b/packages/core/commands/pr/review.md @@ -24,6 +24,16 @@ $ARGUMENTS <%~ include("@load-pr", { ref: "", result: "" }) %> +### Align Local Branch + +- If `` is unavailable, STOP and report that the PR head branch could not be determined +- If `` differs from ``: + - Checkout `` before inspecting local repository files for this PR review + - After checkout, store the active branch as `` + - If checkout fails, STOP and report that the PR branch could not be checked out locally +- Otherwise, store `` as `` +- Do not inspect local repository code for this PR until `` equals `` + ### Load Ticket Context If `` links to exactly one clear ticket: @@ -39,16 +49,17 @@ Call `changes_load` with `base: `, `head: `, ``, and `` -2. Derive `` from ``: +2. Use `` whenever local repository files need to be inspected alongside the diff +3. Derive `` from ``: - Treat resolved threads as settled - Treat threads as settled when they already contain feedback from `` and a later reply makes it clear the concern was intentionally declined, deferred, or answered without a code change request - Treat threads as settled when the author's reply directly answers the concern and the current diff does not add a materially different failure mode -3. Derive `` from `` authored by `` -4. Use diff hunks in `` to map inline comments to the correct lines -5. Derive `` as findings that are: - - new in this diff - - from a previously unreviewed changed area - - clearly missed material defects with a concrete failure mode +4. Derive `` from `` authored by `` +5. Use diff hunks in `` to map inline comments to the correct lines +6. Derive `` as findings that are: + - new in this diff + - from a previously unreviewed changed area + - clearly missed material defects with a concrete failure mode Exclude anything already covered by `` or `` on the same effective diff. <%= it.config.shared.prApprove === true ? "Derive `` from existing approvals on ``.\n\n" : "" %>Before publishing, derive: ``, ``, ``, and whether each proposed finding is included in ``. diff --git a/packages/core/components/load-pr.md b/packages/core/components/load-pr.md index 1b74c92..b980349 100644 --- a/packages/core/components/load-pr.md +++ b/packages/core/components/load-pr.md @@ -3,6 +3,8 @@ - Otherwise, call `pr_load` with no arguments - Do not run separate git or GitHub commands just to discover the PR before calling `pr_load` - Store the result as `<%= it.result %>` +- Store the PR head branch as `` from `<%= it.result %>.pr.headRefName` when it is available +- Run `git branch --show-current` and store the trimmed result as `` when it is available - Treat the loaded PR body, discussion, review history, and any attachments or linked artifacts returned by the loader as part of the source context - Review attached images, screenshots, videos, PDFs, and other linked files whenever they can affect the requested fix, review outcome, reproduction steps, or acceptance criteria - If any relevant attachment cannot be accessed, note that gap and continue only when the remaining PR context is still sufficient to proceed reliably diff --git a/packages/opencode/.opencode/commands/pr/fix.md b/packages/opencode/.opencode/commands/pr/fix.md index 816f650..d940f8f 100644 --- a/packages/opencode/.opencode/commands/pr/fix.md +++ b/packages/opencode/.opencode/commands/pr/fix.md @@ -36,10 +36,22 @@ $ARGUMENTS - Otherwise, call `kompass_pr_load` with no arguments - Do not run separate git or GitHub commands just to discover the PR before calling `kompass_pr_load` - Store the result as `` +- Store the PR head branch as `` from `.pr.headRefName` when it is available +- Run `git branch --show-current` and store the trimmed result as `` when it is available - Treat the loaded PR body, discussion, review history, and any attachments or linked artifacts returned by the loader as part of the source context - Review attached images, screenshots, videos, PDFs, and other linked files whenever they can affect the requested fix, review outcome, reproduction steps, or acceptance criteria - If any relevant attachment cannot be accessed, note that gap and continue only when the remaining PR context is still sufficient to proceed reliably +### Align Local Branch + +- If `` is unavailable, STOP and report that the PR head branch could not be determined +- If `` differs from ``: + - Checkout `` before analyzing repository files or making code changes for this PR + - After checkout, store the active branch as `` + - If checkout fails, STOP and report that the PR branch could not be checked out locally +- Otherwise, store `` as `` +- Do not inspect or modify local code for this PR until `` equals `` + ### Analyze Feedback Separate true course corrections from noise or already-resolved feedback: @@ -54,9 +66,10 @@ Do not blindly follow every suggestion—some may lead you off course. 1. Fix critical navigation issues first 2. Follow existing code patterns and conventions -3. Make focused, minimal changes -4. When maintaining your current heading despite a suggestion, be prepared to explain why -5. Store the modified-file count as `` +3. Use `` as the working branch for every local code read or edit in this command +4. Make focused, minimal changes +5. When maintaining your current heading despite a suggestion, be prepared to explain why +6. Store the modified-file count as `` ### Validate Changes diff --git a/packages/opencode/.opencode/commands/pr/review.md b/packages/opencode/.opencode/commands/pr/review.md index 7b94028..8566573 100644 --- a/packages/opencode/.opencode/commands/pr/review.md +++ b/packages/opencode/.opencode/commands/pr/review.md @@ -32,10 +32,22 @@ $ARGUMENTS - Otherwise, call `kompass_pr_load` with no arguments - Do not run separate git or GitHub commands just to discover the PR before calling `kompass_pr_load` - Store the result as `` +- Store the PR head branch as `` from `.pr.headRefName` when it is available +- Run `git branch --show-current` and store the trimmed result as `` when it is available - Treat the loaded PR body, discussion, review history, and any attachments or linked artifacts returned by the loader as part of the source context - Review attached images, screenshots, videos, PDFs, and other linked files whenever they can affect the requested fix, review outcome, reproduction steps, or acceptance criteria - If any relevant attachment cannot be accessed, note that gap and continue only when the remaining PR context is still sufficient to proceed reliably +### Align Local Branch + +- If `` is unavailable, STOP and report that the PR head branch could not be determined +- If `` differs from ``: + - Checkout `` before inspecting local repository files for this PR review + - After checkout, store the active branch as `` + - If checkout fails, STOP and report that the PR branch could not be checked out locally +- Otherwise, store `` as `` +- Do not inspect local repository code for this PR until `` equals `` + ### Load Ticket Context If `` links to exactly one clear ticket: @@ -55,16 +67,17 @@ Call `kompass_changes_load` with `base: `, `head: `, ``, and `` -2. Derive `` from ``: +2. Use `` whenever local repository files need to be inspected alongside the diff +3. Derive `` from ``: - Treat resolved threads as settled - Treat threads as settled when they already contain feedback from `` and a later reply makes it clear the concern was intentionally declined, deferred, or answered without a code change request - Treat threads as settled when the author's reply directly answers the concern and the current diff does not add a materially different failure mode -3. Derive `` from `` authored by `` -4. Use diff hunks in `` to map inline comments to the correct lines -5. Derive `` as findings that are: - - new in this diff - - from a previously unreviewed changed area - - clearly missed material defects with a concrete failure mode +4. Derive `` from `` authored by `` +5. Use diff hunks in `` to map inline comments to the correct lines +6. Derive `` as findings that are: + - new in this diff + - from a previously unreviewed changed area + - clearly missed material defects with a concrete failure mode Exclude anything already covered by `` or `` on the same effective diff. Derive `` from existing approvals on ``.