@imdeadpool/guardex 7.1.1 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +115 -324
  2. package/package.json +23 -5
  3. package/skills/gitguardex/SKILL.md +83 -3
  4. package/src/agents/finish.js +15 -0
  5. package/src/ci-init/index.js +0 -1
  6. package/src/cli/args.js +137 -3
  7. package/src/cli/commands/branch.js +267 -14
  8. package/src/cli/commands/claude.js +15 -0
  9. package/src/cli/commands/doctor.js +26 -0
  10. package/src/cli/commands/onboard.js +293 -0
  11. package/src/cli/commands/prompt.js +15 -3
  12. package/src/cli/commands/review.js +18 -0
  13. package/src/cli/commands/setup.js +8 -6
  14. package/src/cli/commands/status.js +12 -0
  15. package/src/cli/main.js +2 -0
  16. package/src/cli/shared-locks.js +304 -0
  17. package/src/context.js +21 -3
  18. package/src/core/runtime.js +33 -1
  19. package/src/doctor/index.js +58 -5
  20. package/src/finish/heartbeat.js +169 -0
  21. package/src/finish/index.js +106 -4
  22. package/src/finish/progress.js +262 -0
  23. package/src/finish/review-gate.js +453 -32
  24. package/src/github-api.js +59 -0
  25. package/src/mcp/collect.js +87 -12
  26. package/src/output/index.js +210 -0
  27. package/src/pr-checks.js +121 -0
  28. package/src/pr-review.js +581 -51
  29. package/src/pr.js +143 -21
  30. package/src/provider-binary.js +101 -0
  31. package/src/review-diff.js +116 -0
  32. package/src/review-fix.js +229 -0
  33. package/src/sandbox/index.js +11 -5
  34. package/src/scaffold/index.js +4 -16
  35. package/src/shared-git-state.js +566 -0
  36. package/templates/AGENTS.multiagent-safety.md +63 -11
  37. package/templates/AGENTS.multiagent-safety.min.md +1 -0
  38. package/templates/codex/skills/gitguardex/SKILL.md +83 -3
  39. package/templates/githooks/post-checkout +4 -9
  40. package/templates/githooks/pre-commit +17 -1
  41. package/templates/github/workflows/README.md +30 -23
  42. package/templates/scripts/agent-autofinish-watch.sh +280 -0
  43. package/templates/scripts/agent-branch-finish.sh +354 -23
  44. package/templates/scripts/agent-branch-start.sh +49 -22
  45. package/templates/scripts/agent-claude-stop-finish.sh +194 -0
  46. package/templates/scripts/agent-file-locks.py +167 -24
  47. package/templates/scripts/agent-preflight.sh +14 -2
  48. package/templates/scripts/agent-stalled-report.sh +40 -0
  49. package/templates/scripts/codex-agent.sh +10 -63
  50. package/templates/github/workflows/cr.yml +0 -46
@@ -20,7 +20,9 @@ For typos, single-file tweaks, one-liners, version bumps, comment-only changes,
20
20
 
21
21
  Lightweight escape prefixes: `quick:`, `simple:`, `tiny:`, `minor:`, `small:`, `just:`, `only:`.
22
22
 
23
- Promote to full Guardex / OMX orchestration only when scope grows into multi-file behavior change, API/schema work, refactor, migration, architecture, cross-cutting scope, long prompt, or multi-agent execution.
23
+ Promote to full Guardex / OMX orchestration only when scope grows into multi-file behavior change, API/schema work, refactor, migration, architecture, cross-cutting scope, long prompt, or multi-agent execution. Orchestration alone does not require OpenSpec.
24
+
25
+ OpenSpec is opt-in. Do not create or update OpenSpec artifacts unless the user asks for them, the task continues an existing OpenSpec change, or an explicit T2/T3 workflow is selected.
24
26
 
25
27
  ### Isolation (the load-bearing rule)
26
28
 
