Determine what to show. Check these in priority order to pick the right air invocation:
a. Specific commit or range requested by the user:
Run air --commit <hash> or air --commits <range>.
b. Uncommitted changes exist (staged or unstaged, check via git status --porcelain):
Run air with no flags. This shows the working directory diff.
c. Clean tree, on a gg stack branch — the current branch matches the user/name pattern (no -- in the name part) and .git/gg/config.json exists:
Read the gg base branch from config (parse defaults.base, fall back to main). Run:
air --commits <gg-base>..HEAD
This shows the full stack diff, matching what ai-review displays when opening a gg stack.
d. Clean tree, on a feature branch (not main/master):
Determine the base branch (main or master, whichever exists). Run:
air --branch <base-branch>
e. Clean tree, on main/master with unpushed commits:
Run git log origin/main..HEAD --oneline --reverse (or origin/master) and take the first commit hash. Run:
air --commit <first-unpushed-commit-hash>
f. None of the above: Run air with no flags (empty diff — the app handles it).