From 42eaee8b7e6c1704afad4f7751d233b2faccf2cd Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Fri, 13 Feb 2026 15:09:37 -0500 Subject: [PATCH] chore: fix root_dir resolution/stale scripts during PR review --- .agents/skills/merge-pr/SKILL.md | 1 + .agents/skills/review-pr/SKILL.md | 1 + scripts/pr | 23 ++++++++++++++++++++++- scripts/pr-merge | 13 ++++++++++--- scripts/pr-prepare | 9 ++++++++- scripts/pr-review | 12 +++++++++++- 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/.agents/skills/merge-pr/SKILL.md b/.agents/skills/merge-pr/SKILL.md index ae89b1a274..041e79a676 100644 --- a/.agents/skills/merge-pr/SKILL.md +++ b/.agents/skills/merge-pr/SKILL.md @@ -19,6 +19,7 @@ Merge a prepared PR only after deterministic validation. - Never use `gh pr merge --auto` in this flow. - Never run `git push` directly. - Require `--match-head-commit` during merge. +- Wrapper commands are cwd-agnostic; you can run them from repo root or inside the PR worktree. ## Execution Contract diff --git a/.agents/skills/review-pr/SKILL.md b/.agents/skills/review-pr/SKILL.md index ab9d75d967..f5694ca2c4 100644 --- a/.agents/skills/review-pr/SKILL.md +++ b/.agents/skills/review-pr/SKILL.md @@ -18,6 +18,7 @@ Perform a read-only review and produce both human and machine-readable outputs. - Never push, merge, or modify code intended to keep. - Work only in `.worktrees/pr-`. +- Wrapper commands are cwd-agnostic; you can run them from repo root or inside the PR worktree. ## Execution Contract diff --git a/scripts/pr b/scripts/pr index 1ceb0bce0a..3c51a331b1 100755 --- a/scripts/pr +++ b/scripts/pr @@ -2,6 +2,18 @@ set -euo pipefail +# If invoked from a linked worktree copy of this script, re-exec the canonical +# script from the repository root so behavior stays consistent across worktrees. +script_self="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/$(basename "${BASH_SOURCE[0]}")" +script_parent_dir="$(dirname "$script_self")" +if common_git_dir=$(git -C "$script_parent_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then + canonical_repo_root="$(dirname "$common_git_dir")" + canonical_self="$canonical_repo_root/scripts/$(basename "${BASH_SOURCE[0]}")" + if [ "$script_self" != "$canonical_self" ] && [ -x "$canonical_self" ]; then + exec "$canonical_self" "$@" + fi +fi + usage() { cat </dev/null); then + (cd "$(dirname "$common_git_dir")" && pwd) + return + fi + + # Fallback for environments where git common-dir is unavailable. (cd "$script_dir/.." && pwd) } diff --git a/scripts/pr-merge b/scripts/pr-merge index 745d74d885..728c8289d0 100755 --- a/scripts/pr-merge +++ b/scripts/pr-merge @@ -2,6 +2,13 @@ set -euo pipefail script_dir="$(cd "$(dirname "$0")" && pwd)" +base="$script_dir/pr" +if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then + canonical_base="$(dirname "$common_git_dir")/scripts/pr" + if [ -x "$canonical_base" ]; then + base="$canonical_base" + fi +fi usage() { cat </dev/null); then + canonical_base="$(dirname "$common_git_dir")/scripts/pr" + if [ -x "$canonical_base" ]; then + base="$canonical_base" + fi +fi case "$mode" in init) diff --git a/scripts/pr-review b/scripts/pr-review index 1376080e15..afd765a846 100755 --- a/scripts/pr-review +++ b/scripts/pr-review @@ -1,3 +1,13 @@ #!/usr/bin/env bash set -euo pipefail -exec "$(cd "$(dirname "$0")" && pwd)/pr" review-init "$@" + +script_dir="$(cd "$(dirname "$0")" && pwd)" +base="$script_dir/pr" +if common_git_dir=$(git -C "$script_dir" rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then + canonical_base="$(dirname "$common_git_dir")/scripts/pr" + if [ -x "$canonical_base" ]; then + base="$canonical_base" + fi +fi + +exec "$base" review-init "$@"