From b3e8c18dd83050f4a8c90b7cc14e3389bcd43007 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 15 Mar 2026 20:04:55 -0500 Subject: [PATCH] fix: review, qa, plan-ceo-review detect base branch dynamically Same pattern as ship: replaces hardcoded 'main' with {{BASE_BRANCH_DETECT}}. Also cleans up qa bash-isms (REPORT_DIR variable, port chaining). Co-Authored-By: Claude Opus 4.6 (1M context) --- plan-ceo-review/SKILL.md | 21 ++++++++++++++++++++- plan-ceo-review/SKILL.md.tmpl | 4 +++- qa/SKILL.md | 33 +++++++++++++++++++++++++-------- qa/SKILL.md.tmpl | 16 ++++++++-------- review/SKILL.md | 33 ++++++++++++++++++++++++++------- review/SKILL.md.tmpl | 16 +++++++++------- 6 files changed, 91 insertions(+), 32 deletions(-) diff --git a/plan-ceo-review/SKILL.md b/plan-ceo-review/SKILL.md index 7bb5dad0..83711608 100644 --- a/plan-ceo-review/SKILL.md +++ b/plan-ceo-review/SKILL.md @@ -25,6 +25,25 @@ _UPD=$(~/.claude/skills/gstack/bin/gstack-update-check 2>/dev/null || .claude/sk If output shows `UPGRADE_AVAILABLE `: read `~/.claude/skills/gstack/gstack-upgrade/SKILL.md` and follow the "Inline upgrade flow" (auto-upgrade if configured, otherwise AskUserQuestion with 4 options, write snooze state if declined). If `JUST_UPGRADED `: tell user "Running gstack v{to} (just updated!)" and continue. +## Step 0: Detect base branch + +Determine which branch this PR targets. Use the result as "the base branch" in all subsequent steps. + +1. Check if a PR already exists for this branch: + `gh pr view --json baseRefName -q .baseRefName` + If this succeeds, use the printed branch name as the base branch. + +2. If no PR exists (command fails), detect the repo's default branch: + `gh repo view --json defaultBranchRef -q .defaultBranchRef.name` + +3. If both commands fail, fall back to `main`. + +Print the detected base branch name. In every subsequent `git diff`, `git log`, +`git fetch`, `git merge`, and `gh pr create` command, substitute the detected +branch name wherever the instructions say "the base branch." + +--- + # Mega Plan Review Mode ## Philosophy @@ -69,7 +88,7 @@ Before doing anything else, run a system audit. This is not the plan review — Run the following commands: ``` git log --oneline -30 # Recent history -git diff main --stat # What's already changed +git diff --stat # What's already changed git stash list # Any stashed work grep -r "TODO\|FIXME\|HACK\|XXX" --include="*.rb" --include="*.js" -l find . -name "*.rb" -newer Gemfile.lock | head -20 # Recently touched files diff --git a/plan-ceo-review/SKILL.md.tmpl b/plan-ceo-review/SKILL.md.tmpl index 09fa6274..e7af818b 100644 --- a/plan-ceo-review/SKILL.md.tmpl +++ b/plan-ceo-review/SKILL.md.tmpl @@ -16,6 +16,8 @@ allowed-tools: {{UPDATE_CHECK}} +{{BASE_BRANCH_DETECT}} + # Mega Plan Review Mode ## Philosophy @@ -60,7 +62,7 @@ Before doing anything else, run a system audit. This is not the plan review — Run the following commands: ``` git log --oneline -30 # Recent history -git diff main --stat # What's already changed +git diff --stat # What's already changed git stash list # Any stashed work grep -r "TODO\|FIXME\|HACK\|XXX" --include="*.rb" --include="*.js" -l find . -name "*.rb" -newer Gemfile.lock | head -20 # Recently touched files diff --git a/qa/SKILL.md b/qa/SKILL.md index dd4b888d..bbb2e5c5 100644 --- a/qa/SKILL.md +++ b/qa/SKILL.md @@ -25,6 +25,25 @@ _UPD=$(~/.claude/skills/gstack/bin/gstack-update-check 2>/dev/null || .claude/sk If output shows `UPGRADE_AVAILABLE `: read `~/.claude/skills/gstack/gstack-upgrade/SKILL.md` and follow the "Inline upgrade flow" (auto-upgrade if configured, otherwise AskUserQuestion with 4 options, write snooze state if declined). If `JUST_UPGRADED `: tell user "Running gstack v{to} (just updated!)" and continue. +## Step 0: Detect base branch + +Determine which branch this PR targets. Use the result as "the base branch" in all subsequent steps. + +1. Check if a PR already exists for this branch: + `gh pr view --json baseRefName -q .baseRefName` + If this succeeds, use the printed branch name as the base branch. + +2. If no PR exists (command fails), detect the repo's default branch: + `gh repo view --json defaultBranchRef -q .defaultBranchRef.name` + +3. If both commands fail, fall back to `main`. + +Print the detected base branch name. In every subsequent `git diff`, `git log`, +`git fetch`, `git merge`, and `gh pr create` command, substitute the detected +branch name wherever the instructions say "the base branch." + +--- + # /qa: Systematic QA Testing You are a QA engineer. Test web applications like a real user — click everything, fill every form, check every state. Produce a structured report with evidence. @@ -67,8 +86,7 @@ If `NEEDS_SETUP`: **Create output directories:** ```bash -REPORT_DIR=".gstack/qa-reports" -mkdir -p "$REPORT_DIR/screenshots" +mkdir -p .gstack/qa-reports/screenshots ``` --- @@ -81,8 +99,8 @@ This is the **primary mode** for developers verifying their work. When the user 1. **Analyze the branch diff** to understand what changed: ```bash - git diff main...HEAD --name-only - git log main..HEAD --oneline + git diff ...HEAD --name-only + git log ..HEAD --oneline ``` 2. **Identify affected pages/routes** from the changed files: @@ -95,11 +113,10 @@ This is the **primary mode** for developers verifying their work. When the user 3. **Detect the running app** — check common local dev ports: ```bash - $B goto http://localhost:3000 2>/dev/null && echo "Found app on :3000" || \ - $B goto http://localhost:4000 2>/dev/null && echo "Found app on :4000" || \ - $B goto http://localhost:8080 2>/dev/null && echo "Found app on :8080" + # Try common dev ports in order — stop at the first that loads + $B goto http://localhost:3000 ``` - If no local app is found, check for a staging/preview URL in the PR or environment. If nothing works, ask the user for the URL. + If port 3000 fails, try 4000, then 8080. If none work, ask the user for the URL. 4. **Test each affected page/route:** - Navigate to the page diff --git a/qa/SKILL.md.tmpl b/qa/SKILL.md.tmpl index 6afadcc7..0774c80c 100644 --- a/qa/SKILL.md.tmpl +++ b/qa/SKILL.md.tmpl @@ -16,6 +16,8 @@ allowed-tools: {{UPDATE_CHECK}} +{{BASE_BRANCH_DETECT}} + # /qa: Systematic QA Testing You are a QA engineer. Test web applications like a real user — click everything, fill every form, check every state. Produce a structured report with evidence. @@ -41,8 +43,7 @@ You are a QA engineer. Test web applications like a real user — click everythi **Create output directories:** ```bash -REPORT_DIR=".gstack/qa-reports" -mkdir -p "$REPORT_DIR/screenshots" +mkdir -p .gstack/qa-reports/screenshots ``` --- @@ -55,8 +56,8 @@ This is the **primary mode** for developers verifying their work. When the user 1. **Analyze the branch diff** to understand what changed: ```bash - git diff main...HEAD --name-only - git log main..HEAD --oneline + git diff ...HEAD --name-only + git log ..HEAD --oneline ``` 2. **Identify affected pages/routes** from the changed files: @@ -69,11 +70,10 @@ This is the **primary mode** for developers verifying their work. When the user 3. **Detect the running app** — check common local dev ports: ```bash - $B goto http://localhost:3000 2>/dev/null && echo "Found app on :3000" || \ - $B goto http://localhost:4000 2>/dev/null && echo "Found app on :4000" || \ - $B goto http://localhost:8080 2>/dev/null && echo "Found app on :8080" + # Try common dev ports in order — stop at the first that loads + $B goto http://localhost:3000 ``` - If no local app is found, check for a staging/preview URL in the PR or environment. If nothing works, ask the user for the URL. + If port 3000 fails, try 4000, then 8080. If none work, ask the user for the URL. 4. **Test each affected page/route:** - Navigate to the page diff --git a/review/SKILL.md b/review/SKILL.md index b572283a..bbf61e8e 100644 --- a/review/SKILL.md +++ b/review/SKILL.md @@ -2,7 +2,7 @@ name: review version: 1.0.0 description: | - Pre-landing PR review. Analyzes diff against main for SQL safety, LLM trust + Pre-landing PR review. Analyzes diff against the base branch for SQL safety, LLM trust boundary violations, conditional side effects, and other structural issues. allowed-tools: - Bash @@ -25,17 +25,36 @@ _UPD=$(~/.claude/skills/gstack/bin/gstack-update-check 2>/dev/null || .claude/sk If output shows `UPGRADE_AVAILABLE `: read `~/.claude/skills/gstack/gstack-upgrade/SKILL.md` and follow the "Inline upgrade flow" (auto-upgrade if configured, otherwise AskUserQuestion with 4 options, write snooze state if declined). If `JUST_UPGRADED `: tell user "Running gstack v{to} (just updated!)" and continue. +## Step 0: Detect base branch + +Determine which branch this PR targets. Use the result as "the base branch" in all subsequent steps. + +1. Check if a PR already exists for this branch: + `gh pr view --json baseRefName -q .baseRefName` + If this succeeds, use the printed branch name as the base branch. + +2. If no PR exists (command fails), detect the repo's default branch: + `gh repo view --json defaultBranchRef -q .defaultBranchRef.name` + +3. If both commands fail, fall back to `main`. + +Print the detected base branch name. In every subsequent `git diff`, `git log`, +`git fetch`, `git merge`, and `gh pr create` command, substitute the detected +branch name wherever the instructions say "the base branch." + +--- + # Pre-Landing PR Review -You are running the `/review` workflow. Analyze the current branch's diff against main for structural issues that tests don't catch. +You are running the `/review` workflow. Analyze the current branch's diff against the base branch for structural issues that tests don't catch. --- ## Step 1: Check branch 1. Run `git branch --show-current` to get the current branch. -2. If on `main`, output: **"Nothing to review — you're on main or have no changes against main."** and stop. -3. Run `git fetch origin main --quiet && git diff origin/main --stat` to check if there's a diff. If no diff, output the same message and stop. +2. If on the base branch, output: **"Nothing to review — you're on the base branch or have no changes against it."** and stop. +3. Run `git fetch origin --quiet && git diff origin/ --stat` to check if there's a diff. If no diff, output the same message and stop. --- @@ -59,13 +78,13 @@ Read `.claude/skills/review/greptile-triage.md` and follow the fetch, filter, cl ## Step 3: Get the diff -Fetch the latest main to avoid false positives from a stale local main: +Fetch the latest base branch to avoid false positives from stale local state: ```bash -git fetch origin main --quiet +git fetch origin --quiet ``` -Run `git diff origin/main` to get the full diff. This includes both committed and uncommitted changes against the latest main. +Run `git diff origin/` to get the full diff. This includes both committed and uncommitted changes against the latest base branch. --- diff --git a/review/SKILL.md.tmpl b/review/SKILL.md.tmpl index edc1e6c9..752710e6 100644 --- a/review/SKILL.md.tmpl +++ b/review/SKILL.md.tmpl @@ -2,7 +2,7 @@ name: review version: 1.0.0 description: | - Pre-landing PR review. Analyzes diff against main for SQL safety, LLM trust + Pre-landing PR review. Analyzes diff against the base branch for SQL safety, LLM trust boundary violations, conditional side effects, and other structural issues. allowed-tools: - Bash @@ -16,17 +16,19 @@ allowed-tools: {{UPDATE_CHECK}} +{{BASE_BRANCH_DETECT}} + # Pre-Landing PR Review -You are running the `/review` workflow. Analyze the current branch's diff against main for structural issues that tests don't catch. +You are running the `/review` workflow. Analyze the current branch's diff against the base branch for structural issues that tests don't catch. --- ## Step 1: Check branch 1. Run `git branch --show-current` to get the current branch. -2. If on `main`, output: **"Nothing to review — you're on main or have no changes against main."** and stop. -3. Run `git fetch origin main --quiet && git diff origin/main --stat` to check if there's a diff. If no diff, output the same message and stop. +2. If on the base branch, output: **"Nothing to review — you're on the base branch or have no changes against it."** and stop. +3. Run `git fetch origin --quiet && git diff origin/ --stat` to check if there's a diff. If no diff, output the same message and stop. --- @@ -50,13 +52,13 @@ Read `.claude/skills/review/greptile-triage.md` and follow the fetch, filter, cl ## Step 3: Get the diff -Fetch the latest main to avoid false positives from a stale local main: +Fetch the latest base branch to avoid false positives from stale local state: ```bash -git fetch origin main --quiet +git fetch origin --quiet ``` -Run `git diff origin/main` to get the full diff. This includes both committed and uncommitted changes against the latest main. +Run `git diff origin/` to get the full diff. This includes both committed and uncommitted changes against the latest base branch. ---