@@ -50,9 +52,7 @@ If you are about to type `git checkout agent/...` from the primary checkout, **s
50
52
 
51
53
  ### Dirty-tree rule
52
54
 
53
- Finish or stash edits inside the worktree they belong to before any branch switch on primary. The post-checkout guard may auto-stash a dirty primary tree as `guardex-auto-revert <ts> <prev>-><new>` — that is a safety net, not a workflow.
54
-
55
- Recover: `git stash list | grep 'guardex-auto-revert'`.
55
+ Finish or stash edits inside the worktree they belong to before any branch switch on primary. The post-checkout guard auto-reverts only a clean primary tree. If the primary tree is dirty, it leaves the branch and files in place and prints a manual recovery hint instead of stashing or reverting someone else's work.
56
56
 
57
57
  ### Ownership
58
58
 
@@ -76,7 +76,7 @@ When posting handoff or working-state notes (`.omx/notepad.md`, PR description,
76
76
  branch=<branch>; task=<task>; blocker=<blocker>; next=<next>; evidence=<path|command|PR|spec>
77
77
  ```
78
78
 
79
- No long proof dumps, no stale narrative, no full logs. Bulky proof goes in OpenSpec artifacts, PRs, or command output.
79
+ No long proof dumps, no stale narrative, no full logs. Bulky proof goes in PRs or command output; do not create OpenSpec artifacts only to hold routine progress.
80
80
 
81
81
  ### Completion
82
82
 
@@ -88,7 +88,58 @@ gx branch finish --branch "<agent-branch>" --via-pr --wait-for-merge --cleanup
88
88
  gx finish --all
89
89
  ```
90
90
 
91
- Task scaffolds and manual task edits must include a final completion/cleanup section that ends with PR merge + sandbox cleanup and records PR URL + final `MERGED` evidence.
91
+ **Default to the self-repairing gated ship.** Unless the user says keep-local, end
92
+ a task with the gate armed so review findings are fixed and re-verified before the
93
+ merge, instead of leaving a PR open for a human to chase:
94
+
95
+ ```bash
96
+ gx branch finish --branch "<agent-branch>" --base <base> \
97
+ --via-pr --wait-for-merge --cleanup \
98
+ --gate-review --gate-autofix
99
+ ```
100
+
101
+ What each flag buys, and why they are not optional in an unattended run:
102
+
103
+ - `--gate-review` — fail-CLOSED. Blocks the merge on any HIGH/CRITICAL finding, on
104
+ red CI, and on GitHub reporting the PR unmergeable. A provider error or timeout
105
+ also blocks; it is never read as clean.
106
+ - `--gate-autofix` — on a blocking verdict, repairs the findings in the worktree,
107
+ pushes, and RE-REVIEWS with a fresh provider run before deciding. Bounded by
108
+ `--gate-autofix-rounds N` (1-5, default 1). A repair round that changes nothing
109
+ stops the loop rather than spinning.
110
+ - `--gate-baseline` — add this only in a repo whose base branch CI is already red.
111
+ It gates on "this change adds no NEW failing check" instead of absolute green,
112
+ comparing against the base branch and the last merged PR.
113
+
114
+ Three knobs for how long the gate takes without removing a gate:
115
+
116
+ - CI waits for the review by default: the PR remains draft while the provider
117
+ runs, preserving GitHub's hard "draft PRs cannot merge" barrier until the
118
+ verdict is clean. `--no-gate-serial-ci` opts into promoting before review so
119
+ CI overlaps the review — faster, but it leaves a ready PR while the review is
120
+ still pending.
121
+ - Codex review and fix agents default to bounded `medium` reasoning effort instead
122
+ of inheriting an interactive session's potentially slow `xhigh`; set
123
+ `GUARDEX_REVIEW_CODEX_EFFORT=low|medium|high|xhigh` to override it.
124
+ - `--review-model <name>` (or `GUARDEX_REVIEW_MODEL`) picks the review model, and
125
+ `GUARDEX_REVIEW_CLAUDE_BIN` / `GUARDEX_REVIEW_CODEX_BIN` name the binary to run
126
+ — useful when the provider's name on PATH resolves to a launcher whose startup
127
+ is charged to every review round.
128
+
129
+ Two things the gate deliberately will NOT do, so do not expect them:
130
+
131
+ - **It never accepts a finding's disappearance as a fix.** A file that carried a
132
+ blocking finding must either still be under review or have actually been edited
133
+ by a repair round; otherwise the merge blocks. Review providers are
134
+ nondeterministic, and a HIGH that simply fails to reappear is not a fixed HIGH.
135
+ - **It never lets the fixer grade its own work.** Every repair is judged by a
136
+ separate review invocation.
137
+
138
+ Posting a review is NOT merging. `gx pr-review` / `gx review` post findings and
139
+ exit; only `gx branch finish` (or `gx ship`) merges. A PR sitting open with a
140
+ clean review means the finish flow was never run.
141
+
142
+ When an explicit task scaffold exists, its final section must end with PR merge + sandbox cleanup and record PR URL + final `MERGED` evidence. Routine work does not need a scaffold.
92
143
 
93
144
  Task is complete only when **all six** are true:
94
145
 
@@ -113,7 +164,7 @@ Assume other agents edit nearby. Never revert unrelated changes. Never simplify
113
164
 
114
165
  ### Reporting
115
166
 
116
- Every completion handoff includes: branch, task, files changed, behavior touched, verification commands + results, PR URL, merge state, sandbox cleanup state, risks/follow-ups.
167
+ Keep the completion handoff to at most five short lines: outcome, files/behavior, verification, PR/merge/cleanup, and only material risk.
117
168
 
118
169
  Blocked? Use:
119
170
 
@@ -132,13 +183,14 @@ Before claiming completion, run the narrowest meaningful verification (`pnpm tes
132
183
 
133
184
  ### Open questions
134
185
 
135
- Persist unresolved questions or blockers into `openspec/plan/<plan-slug>/open-questions.md` as unchecked items. Resolve in-place rather than burying in chat.
186
+ Report unresolved blockers concisely. Persist them in `openspec/plan/<plan-slug>/open-questions.md` only when that explicit plan workspace already exists.
136
187
 
137
188
  ### Optional companion tooling (use if installed)
138
189
 
139
190
  - **fff MCP** (file search): prefer for all file search; fall back to `rtk grep`/`rtk find` or `rg`.
140
- - **rtk** (shell compression): wrap noisy discovery (`rtk ls`/`grep`/`find`/`read`), git/gh (`rtk git status`/`gh pr list`), and verification (`rtk tsc`/`lint`/`test`). Do **not** wrap machine-readable commands (`--porcelain`, `--json`, exact stdout contracts).
141
- - **OpenSpec**: keep `openspec/changes/<slug>/tasks.md` current during work, not batched. Validate with `openspec validate --specs` before archive.
191
+ - **rtk** (shell compression): wrap noisy discovery (`rtk ls`/`grep`/`find`/`read`), git/gh (`rtk git status`/`gh pr list`), verification (`rtk tsc`/`lint`/`test`), and noisy gx reads (`rtk gx status`/`rtk gx doctor`). Do **not** wrap machine-readable commands (`--porcelain`, `--json`, exact stdout contracts) or shell-ready output (`gx prompt --exec`).
192
+ - **headroom** (context compression): when available, run large `gx` output, long logs, and big file/diff dumps through `headroom_compress` before reasoning over them (reversible — `headroom_retrieve` restores). Or set `GUARDEX_COMPRESS_CMD="<filter>"` so gx routes its own large narrative output — `gx prompt`, `gx prompt --snippet` — through your compressor (terse/non-TTY only, fail-open, JSON skipped; `--exec` stays raw). Keep PR URLs, branch names, and file paths visible; never compress `--json`/`--porcelain` or values you act on verbatim.
193
+ - **OpenSpec (opt-in)**: use it only for a user-requested or explicit T2/T3 workflow. When active, update checkpoints at meaningful milestones rather than after every tool call, then validate before archive.
142
194
 
143
195
  ### Token / context budget
144
196
 
@@ -163,7 +215,7 @@ Fan-out saves tokens only when each agent has a narrow job and returns a compact
163
215
 
164
216
  ### Version bumps
165
217
 
166
- If a change bumps a published version, the same PR records release notes in the appropriate OpenSpec artifact or release-note mechanism for the repo. Do not edit `CHANGELOG.md` directly unless the repo explicitly requires manual changelog edits.
218
+ If a change bumps a published version, the same PR records release notes in the repository's release-note mechanism. Do not create OpenSpec solely for a version bump, and do not edit `CHANGELOG.md` directly unless the repo explicitly requires it.
167
219
 
168
220
  ### What not to put in this file
169
221
 
@@ -6,6 +6,7 @@ Guardex is enabled by default. Disable via repo-root `.env` with `GUARDEX_ON=0`.
6
6
  - Work from an `agent/*` branch + worktree — never edit the protected base (`main`/`dev`) directly. Start with `gx branch start "<task>" "<agent-name>"`, then `cd` into the printed worktree.
7
7
  - Claim files before editing: `gx locks claim --branch "<agent-branch>" <file...>`.
8
8
  - Finish completed work via PR + cleanup: `gx branch finish --branch "<agent-branch>" --via-pr --wait-for-merge --cleanup` (or `gx finish --all`).
9
+ - Default to the self-repairing gated ship — add `--gate-review --gate-autofix` so blocking findings are fixed and re-verified before the merge instead of leaving the PR open. Add `--gate-baseline` only where the base branch CI is already red. CI waits until the review is clean by default; `--no-gate-serial-ci` opts into overlap. Codex code-assist defaults to bounded `medium` effort (override with `GUARDEX_REVIEW_CODEX_EFFORT`). Posting a review is not merging: `gx pr-review` posts and exits; only `gx branch finish` merges.
9
10
 
10
11
  Want the full multi-agent contract (Colony coordination, OpenSpec, token discipline, recovery)? Run `gx setup --contract`.
11
12
  <!-- multiagent-safety:END -->
@@ -1,13 +1,93 @@
1
1
  ---
2
2
  name: gitguardex
3
- description: "Repo guardrail check and repair."
3
+ description: "Use for GitGuardex branch/worktree safety, agent or subagent collision avoidance, file ownership, and gated PR finishing. Not for code-quality review."
4
4
  ---
5
5
 
6
- Use when repo safety may be broken.
6
+ Use when a GitGuardex-managed repository needs safe edits or multi-agent coordination.
7
7
 
8
8
  `gx status` -> `gx doctor` -> `gx status --strict`
9
9
 
10
10
  Bootstrap: `gx setup`
11
11
  Ops: `gx branch start "<task>" "<agent>"`, `gx locks claim --branch "<agent-branch>" <file...>`, `gx branch finish --branch "<agent-branch>" --base <base> --via-pr --wait-for-merge --cleanup`, `gx finish --all`, `gx cleanup`
12
12
 
13
- When inspecting or verifying, prefer `rtk` compact wrappers if available (`rtk git status`, `rtk grep`, `rtk test <cmd>`). Do not wrap commands whose stdout is parsed by scripts.
13
+ ## Keep the default workflow lean
14
+
15
+ - Default to direct T1 work in code and tests. Do not create OpenSpec artifacts from task wording alone.
16
+ - OpenSpec is explicit opt-in: use `--tier T2` for a change workspace or `--tier T3` for change plus plan only when the user requests OpenSpec or the caller explicitly selects T2/T3.
17
+ - Treat the commit, targeted test output, and compact final handoff as the routine task record.
18
+
19
+ ## Agent and subagent collaboration
20
+
21
+ Before parallel work, inspect the field with the MCP `list_agents` tool or the CLI fallback:
22
+
23
+ ```sh
24
+ gx mcp list-agents --no-prs
25
+ ```
26
+
27
+ For every file a writer may touch, check ownership, create an isolated lane, then claim it:
28
+
29
+ ```sh
30
+ gx mcp who-owns path/to/file.ts
31
+ gx branch start "<bounded task>" "<agent>"
32
+ gx locks claim --branch "<agent-branch>" path/to/file.ts
33
+ ```
34
+
35
+ - **One owner per file.** Split writer subagents by non-overlapping files or modules. Read-only scouts may share a surface; writers may not.
36
+ - Give each subagent one bounded objective and a verification command. Do not ask one subagent to explore, redesign, implement, and review the same slice.
37
+ - Re-check `list_agents` before expanding scope. If another lane owns or is already editing a file, coordinate a handoff or choose a different slice.
38
+ - Return a compact handoff: conclusion, `file:line`, changed files, verification result, and blocker or next action. Do not relay full logs.
39
+ - Finish each writing lane through its own PR once. Never run duplicate finish commands for the same branch.
40
+
41
+ ## Optional cross-machine Git lock and radar state
42
+
43
+ Local worktree locks remain the default. When agents on multiple machines use the same writable Git remote, opt into shared state per repository:
44
+
45
+ ```sh
46
+ gx locks shared-enable --remote origin
47
+ gx locks shared-status
48
+ ```
49
+
50
+ After enablement, ordinary `claim`, `allow-delete`, `validate`, `release`, and `status` commands also use atomic remote refs under `refs/gitguardex/locks/*`. `gx mcp list-agents` combines local worktrees with remote `agent/*` branches and shared lock owners; `gx mcp who-owns` resolves the same shared owner data.
51
+
52
+ - Shared mode is explicit and fail-closed: if the remote is unreachable, rejects custom refs, or returns invalid metadata, do not keep a local-only claim or approve a commit.
53
+ - The remote must allow authenticated custom-ref creation, compare-and-swap updates, and deletion. GitGuardex stores validated JSON metadata in commits; it never executes remote metadata, and publishes only a hashed machine identifier.
54
+ - Push the agent branch when full remote-lane visibility matters. A lock still makes an unpushed branch visible as a lock-owning remote lane.
55
+ - Release locks before disabling shared state or abandoning a lane. Cross-machine locks are not automatically reaped because one host cannot safely prove that another host's process is dead.
56
+ - `gx locks shared-disable` stops shared reads and writes for this repository; it does not delete remote refs owned by any machine.
57
+
58
+ ## Finish checklist in Codex
59
+
60
+ Before starting a long `gx finish`, `gx ship`, or `gx branch finish`, show this compact Markdown checklist in commentary and update it from the CLI's `[gx:finish]` transition lines:
61
+
62
+ - [ ] Prepare branch
63
+ - [ ] Local preflight
64
+ - [ ] Push and open PR
65
+ - [ ] AI review
66
+ - [ ] Review autofix
67
+ - [ ] CI checks
68
+ - [ ] Merge
69
+ - [ ] Cleanup
70
+
71
+ Render each state-change update as a compact card, not as a raw log dump:
72
+
73
+ ### 🚀 GX Finish · `3/8`
74
+ `agent/...` → `main` · 🔄 **AI review** · `00:44`
75
+
76
+ - ✅ Prepare branch
77
+ - ✅ Local preflight
78
+ - ✅ Push and open PR · `#123`
79
+ - 🔄 AI review
80
+ - ⬜ Review autofix
81
+ - ⬜ CI checks
82
+ - ⬜ Merge
83
+ - ⬜ Cleanup
84
+
85
+ Start the command with a short initial yield, then poll the background process every 15-30 seconds. Between polls, post an updated checklist when the active stage changes; during a quiet long stage, name the active stage and elapsed time at most every 30 seconds. Never leave the user with only Codex's generic **Working** or **Waiting for background terminal** label. Do not launch a duplicate finish while the first process is still alive, and do not mark a checkbox complete until a matching `✓` line or equivalent terminal evidence arrives.
86
+
87
+ Treat `🏁 Cleanup` as finished-but-best-effort, not as unconditional success: surface any cleanup warnings beside it instead of converting it to `✅`.
88
+
89
+ Structured phase events are persisted privately under `.omx/state/finish-runs/*.jsonl` (`0700` directory, `0600` files). Prefer that JSONL stream over parsing narrative logs when exact state is needed; the visual output prints the active event-file path.
90
+
91
+ When inspecting or verifying, prefer `rtk` compact wrappers if available (`rtk git status`, `rtk grep`, `rtk test <cmd>`, and noisy gx reads like `rtk gx status` / `rtk gx doctor`). Do not wrap commands whose stdout is parsed by scripts (`--json`, `--porcelain`, exact stdout contracts) or shell-ready output (`gx prompt --exec`).
92
+
93
+ To shrink gx's own large narrative output (e.g. `gx prompt`, `gx prompt --snippet`) before it lands in your context, set `GUARDEX_COMPRESS_CMD="<stdin->stdout filter>"`; gx routes that output through the filter (terse/non-TTY mode, fail-open, JSON skipped). Unset = byte-for-byte unchanged. Confirm it is wired with `gx status` or `gx doctor` — both print a `Token compression` line and flag a configured-but-missing binary (doctor's warning is advisory and never changes its safe/unsafe exit code).
@@ -67,20 +67,15 @@ echo "[agent-primary-branch-guard] The primary working tree must stay on its bas
67
67
  echo "[agent-primary-branch-guard] Use 'git worktree add' (or gx branch start) for feature work." >&2
68
68
 
69
69
  if [[ "$is_agent" == "1" ]]; then
70
- echo "[agent-primary-branch-guard] Agent session detected — reverting to '$prev_branch'." >&2
70
+ echo "[agent-primary-branch-guard] Agent session detected." >&2
71
71
  echo "[agent-primary-branch-guard] Bypass with GUARDEX_ALLOW_PRIMARY_BRANCH_SWITCH=1 if truly intentional." >&2
72
72
  if git diff --quiet && git diff --cached --quiet; then
73
+ echo "[agent-primary-branch-guard] Clean tree detected — reverting to '$prev_branch'." >&2
73
74
  GUARDEX_ALLOW_PRIMARY_BRANCH_SWITCH=1 git checkout "$prev_branch" >/dev/null 2>&1 || true
74
75
  echo "[agent-primary-branch-guard] Reverted to '$prev_branch'." >&2
75
76
  else
76
- stash_msg="guardex-auto-revert $(date +%s) ${prev_branch}->${new_branch}"
77
- if git stash push --include-untracked -m "$stash_msg" >/dev/null 2>&1; then
78
- GUARDEX_ALLOW_PRIMARY_BRANCH_SWITCH=1 git checkout "$prev_branch" >/dev/null 2>&1 || true
79
- echo "[agent-primary-branch-guard] Dirty tree auto-stashed as '$stash_msg'; primary reverted to '$prev_branch'." >&2
80
- echo "[agent-primary-branch-guard] Restore later with: git stash list | grep 'guardex-auto-revert'" >&2
81
- else
82
- echo "[agent-primary-branch-guard] Auto-stash failed; working tree left on '$new_branch'. Fix manually: git stash -u && git checkout $prev_branch" >&2
83
- fi
77
+ echo "[agent-primary-branch-guard] Working tree dirty — auto-revert skipped to avoid moving uncommitted work." >&2
78
+ echo "[agent-primary-branch-guard] Primary checkout left on '$new_branch'. Commit or stash the changes in the correct worktree, then recover manually with: GUARDEX_ALLOW_PRIMARY_BRANCH_SWITCH=1 git checkout '$prev_branch'" >&2
84
79
  fi
85
80
  else
86
81
  echo "[agent-primary-branch-guard] Bypass with GUARDEX_ALLOW_PRIMARY_BRANCH_SWITCH=1 if intentional." >&2
@@ -213,11 +213,27 @@ if [[ "$branch" == agent/* ]]; then
213
213
  # Auto-claim non-deletion staged paths. Deletions need an explicit
214
214
  # `--allow-delete` flag below so `locks validate --staged` doesn't
215
215
  # reject the commit on the same trip the user staged the delete.
216
+ # Claim in ONE call: each `locks claim` spawns node -> python and rescans
217
+ # every worktree's lock file, so a per-file loop cost ~150ms per staged
218
+ # path (3.6s for 24 files across 12 worktrees) on every single commit.
219
+ _staged_files=()
216
220
  while IFS= read -r staged_file; do
217
221
  [[ -z "$staged_file" ]] && continue
218
222
  [[ "$staged_file" == ".omx/state/agent-file-locks.json" ]] && continue
219
- run_guardex_cli locks claim --branch "$branch" "$staged_file" >/dev/null 2>&1 || true
223
+ _staged_files+=("$staged_file")
220
224
  done < <(git diff --cached --name-only --diff-filter=ACMRTUXB)
225
+ if (( ${#_staged_files[@]} > 0 )); then
226
+ # `locks claim` is atomic: one foreign-owned path rejects the whole
227
+ # batch. Fall back to per-file claims so the rest still get claimed and
228
+ # the `validate` below names only the genuinely conflicting path instead
229
+ # of reporting every staged file as unclaimed.
230
+ if ! run_guardex_cli locks claim --branch "$branch" \
231
+ "${_staged_files[@]}" >/dev/null 2>&1; then
232
+ for staged_file in "${_staged_files[@]}"; do
233
+ run_guardex_cli locks claim --branch "$branch" "$staged_file" >/dev/null 2>&1 || true
234
+ done
235
+ fi
236
+ fi
221
237
 
222
238
  # Auto-approve deletions for the same branch (gated separately so
223
239
  # operators can disable this single behavior without disabling the
@@ -6,11 +6,18 @@ the **default** budget posture for projects that use `gx branch start`
6
6
  to drive agent iterations.
7
7
 
8
8
  Agent flows land a high volume of PRs per month. Without these trims,
9
- every PR + every post-merge push fans out across CI, CodeQL, Scorecard,
10
- and Code Review — which dominates the GitHub Actions bill for any
9
+ every PR + every post-merge push fans out across CI, CodeQL, and
10
+ Scorecard — which dominates the GitHub Actions bill for any
11
11
  multi-agent repo. The trims below cut that cost without giving up
12
12
  correctness coverage.
13
13
 
14
+ No AI-code-review workflow is scaffolded. `gx` drives review from the
15
+ CLI side (`gx review`, `gx branch finish --gate-review`), so a
16
+ per-PR review workflow was a second, unconfigured copy of the same
17
+ gate: without an `OPENAI_API_KEY` repo secret it reported a green
18
+ check that had reviewed nothing. Wire review into the finish gate
19
+ instead, where a missing provider fails closed.
20
+
14
21
  ## What's trimmed and why
15
22
 
16
23
  1. **`concurrency: cancel-in-progress: true`** scoped per workflow + ref
@@ -22,18 +29,12 @@ correctness coverage.
22
29
  `pull_request.types: [..., ready_for_review]` in the trigger list so
23
30
  CI fires the moment the PR is promoted out of draft.
24
31
 
25
- 3. **`if: !startsWith(head.ref, 'agent/')`** on the Code Review job
26
- (`cr.yml`) — skip AI review on automated agent-lane PRs. AI review
27
- on hundreds of agent PRs per month burns both Actions minutes and
28
- OpenAI tokens without adding signal; human-authored PRs (any non-
29
- `agent/*` head branch) still get reviewed.
30
-
31
- 4. **No `push: main` trigger** in `ci.yml` — branch protection on
32
+ 3. **No `push: main` trigger** in `ci.yml` — branch protection on
32
33
  `main` forces all changes through a PR, so PR-time CI is sufficient
33
34
  and post-merge CI on `main` was pure duplication. Use
34
35
  `workflow_dispatch` for ad-hoc full runs.
35
36
 
36
- 5. **`paths-ignore`** for docs / openspec / template-only changes — skip
37
+ 4. **`paths-ignore`** for docs / openspec / template-only changes — skip
37
38
  CI on changes that don't affect runtime behavior.
38
39
 
39
40
  ## Customizing
@@ -50,31 +51,37 @@ If your CI is fast (≤ 2 min) and you want continuous validation as
50
51
  agents iterate, drop the `if: pull_request.draft == false` job guard.
51
52
  The concurrency cancel alone still prevents minute pile-up.
52
53
 
53
- ## When to re-enable AI code review on agent PRs
54
+ ## Where AI code review lives
55
+
56
+ Not in a workflow. Run it from the CLI, where a missing or broken
57
+ provider blocks the merge instead of reporting a green check:
58
+
59
+ - `gx review --only-pr <n> --once` — review an open PR on demand.
60
+ - `gx branch finish --gate-review` — fail-closed gate; refuses to
61
+ merge unless the review comes back clean.
54
62
 
55
- If your team relies on AI review as a true gating signal (not just
56
- advisory), remove the `!startsWith(head.ref, 'agent/')` guard in
57
- `cr.yml`. Expect the OpenAI bill to scale linearly with merge volume.
63
+ A `cr.yml`-style workflow was scaffolded here until it proved to be
64
+ the wrong shape: repos without an `OPENAI_API_KEY` secret got a
65
+ `review` check that passed in six seconds having read nothing, which
66
+ reads as "reviewed" on the PR page. One gate, one place.
58
67
 
59
68
  ## Per-PR label opt-in
60
69
 
61
- Both `cr.yml` and `ci-full.yml` honor PR labels so the occasional
62
- agent PR that actually needs the heavier check can opt in without
63
- flipping a global toggle:
70
+ `ci-full.yml` honors a PR label so the occasional agent PR that
71
+ actually needs the heavier check can opt in without flipping a global
72
+ toggle:
64
73
 
65
74
  | Label | Effect |
66
75
  | --- | --- |
67
- | `needs-review` | Run AI code review on this PR even though it's `agent/*`. Useful for security-sensitive changes or public-API redesigns. |
68
76
  | `needs-ci-full` | Run the full cross-runtime matrix from `ci-full.yml` on this PR instead of waiting for the weekly schedule. Useful before a release branch lands. |
69
77
 
70
- To enable: open the PR, then `gh pr edit <num> --add-label needs-review`
78
+ To enable: open the PR, then `gh pr edit <num> --add-label needs-ci-full`
71
79
  (or click the labels picker in the GitHub UI). The label-trigger fires
72
80
  the workflow immediately; you don't need to re-push.
73
81
 
74
- Add label definitions to your repo with `gh label create needs-review
75
- --description "Run AI code review on this PR"` and similar for
76
- `needs-ci-full`, or define them in `.github/labels.yml` if you use a
77
- label-sync workflow.
82
+ Add the label definition to your repo with `gh label create
83
+ needs-ci-full --description "Run the full CI matrix on this PR"`, or
84
+ define it in `.github/labels.yml` if you use a label-sync workflow.
78
85
 
79
86
  ## What about CodeQL / Scorecard?
80
87