From ad6f91d00c78ff5e46a66b13a5ead729593ded34 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Sun, 15 Mar 2026 20:04:41 -0500 Subject: [PATCH] feat: add {{BASE_BRANCH_DETECT}} resolver to gen-skill-docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DRY placeholder for dynamic base branch detection across PR-targeting skills. Detects via gh pr view (existing PR base) → gh repo view (repo default) → fallback to main. Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/gen-skill-docs.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/gen-skill-docs.ts b/scripts/gen-skill-docs.ts index 7f6bd249..2d7e9d7e 100644 --- a/scripts/gen-skill-docs.ts +++ b/scripts/gen-skill-docs.ts @@ -126,11 +126,33 @@ If \`NEEDS_SETUP\`: 3. If \`bun\` is not installed: \`curl -fsSL https://bun.sh/install | bash\``; } +function generateBaseBranchDetect(): string { + return `## 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." + +---`; +} + const RESOLVERS: Record string> = { COMMAND_REFERENCE: generateCommandReference, SNAPSHOT_FLAGS: generateSnapshotFlags, UPDATE_CHECK: generateUpdateCheck, BROWSE_SETUP: generateBrowseSetup, + BASE_BRANCH_DETECT: generateBaseBranchDetect, }; // ─── Template Processing ────────────────────────────────────