End-to-end commit workflow. /commit analyzes the working tree, asks
the agent for a conventional-commit plan (single or multi), executes
after explicit confirmation, pushes with fork-aware routing and
head-drift detection, and creates or updates the PR. Auto-appends
Closes #N when the branch is linked to a tracking issue — closing
the loop on /develop's park path.
Ported from an internal commit automation plugin. The
deterministic parts (preflight, pickers, push routing, head-drift
detection, gh calls) live in TypeScript; commit-message and PR-body
generation stay on the main agent via pi.sendMessage +
ctx.waitForIdle().
pi install git:github.com/vegardx/pi-ext-commitindex.ts—/commit [guidance]command. Drives the workflow end-to-end.helpers.ts— pure helpers:parseTitleAndBody(text)— pulls TITLE/BODY out of the agent's PR replyisSafeBranchName/isValidIssueNumber— shell-injection guardsbuildForkUrl(originUrl, forkNameWithOwner)— swaps the path component of the origin URL while preserving host, protocol, and auth bits. Used to add a fork remote on a cross-repo PR.summarisePlan(text)— first usable line, for picker titles.
git.ts— thinspawnSyncwrappers for every git op we do.gh.ts—ghwrappers:findOpenPr,viewPr,createPr,editPrwith JSON parsing and error surfacing.skills/commit/SKILL.md— the workflow described for the agent. Usable standalone via/skill:commiteven without the extension.__tests__/helpers.test.ts— 24+ tests for pure helpers.
| Command | Effect |
|---|---|
/commit |
Full workflow: analyze → propose → execute → push → PR. |
/commit <guidance> |
Same, but hands the guidance to the agent as the starting point for the plan. |
- Preflight — verify repo, working tree has changes, current
branch is safe. If you're on the default branch, a confirm dialog
asks whether to continue (you usually want to branch first via
/develop <desc>). - Offer
/review— picker: run review first, or commit now. If review, the extension prints the follow-up instruction and stops. - Plan —
pi.sendMessage(..., deliverAs: "followUp", triggerTurn: true)with a prompt asking the agent to analyze the diff and propose a conventional-commit plan.ctx.waitForIdle()blocks the command until the agent's turn ends. - Execute picker — Commit / Edit plan / Cancel. Edit opens
ctx.ui.editorprefilled with the agent's plan; the edited text is handed back to the agent verbatim as the execution instruction. - Execute — another
sendMessage+waitForIdle. The agent runsgit add <explicit paths>andgit commitper the plan. After the turn, the extension comparesHEADbefore/after; if nothing advanced, it aborts the push/PR steps. - Push picker — Push and manage PR / Push only / Don't push.
- Push routing — if no PR or same-repo PR, push to
origin. If cross-repo withmaintainerCanModify: false, offergit format-patchinstead of pushing. If cross-repo withmaintainerCanModify: true, add the fork as a remote (URL derived from origin with path swapped), fetch, and push there. - Head-drift —
git merge-base --is-ancestorthen tree comparison to distinguish "author amended/rebased to same content" from "real new upstream commits". In the first case,git rebase --ontoreplays automatically; in the second, the user is asked Rebase/Force-push/Abort. - Tracking issue — read
branch.<name>.tracking-issue. If unset, optionally offer to link one (digits-only validation). - PR title/body — the agent is asked to emit title and body
wrapped in
---TITLE---/---BODY---/---END---sentinels. The extension parses them, previews, and offers Create/Update, Edit first, or Skip. - Return to default — optional
git checkout + pullof the default branch.
This closes the loop on /develop's park path. When the user runs
/develop <desc> and picks Park, the extension persists
git config branch.<name>.tracking-issue <N> where <N> is the
created issue number. When the user later creates the branch (manually
or via /develop <same desc> + Implement) and runs /commit, step 9
reads that config and step 10 appends Closes #<N> to the PR body.
GitHub auto-closes the issue when the PR merges into the default
branch.
Before this package: the /park config was dead code — nothing read it.
- Never stages via
-A/-u/.. The plan prompt explicitly instructs the agent to use explicit paths, because blanket staging can pick up.envfiles and other files the user didn't mean to commit. - Explicit confirmation before any git mutation. No commits are made before the Commit picker resolves.
- Force-push requires two confirmations — the fork-drift picker AND a separate confirm dialog. Never implicit.
- Shell-injection guards on every branch name and issue number
interpolated into
git configkeys.
git clone https://github.com/vegardx/pi-ext-commit
cd pi-ext-commit
npm install
npm run check # lint + typecheck + test
pi -e . # load extension locallyTry on a small change:
/commit
Walk through the workflow. To exercise the editor, pick "Edit plan
before committing" at step 4. To exercise fork handling, open a PR
from a fork (by forking the repo and opening a PR upstream) and run
/commit on the upstream clone.
ghrequired for the push + PR steps. Ifghisn't installed or authed, the push step stops with an error; commits remain local.- Host routing relies on
gh's auto-detection. See/skill:ghfor the rules. Works for publicgithub.com, GHEC-DR tenants, and GHES. If you're operating on a non-default host and a cross-repo PR,buildForkUrlpreserves the host — tested for both SSH and HTTPS origin formats. - No squash/rebase merge. We create/update the PR; merging is
still a user decision (via
gh pr mergeor the GitHub UI). - No commit-message signing. The agent runs
git commitwith whatever your local config specifies (GPG/SSH sign if enabled, otherwise unsigned). We don't pass-Sourselves. - Agent must emit TITLE/BODY sentinels. If the agent ignores the format instruction, the extension skips the PR step with a warning. The user can still create the PR manually.
MIT
pi-ext-develop— plans a change;/parkwrites the tracking issue this command reads.pi-ext-review— multi-agent code review, recommended before committing.pi-ext-gh— multi-host routing reference.