Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions skills/create-branch/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ Run:
git rev-parse --abbrev-ref HEAD
```

**If the result is NOT `main`, `master`, or `develop`:** the session is already on a feature branch. Skip silently — return control to the caller without any output.
Compare the result against the base branch detected by:

**If the result is `main`, `master`, or `develop` (or `HEAD` for detached state):** proceed to Step 2.
```!
bash scripts/detect-base-branch.sh
```

**If the current branch is NOT the base branch (and not `HEAD`):** the session is already on a feature branch. Skip silently — return control to the caller without any output.

**If the current branch IS the base branch (or `HEAD` for detached state):** proceed to Step 2.

## Step 2: Infer branch name

Expand Down
1 change: 1 addition & 0 deletions skills/create-branch/scripts/detect-base-branch.sh
10 changes: 7 additions & 3 deletions skills/rebase/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ Rebase the current feature branch onto the latest base branch to keep it up-to-d

Run these checks in order. If any fail, inform the user and stop.

### Detect current branch
### Detect current branch and base branch

```bash
git rev-parse --abbrev-ref HEAD
```

If the result is `main`, `master`, or `develop` — inform the user they're already on the base branch and stop.

### Detect base branch
Detect the base branch:

Check for `main`, `master`, `develop` (in that order). Use the first one that exists. If none exist, inform the user and stop.
```!
bash scripts/detect-base-branch.sh
```

If the script exits with an error, inform the user no base branch was found and stop.

### Check for uncommitted changes

Expand Down
1 change: 1 addition & 0 deletions skills/rebase/scripts/detect-base-branch.sh
32 changes: 8 additions & 24 deletions skills/review/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,16 @@ Parse the review scope above for optional file paths or directories.

**If no paths provided:**

1. Detect current branch:
Run the scope detection script:

```bash
git rev-parse --abbrev-ref HEAD
```
```!
bash scripts/detect-review-scope.sh
```

2. Detect default branch:

```bash
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/origin/||'
```

Fallback: check for `main`, then `master`.

3. **If on a feature branch** (current branch differs from the default branch):
- Get changed files: `git diff <default-branch>...HEAD --name-only`
- Include uncommitted changes: `git diff --name-only` and `git diff --cached --name-only`
- Deduplicate the combined file list
- Announce scope summary: number of changed files, which areas of the codebase are affected
- Proceed to Step 2 — the user invoked `/review`, intent is clear

4. **If on the default branch:**
- Tell the user: "You're on `<branch>`. No branch diff available."
- Use **AskUserQuestion**: "What would you like to review?" with options:
- **Specify files or directories**: accept paths from the user
- **Review entire project**: no scope constraint
- **If `SCOPE=branch`**: use the listed files as review scope. Announce scope summary: number of changed files, which areas of the codebase are affected. Proceed to Step 2.
- **If `SCOPE=default`**: tell the user: "You're on `<CURRENT_BRANCH>`. No branch diff available." Use **AskUserQuestion**: "What would you like to review?" with options:
- **Specify files or directories**: accept paths from the user
- **Review entire project**: no scope constraint

## Step 2 — Run Reviews

Expand Down
1 change: 1 addition & 0 deletions skills/review/scripts/detect-review-scope.sh
15 changes: 15 additions & 0 deletions skills/shared/scripts/detect-base-branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
# Detect the default/base branch of the repository.
# Checks main, master, develop in order. Outputs the first one found.
# Exits 1 if none exist.

for branch in main master develop; do
if git rev-parse --verify "$branch" &>/dev/null ||
git rev-parse --verify "origin/$branch" &>/dev/null; then
echo "$branch"
exit 0
fi
done

echo "ERROR: no base branch found (checked main, master, develop)" >&2
exit 1
44 changes: 44 additions & 0 deletions skills/shared/scripts/detect-review-scope.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Detect review scope: current branch, base branch, and changed files.
# Output format (one section per line):
# CURRENT_BRANCH=<branch>
# BASE_BRANCH=<branch>
# SCOPE=branch|default
# FILES (one per line after the FILES header)
#
# Usage: detect-review-scope.sh

set -euo pipefail

CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "CURRENT_BRANCH=$CURRENT_BRANCH"

# Detect base branch
BASE_BRANCH=""
DEFAULT_REF=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/origin/||' || true)
if [ -n "$DEFAULT_REF" ]; then
BASE_BRANCH="$DEFAULT_REF"
else
for branch in main master develop; do
if git rev-parse --verify "$branch" &>/dev/null ||
git rev-parse --verify "origin/$branch" &>/dev/null; then
BASE_BRANCH="$branch"
break
fi
done
fi
echo "BASE_BRANCH=$BASE_BRANCH"

# Determine scope
if [ "$CURRENT_BRANCH" = "$BASE_BRANCH" ] || [ -z "$BASE_BRANCH" ]; then
echo "SCOPE=default"
else
echo "SCOPE=branch"
echo "FILES"
# Combine branch diff + uncommitted + staged, deduplicate
{
git diff "$BASE_BRANCH"...HEAD --name-only 2>/dev/null
git diff --name-only 2>/dev/null
git diff --cached --name-only 2>/dev/null
} | sort -u
fi
Loading