Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Added `/open-pr` workflow with review gate (#15042)
Damian Legawiec1af7990a8893
diff --git a/.claude/commands/implement-plan.md b/.claude/commands/implement-plan.mdindex 44df6a60f0..4bca3bf7bd 100644--- a/.claude/commands/implement-plan.md+++ b/.claude/commands/implement-plan.md@@ -189,8 +189,8 @@ Print, in one block the user can act on directly:## 10. Open the pull request and monitor it-- Squash fixups, make sure the branch is pushed to `spree/spree`, then open the- PR with `gh pr create --repo spree/spree --base main`. The title ends with+- Squash fixups, then run `/open-pr`. It runs the security review, records+ the reviewed commit, opens the PR and starts monitoring it. The title ends withthe Linear id in parentheses, the way the repository already does it:`Add order stages to the dashboard (V-1234)`. The body: what thechange does and why, which plan it implements and which phases, the@@ -207,8 +207,8 @@ Print, in one block the user can act on directly:reader coming from the Roadmap finds the code. When the PR merges, theplan's status becomes `Implemented` through `/project:update-plan`, whichmoves the trackers to Done and closes the GitHub issue.-- Run `/autofix-pr` to watch review comments (humans, Bugbot, CodeRabbit) and- CI, fix what comes back, and push. Stop and report clearly if something+- `/open-pr` ends by running `/autofix-pr`, which watches review comments+ (humans, Bugbot, CodeRabbit) and CI. Stop and report clearly if somethingneeds the user — a required review, a failing check you cannot reproducelocally, a permission error.diff --git a/.claude/commands/open-pr.md b/.claude/commands/open-pr.mdnew file mode 100644index 0000000000..d4cf958302--- /dev/null+++ b/.claude/commands/open-pr.md@@ -0,0 +1,52 @@+---+description: Review, security-review, open and monitor a pull request for the current branch.+---++Take the current branch from finished work to an open, monitored pull request+on `spree/spree`. Run the steps in order and skip none because the change looks+small. A pre-tool hook blocks `gh pr create` until steps 1–3 have run on the+current `HEAD`.++Never run this on `main`: branch first (`feat/`, `fix/` or `chore/`). Commit any+uncommitted work before step 1 so the reviews see it.++## 1. Code review++Run `/code-review --fix` on the branch. Re-run `pnpm test:changed`, then commit+the fixes. A finding you reject gets a one-line reason for the final report,+not silence.++## 2. Security review++Run `/security-review` on the branch. Fix every confirmed finding, re-run+`pnpm test:changed`, and commit. Record rejected findings the same way. If a+fix changed any file, go back to step 1 so the fix gets both reviews.++## 3. Record the reviewed commit++With the working tree clean:++```bash+git rev-parse HEAD > "$(git rev-parse --absolute-git-dir)/claude-reviewed"+```++Any later commit makes this stale; go back to step 1 before opening the PR.++## 4. Open the pull request++Push the branch, then open the PR with+`gh pr create --repo spree/spree --base main`. Follow AGENTS.md "Git" for the+title and body. When a Linear issue exists, end the title with its id in+parentheses and add `Linear: V-1234` on its own line in the body.++## 5. Monitor it++Run `/autofix-pr` to watch review comments and CI, fix what comes back, and+push each round as its own commit. Stop and report when something needs the+user: a required review, a failing check you cannot reproduce, a permission+error.++## Final report++The PR URL, the review findings fixed, the findings skipped with their reasons,+and the CI state when monitoring stopped.diff --git a/.claude/hooks/pre-commit-gate.sh b/.claude/hooks/pre-commit-gate.shindex 7f7940fc71..10711bca0b 100755--- a/.claude/hooks/pre-commit-gate.sh+++ b/.claude/hooks/pre-commit-gate.sh@@ -14,8 +14,10 @@set -u-# Parse the command out of the Claude hook input JSON.-cmd=$(jq -r '.tool_input.command // empty')+# Parse the command and its working directory out of the Claude hook input JSON.+input=$(cat)+cmd=$(jq -r '.tool_input.command // empty' <<<"$input")+hook_cwd=$(jq -r '.cwd // empty' <<<"$input")# Full test suites are queued machine-wide and are otherwise CI's job (see# AGENTS.md "Testing"). Block the bare forms so a session that has not read the@@ -46,21 +48,44 @@ done < <(echo "$cmd" | tr ';&|' '\n')# quoted strings (`echo 'git commit later'`) and other git subcommands# (`git checkout`, `git diff`) are not.#+# GIT_SUB holds the git subcommand of any git segment, matched or not.# On match, GIT_C_PATH holds the value passed to `-C` (empty when -C wasn't# used) so the caller can scope the gate to the repo the command targets.GIT_C_PATH=""+GIT_SUB=""++# Sets LAUNCHED to the segment without what runs in front of the real command:+# variable assignments (quoted values included), `env` with its options and+# assignments, `command` and `builtin`.+LAUNCHED=""+strip_launchers() {+ local s="$1" in_env=0 tok+ local assign="^[A-Za-z_][A-Za-z0-9_]*=(\"[^\"]*\"|'[^']*'|[^[:space:]\"']*)+"+ while :; do+ s="${s#"${s%%[![:space:]]*}"}"+ if [[ "$s" =~ $assign ]]; then s="${s:${#BASH_REMATCH[0]}}"; continue; fi+ tok="${s%%[[:space:]]*}"+ case "$tok" in+ env) in_env=1 ;;+ command|builtin) ;;+ -u|-C|--unset|--chdir)+ [ $in_env -eq 1 ] || break+ s="${s#"$tok"}"; s="${s#"${s%%[![:space:]]*}"}"; tok="${s%%[[:space:]]*}" ;;+ -*) [ $in_env -eq 1 ] || break ;;+ *) break ;;+ esac+ s="${s#"$tok"}"+ done+ LAUNCHED="$s"+}+match_segment() {local seg="$1"GIT_C_PATH=""+ GIT_SUB=""+ strip_launchers "$seg"# shellcheck disable=SC2086- set -- $seg- # Skip leading env-var assignments (FOO=bar git ...)- while [ $# -gt 0 ] && [[ "$1" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; do shift; done- # Skip optional `env` plus its own env assignments (env FOO=bar git ...)- if [ "${1:-}" = "env" ]; then- shift- while [ $# -gt 0 ] && [[ "$1" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; do shift; done- fi+ set -- $LAUNCHED# Must now start with literal `git`[ "${1:-}" = "git" ] || return 1shift@@ -77,10 +102,42 @@ match_segment() {*) break ;;esacdone- case "${1:-}" in commit|push) return 0 ;; esac+ GIT_SUB="${1:-}"+ case "$GIT_SUB" in commit|push) return 0 ;; esacreturn 1}+# Pull requests open through /open-pr, which runs /code-review and+# /security-review and then records the reviewed HEAD in the git dir. Block+# `gh pr create` until that marker matches HEAD in the session's directory, so+# a commit made after the reviews sends the branch back through them. The check+# runs before the command does, so an earlier step in the same command that+# changes directory or may move HEAD is blocked rather than parsed.+pr_dir="${hook_cwd:-${CLAUDE_PROJECT_DIR:-.}}"+gh_pr_create='^gh([[:space:]]+-[^[:space:]]+([[:space:]]+[^-[:space:]][^[:space:]]*)?)*[[:space:]]+pr[[:space:]]+create([[:space:]);}]|$)'+chained=0+while IFS= read -r segment; do+ seg="${segment#"${segment%%[ ;; *) chained=1 ;; esac+ continue+ fi+ if [[ "$LAUNCHED" =~ ^(cd|pushd|popd)([[:space:]]|$) ]]; then chained=1; continue; fi+ [[ "$LAUNCHED" =~ $gh_pr_create ]] || continue+ if [ $chained -eq 1 ]; then+ echo "Blocked: $seg" >&2+ echo "Run gh pr create as its own command: an earlier cd or git step in the same command changes what it would open." >&2+ exit 2+ fi+ head=$(git -C "$pr_dir" rev-parse HEAD 2>/dev/null)+ marker="$(git -C "$pr_dir" rev-parse --absolute-git-dir 2>/dev/null)/claude-reviewed"+ if [ -z "$head" ] || [ "$(cat "$marker" 2>/dev/null)" != "$head" ]; then+ echo "Blocked: $seg" >&2+ echo "Open pull requests with /open-pr: /code-review and /security-review have not run on this HEAD. See AGENTS.md, Git." >&2+ exit 2+ fi+done < <(echo "$cmd" | tr ';&|' '\n')+trigger=0while IFS= read -r segment; doif match_segment "$segment"; then trigger=1; break; fidiff --git a/AGENTS.md b/AGENTS.mdindex 7815a7290e..b7d7c529b6 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -74,6 +74,7 @@ pnpm wt:template # rebuild the template DB after schema-changing pulls- Never commit to `main`. Branches start with `feat/`, `fix/` or `chore/`; bug-fix commits start with `Fix: `.- Titles use plain verbs (Added, Removed, Fixed, Changed). Bodies are three or four sentences on what and why.- No co-author or "generated with" trailers.+- Open every pull request with `/open-pr` (code review, security review, open, monitor). A hook blocks a bare `gh pr create` until both reviews have run on `HEAD`.- Pull request descriptions are public: no credentials, personal data or local URLs. Keep them short; bullets for larger changes.## Testing