---
name: gp
description: >-
  Git push with checks and report. Used when the user writes "push", "gp",
  "git push", or after running /skill:do and /skill:review to send changes.
---

# Git push with checks and report

Push orchestrator: collect state, push, report. Runs autonomously — no confirmation prompts.

## Input

The user input after `/skill:gp` may include optional flags, currently `--force-with-lease`.

---

## Step 1 — Pre-check

Run the yoke-pi helper script. Resolve it without Claude-specific environment variables:

```bash
SCRIPT=""
for p in \
  "./lib/gp-precheck.sh" \
  "$HOME/.pi/agent/npm/node_modules/yoke-pi/lib/gp-precheck.sh" \
  ".pi/npm/node_modules/yoke-pi/lib/gp-precheck.sh"; do
  if [ -f "$p" ]; then SCRIPT="$p"; break; fi
done
if [ -z "$SCRIPT" ]; then
  echo "ERROR: lib/gp-precheck.sh not found. Run from the yoke-pi repo root or install yoke-pi as a pi package."
else
  bash "$SCRIPT"
fi
```

Parse the structured block. Single-value fields are `KEY: value`; list fields (`UNCOMMITTED_LIST`) span from the line after `KEY:` to the next top-level `KEY:`.

If the script prints `ERROR:`, report it and stop.

---

## Step 2 — Decide

Blocking (report and stop):

- `ERRORS` contains `detached HEAD` → "Checkout a branch before push".
- `ERRORS` contains `no remote` → "Add a remote: `git remote add origin <url>`".
- `UNPUSHED_COMMITS = 0` and `HAS_UPSTREAM = true` → "Nothing to push" (if `UNCOMMITTED_FILES > 0`, add: commit first with `/skill:gca`).

Non-blocking:

- `GH_AUTH != ok` → push still proceeds; only PR/URL info is skipped in the report.
- `UNCOMMITTED_FILES > 0` → never blocks. `git push` sends only commits; note them in the report.

PUSH_MODE:

- `HAS_UPSTREAM = false` → `set-upstream`
- user input contains `--force-with-lease` → `force-with-lease`
- otherwise → `normal`

---

## Step 3 — Push

Run the yoke-pi push helper with the `BRANCH` and `PUSH_MODE` values:

```bash
SCRIPT=""
for p in \
  "./lib/gp-push.sh" \
  "$HOME/.pi/agent/npm/node_modules/yoke-pi/lib/gp-push.sh" \
  ".pi/npm/node_modules/yoke-pi/lib/gp-push.sh"; do
  if [ -f "$p" ]; then SCRIPT="$p"; break; fi
done
if [ -z "$SCRIPT" ]; then
  echo "ERROR: lib/gp-push.sh not found. Run from the yoke-pi repo root or install yoke-pi as a pi package."
else
  bash "$SCRIPT" "<BRANCH>" "<PUSH_MODE>"
fi
```

Replace `<BRANCH>` and `<PUSH_MODE>` with the parsed values before running.

If `PUSH_STATUS = FAILED` → show `PUSH_ERROR`. If it contains "non-fast-forward" → suggest `git pull --rebase` or `/skill:gp --force-with-lease`. Stop.

---

## Step 4 — Report

Fill from the `gp-push.sh` block; `Commits:` ← `PUSHED_LIST`:

```text
Pushed to origin/<BRANCH>: +<PUSHED_COMMITS> commits

Commits:
  <PUSHED_LIST>

Stats: <DIFF_STAT>
Link: <BRANCH_URL>
```

- Omit the `Link:` line when `BRANCH_URL = empty`.
- `PR_EXISTS = true` → add `PR: <PR_TITLE> (<PR_URL>)` and suggest `/skill:pr` to update it.
- `PR_EXISTS = false` → suggest `/skill:pr` to create one.
- `UNCOMMITTED_FILES` (carried from Step 1) `> 0` → add `Uncommitted (not pushed): <N> files`.

Print the report and the suggestion — do not ask a follow-up question.

---

## Rules

- Runs autonomously: no confirmation prompts.
- Remote: `origin`. When multiple remotes exist — push to origin.
- `gh` is optional; its absence only removes PR/URL info, never blocks the push.
- The only mutation is `git push` (inside `lib/gp-push.sh`).
- Output limit: max 20 commits.
