diff --git a/packages/core/commands/pr/fix.md b/packages/core/commands/pr/fix.md index ceb7231..e8913d1 100644 --- a/packages/core/commands/pr/fix.md +++ b/packages/core/commands/pr/fix.md @@ -30,7 +30,7 @@ $ARGUMENTS ### Align Local Branch -<%~ include("@align-pr-branch", { action: "analyzing repository files or making code changes for this PR", scope: "inspect or modify local code for this PR" }) %> +<%~ include("@align-pr-branch", { action: "analyzing repository files or making code changes for this PR", scope: "inspect or modify local code for this PR", requiresBranch: true }) -%> ### Load Changes diff --git a/packages/core/commands/pr/review.md b/packages/core/commands/pr/review.md index 40a8967..6c7fb91 100644 --- a/packages/core/commands/pr/review.md +++ b/packages/core/commands/pr/review.md @@ -26,7 +26,7 @@ $ARGUMENTS ### Align Local Branch -<%~ include("@align-pr-branch", { action: "inspecting local repository files for this PR review", scope: "inspect local repository code for this PR" }) %> +<%~ include("@align-pr-branch", { action: "inspecting local repository files for this PR review", scope: "inspect local repository code for this PR", requiresBranch: false }) -%> ### Load Ticket Context diff --git a/packages/core/components/align-pr-branch.md b/packages/core/components/align-pr-branch.md index ebabe6c..b05385e 100644 --- a/packages/core/components/align-pr-branch.md +++ b/packages/core/components/align-pr-branch.md @@ -1,5 +1,18 @@ - If `` is unavailable, STOP and report that the PR head branch could not be determined -- Run `gh pr checkout ` before <%= it.action %> -- After checkout, store the active branch as `` -- If checkout fails, STOP and report that the PR branch could not be checked out locally -- Do not <%= it.scope %> until `` equals `` +<% if (it.requiresBranch) { -%> +- If `` equals `` and `` equals ``, store `` as `` and do not checkout again +- If `` differs from `` or `` differs from ``: + - Run `gh pr checkout ` before <%= it.action %> + - After checkout, store the active branch as `` + - Run `git rev-parse HEAD` again and store the trimmed result as `` + - If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks +- Do not <%= it.scope %> until `` equals `` and `` equals `` +<% } else { -%> +- If `` equals ``, store `` as `` when `` is available; otherwise store `` as ``. Do not checkout because the worktree is already at the PR head commit. +- If `` differs from ``: + - Run `gh pr checkout ` before <%= it.action %> + - After checkout, store the active branch as `` + - Run `git rev-parse HEAD` again and store the trimmed result as `` + - If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks +- Do not <%= it.scope %> until `` equals `` +<% } -%> diff --git a/packages/core/components/load-pr.md b/packages/core/components/load-pr.md index a4aa2b1..6e181e6 100644 --- a/packages/core/components/load-pr.md +++ b/packages/core/components/load-pr.md @@ -5,6 +5,7 @@ - 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 +- Run `git rev-parse HEAD` 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/core/test/commands.test.ts b/packages/core/test/commands.test.ts index 1ba256c..0fa8290 100644 --- a/packages/core/test/commands.test.ts +++ b/packages/core/test/commands.test.ts @@ -13,4 +13,23 @@ describe("resolveCommands", () => { assert.deepEqual(commands["pr/review"]?.config, { enabled: true }); }); + + test("skips PR checkout when pr/review is already at PR head", async () => { + const commands = await resolveCommands(process.cwd()); + const template = commands["pr/review"]?.template ?? ""; + + assert.match(template, /git rev-parse HEAD/); + assert.match(template, /`` equals ``/); + assert.match(template, /Run `gh pr checkout `/); + assert.match(template, /do not retry checkout unless the user explicitly asks/); + }); + + test("requires PR branch for pr/fix checkout alignment", async () => { + const commands = await resolveCommands(process.cwd()); + const template = commands["pr/fix"]?.template ?? ""; + + assert.match(template, /`` equals `` and `` equals ``/); + assert.match(template, /`` differs from `` or `` differs from ``/); + assert.match(template, /Do not inspect or modify local code for this PR until `` equals `` and `` equals ``/); + }); }); diff --git a/packages/opencode/.opencode/commands/pr/fix.md b/packages/opencode/.opencode/commands/pr/fix.md index 0a118cc..ab03e0c 100644 --- a/packages/opencode/.opencode/commands/pr/fix.md +++ b/packages/opencode/.opencode/commands/pr/fix.md @@ -38,6 +38,7 @@ $ARGUMENTS - 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 +- Run `git rev-parse HEAD` 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 @@ -45,10 +46,13 @@ $ARGUMENTS ### Align Local Branch - If `` is unavailable, STOP and report that the PR head branch could not be determined -- Run `gh pr 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 -- Do not inspect or modify local code for this PR until `` equals `` +- If `` equals `` and `` equals ``, store `` as `` and do not checkout again +- If `` differs from `` or `` differs from ``: + - Run `gh pr checkout ` before analyzing repository files or making code changes for this PR + - After checkout, store the active branch as `` + - Run `git rev-parse HEAD` again and store the trimmed result as `` + - If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks +- Do not inspect or modify local code for this PR until `` equals `` and `` equals `` ### Load Changes diff --git a/packages/opencode/.opencode/commands/pr/review.md b/packages/opencode/.opencode/commands/pr/review.md index c75e39e..59351c0 100644 --- a/packages/opencode/.opencode/commands/pr/review.md +++ b/packages/opencode/.opencode/commands/pr/review.md @@ -34,6 +34,7 @@ $ARGUMENTS - 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 +- Run `git rev-parse HEAD` 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 @@ -41,10 +42,13 @@ $ARGUMENTS ### Align Local Branch - If `` is unavailable, STOP and report that the PR head branch could not be determined -- Run `gh pr 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 -- Do not inspect local repository code for this PR until `` equals `` +- If `` equals ``, store `` as `` when `` is available; otherwise store `` as ``. Do not checkout because the worktree is already at the PR head commit. +- If `` differs from ``: + - Run `gh pr checkout ` before inspecting local repository files for this PR review + - After checkout, store the active branch as `` + - Run `git rev-parse HEAD` again and store the trimmed result as `` + - If checkout fails or times out, STOP and report that the PR branch could not be checked out locally; do not retry checkout unless the user explicitly asks +- Do not inspect local repository code for this PR until `` equals `` ### Load Ticket Context