@plainconceptsplatform/workflows 0.4.34 → 0.6.1

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 (61) hide show
  1. package/README.md +88 -88
  2. package/dist/action-validation.test.js +5 -2
  3. package/dist/catalog-installation.js +50 -7
  4. package/dist/catalog-installation.test.js +59 -22
  5. package/dist/catalog-listing.test.js +4 -4
  6. package/dist/index.js +48 -48
  7. package/dist/index.test.js +9 -9
  8. package/dist/repository-inspection.test.js +2 -2
  9. package/dist/route-processing.js +24 -25
  10. package/dist/route-processing.test.js +166 -233
  11. package/dist/stack-defaults.js +14 -14
  12. package/dist/stack-defaults.test.js +79 -79
  13. package/dist/tui.test.js +10 -7
  14. package/dist/workflow-catalog.d.ts +1 -1
  15. package/dist/workflow-catalog.js +1 -5
  16. package/loops/actions/add-issue-labels/action.yml +2 -2
  17. package/loops/actions/agent-output.cjs +17 -17
  18. package/loops/actions/apply-agent-bundle/apply-bundle.sh +14 -1
  19. package/loops/actions/audit-close/action.yml +24 -0
  20. package/loops/actions/classify-route/action.yml +8 -3
  21. package/loops/actions/classify-route/classify-route.sh +58 -38
  22. package/loops/actions/cleanup-artifacts/action.yml +38 -12
  23. package/loops/actions/identify-gate-subject/action.yml +3 -1
  24. package/loops/actions/remove-issue-labels/action.yml +4 -2
  25. package/loops/actions/update-changelog/action.yml +113 -0
  26. package/loops/actions/validate-merge-gate-output/action.yml +40 -40
  27. package/loops/actions/validate-refine-output/validate-refine-output.sh +34 -5
  28. package/loops/actions/validate-review-output/action.yml +35 -35
  29. package/loops/actions/validate-triage-output/action.yml +36 -36
  30. package/loops/actions/verify-refine-output/verify-refine-output.sh +20 -0
  31. package/loops/actions/verify-route-matrix/verify-route-matrix.sh +375 -36
  32. package/loops/scripts/compile-agent-workflows.mjs +290 -6
  33. package/loops/scripts/merge-changelog.mjs +76 -0
  34. package/loops/templates/agentics/actionlint.yaml +13 -0
  35. package/loops/templates/agentics/agentics-checks.yml +125 -8
  36. package/loops/templates/agentics/agentics-maintenance.yml +121 -121
  37. package/loops/templates/ci/app-ci-dotnet-next.yml +330 -171
  38. package/loops/templates/ci/app-ci-node-monorepo.yml +260 -178
  39. package/loops/templates/issues/bug_report.yml +109 -109
  40. package/loops/templates/issues/feature_request.yml +75 -75
  41. package/loops/templates/opencode/opencode.ci.json +49 -47
  42. package/loops/templates/opencode/opencode.ci.json.md +49 -41
  43. package/loops/templates/release/github-release.yml +30 -30
  44. package/loops/workflows/agent-apply-review.md +469 -443
  45. package/loops/workflows/agent-audit.md +213 -197
  46. package/loops/workflows/agent-implement.md +640 -414
  47. package/loops/workflows/agent-merge-gate.md +844 -584
  48. package/loops/workflows/agent-refine.md +633 -418
  49. package/loops/workflows/agent-release.md +258 -0
  50. package/loops/workflows/agent-triage.md +447 -439
  51. package/loops/workflows/authorize-bot-work.yml +85 -82
  52. package/loops/workflows/shared/opencode-ci.md +206 -197
  53. package/loops/workflows/shared/platform-defaults.md +19 -16
  54. package/loops/workflows/work-router.yml +1038 -632
  55. package/package.json +7 -8
  56. package/dist/repository-state.d.ts +0 -18
  57. package/dist/repository-state.js +0 -77
  58. package/dist/repository-state.test.d.ts +0 -1
  59. package/dist/repository-state.test.js +0 -96
  60. package/loops/workflows/agent-direct.md +0 -375
  61. package/loops/workflows/agent-propose.md +0 -342
@@ -1,584 +1,844 @@
1
- ---
2
- # Managed by @plainconceptsplatform/workflows. Source: loops/workflows/agent-merge-gate.md. Update with `workflows update --force`; consumer edits may be overwritten.
3
- env:
4
- VERIFY_COMMANDS: "dotnet restore apps/api/Numa.slnx && dotnet build apps/api/Numa.slnx -c Release --no-restore && dotnet test apps/api/tests/Numa.UnitTests/Numa.UnitTests.csproj -c Release --no-build && dotnet test apps/api/tests/Numa.ParityTests/Numa.ParityTests.csproj -c Release --no-build"
5
- REPO_RULES: "Make a risk-based merge decision for the selected bot pull request. Merge only when CI is green and no risk indicators are present. Risk indicators for Numa: changes to QuoteCalculator or calculation waterfall, audit appender or hash chain, JWT issuance or permission checks, EF migrations or entity configurations, decimal precision or money handling, quote lifecycle transitions. Any of these require human review. Do not merge protected file changes."
6
- WORKING_LABEL: bot-working
7
- IMPLEMENT_LABEL: implement
8
- REVIEW_LABEL: review
9
- GATE_MARKER: "<!-- agent-merge-gate -->"
10
- INCOMPLETE_COMMENT: "Automated CI failure remediation ended without an outcome. The issue remains for a retry."
11
- ISSUE_CONTEXT_PATH: /tmp/gh-aw/agent/issue-context.json
12
- GH_AW_ALLOWED_BOTS: "platform-devbox[bot],github-actions[bot]"
13
- GIT_AUTHOR_NAME: "github-actions[bot]"
14
- GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
15
- GIT_COMMITTER_NAME: "github-actions[bot]"
16
- GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
17
- description: |
18
- Decides what happens to a bot-authored pull request once CI has reported: merge when the
19
- risk assessment is clean, hand to a human when it is not, fix CI when it failed. Called by
20
- the Work Router; does not trigger on public events.
21
-
22
- The router supplies the CI conclusion and run ID as facts, so there is no polling and no
23
- timeout branch. The conclusion is read from the inputs instead of filtered at the trigger.
24
-
25
- name: "Agent: Merge Gate"
26
-
27
- # Router-only worker. The Work Router owns triggers, classification, and rung 1-2 checks.
28
- # This workflow receives the classified inputs and runs rung 3+.
29
- imports:
30
- - github/gh-aw/.github/workflows/shared/opencode.md@v0.86.2
31
- - shared/platform-defaults.md
32
- - shared/opencode-ci.md
33
-
34
- on:
35
- workflow_call:
36
- inputs:
37
- pr-number:
38
- description: Pull request number to gate.
39
- required: true
40
- type: string
41
- linked-issue:
42
- description: Issue number the pull request closes. May be empty.
43
- required: false
44
- type: string
45
- ci-conclusion:
46
- description: CI conclusion (success, failure, action_required, cancelled, etc.).
47
- required: true
48
- type: string
49
- ci-run-id:
50
- description: CI workflow run ID for fetching failing logs.
51
- required: false
52
- type: string
53
-
54
- # Rung 4. Router has classified the event; identify-gate-subject validates PR ownership,
55
- # resolves the closing issue, and confirms the CI verdict.
56
- # A custom job, not `on.steps`, because the prompt and the precompute step need these
57
- # values and `on.steps` outputs do not reach the agent job.
58
- jobs:
59
- subject:
60
- runs-on: RunnerLandingZone
61
- permissions:
62
- contents: read
63
- issues: read
64
- pull-requests: read
65
- actions: read
66
- outputs:
67
- found: ${{ steps.subject.outputs.found }}
68
- pr: ${{ steps.subject.outputs.pr }}
69
- issue: ${{ steps.subject.outputs.issue }}
70
- conclusion: ${{ steps.subject.outputs.conclusion }}
71
- review_blocked: ${{ steps.review.outputs.review_blocked }}
72
- steps:
73
- - name: Checkout workflow actions
74
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
75
- with:
76
- persist-credentials: false
77
- - name: Identify the pull request, its issue, and the CI verdict
78
- id: subject
79
- uses: ./.github/actions/identify-gate-subject
80
- with:
81
- token: ${{ github.token }}
82
- pr-number: ${{ inputs.pr-number }}
83
- ci-conclusion: ${{ inputs.ci-conclusion }}
84
- linked-issue: ${{ inputs.linked-issue }}
85
- require-label: ${{ env.IMPLEMENT_LABEL }}
86
- - name: Block a pull request with requested changes
87
- id: review
88
- env:
89
- GH_TOKEN: ${{ github.token }}
90
- REPO: ${{ github.repository }}
91
- PR: ${{ steps.subject.outputs.pr }}
92
- run: |
93
- set -euo pipefail
94
- decision=$(gh pr view "$PR" --repo "$REPO" --json reviewDecision --jq '.reviewDecision')
95
- echo "review_blocked=$([ "$decision" = 'CHANGES_REQUESTED' ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
96
-
97
- protected_changes:
98
- needs: subject
99
- if: needs.subject.outputs.found == 'true'
100
- runs-on: RunnerLandingZone
101
- permissions:
102
- pull-requests: read
103
- outputs:
104
- requires_review: ${{ steps.files.outputs.requires_review }}
105
- files: ${{ steps.files.outputs.files }}
106
- steps:
107
- - name: Require review for protected pull request files
108
- id: files
109
- env:
110
- GH_TOKEN: ${{ github.token }}
111
- REPO: ${{ github.repository }}
112
- PR: ${{ needs.subject.outputs.pr }}
113
- run: |
114
- set -euo pipefail
115
- files=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[].filename')
116
- protected=$(printf '%s\n' "$files" | grep -E '^(\.|AGENTS\.md$|ARCHITECTURE\.md$|opencode\.jsonc$|package\.json$|pnpm-lock\.yaml$|Directory\.Packages\.props$|global\.json$)' || true)
117
-
118
- if [ -n "$protected" ]; then
119
- echo "requires_review=true" >> "$GITHUB_OUTPUT"
120
- {
121
- echo 'files<<EOF'
122
- printf '%s\n' "$protected"
123
- echo EOF
124
- } >> "$GITHUB_OUTPUT"
125
- else
126
- echo "requires_review=false" >> "$GITHUB_OUTPUT"
127
- echo "files=" >> "$GITHUB_OUTPUT"
128
- fi
129
-
130
- review_required:
131
- needs: [subject, protected_changes]
132
- # gh-aw makes the agent depend on custom jobs. Keep this job successful when
133
- # there are no protected files instead of skipping it and blocking remediation.
134
- if: always() && needs.subject.outputs.found == 'true'
135
- runs-on: RunnerLandingZone
136
- permissions:
137
- contents: read
138
- issues: write
139
- steps:
140
- - name: Checkout workflow actions
141
- if: needs.protected_changes.outputs.requires_review == 'true'
142
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
143
- with:
144
- persist-credentials: false
145
- - name: Create bot token
146
- if: needs.protected_changes.outputs.requires_review == 'true'
147
- id: app-token
148
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
149
- with:
150
- client-id: ${{ secrets.BOT_APP_ID }}
151
- private-key: ${{ secrets.BOT_PRIVATE_KEY }}
152
- - name: Release the issue
153
- if: needs.protected_changes.outputs.requires_review == 'true'
154
- uses: ./.github/actions/remove-issue-labels
155
- with:
156
- token: ${{ steps.app-token.outputs.token }}
157
- issue-number: ${{ needs.subject.outputs.issue }}
158
- labels: ${{ env.WORKING_LABEL }}
159
- - name: Flag human review
160
- if: needs.protected_changes.outputs.requires_review == 'true'
161
- uses: ./.github/actions/add-issue-labels
162
- with:
163
- token: ${{ steps.app-token.outputs.token }}
164
- issue-number: ${{ needs.subject.outputs.issue }}
165
- labels: ${{ env.REVIEW_LABEL }}
166
- - name: Explain the merge hold
167
- if: needs.protected_changes.outputs.requires_review == 'true'
168
- uses: ./.github/actions/create-issue-comment
169
- with:
170
- token: ${{ steps.app-token.outputs.token }}
171
- issue-number: ${{ needs.subject.outputs.issue }}
172
- body: |
173
- ${{ env.GATE_MARKER }}
174
- PR #${{ needs.subject.outputs.pr }} changes protected files and cannot be auto-merged.
175
- The `review` label is set: a human must merge this PR manually.
176
-
177
- Protected files:
178
- ${{ needs.protected_changes.outputs.files }}
179
-
180
- reserve:
181
- needs: subject
182
- if: needs.subject.outputs.found == 'true'
183
- runs-on: RunnerLandingZone
184
- permissions:
185
- contents: read
186
- issues: write
187
- pull-requests: read
188
- outputs:
189
- has_conflicts: ${{ steps.conflicts.outputs.has_conflicts || 'false' }}
190
- steps:
191
- - name: Checkout workflow actions
192
- if: needs.subject.outputs.conclusion == 'failure'
193
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
194
- with:
195
- persist-credentials: false
196
- - name: Create bot token
197
- if: needs.subject.outputs.conclusion == 'failure'
198
- id: app-token
199
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
200
- with:
201
- client-id: ${{ secrets.BOT_APP_ID }}
202
- private-key: ${{ secrets.BOT_PRIVATE_KEY }}
203
- - name: Check for merge conflicts
204
- if: needs.subject.outputs.conclusion == 'failure'
205
- id: conflicts
206
- env:
207
- GH_TOKEN: ${{ steps.app-token.outputs.token }}
208
- REPO: ${{ github.repository }}
209
- PR: ${{ needs.subject.outputs.pr }}
210
- run: |
211
- set -euo pipefail
212
- mergeable=$(gh pr view "$PR" --repo "$REPO" --json mergeable --jq '.mergeable')
213
- if [ "$mergeable" = "CONFLICTING" ]; then
214
- echo "has_conflicts=true" >> "$GITHUB_OUTPUT"
215
- else
216
- echo "has_conflicts=false" >> "$GITHUB_OUTPUT"
217
- fi
218
- - name: Comment on issue - problems found, solving them
219
- if: needs.subject.outputs.conclusion == 'failure'
220
- uses: ./.github/actions/create-issue-comment
221
- with:
222
- token: ${{ steps.app-token.outputs.token }}
223
- issue-number: ${{ needs.subject.outputs.issue }}
224
- body: |
225
- ${{ env.GATE_MARKER }}
226
- Problems found in PR #${{ needs.subject.outputs.pr }}. ${{ steps.conflicts.outputs.has_conflicts == 'true' && 'Merge conflicts detected.' || 'CI failed.' }}
227
- Bot is working on fixing it.
228
- validate_output:
229
- needs: [activation, agent, safe_outputs]
230
- if: >
231
- always() &&
232
- needs.agent.result == 'success' &&
233
- needs.safe_outputs.result == 'success'
234
- runs-on: RunnerLandingZone
235
- permissions:
236
- contents: read
237
- outputs:
238
- valid: ${{ steps.validate.outputs.valid }}
239
- outcome: ${{ steps.validate.outputs.outcome }}
240
- steps:
241
- - name: Checkout workflow actions
242
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
243
- with:
244
- persist-credentials: false
245
- - name: Download agent output
246
- id: output
247
- uses: ./.github/actions/download-agent-output
248
- with:
249
- artifact-name: ${{ needs.activation.outputs.artifact_prefix }}agent
250
- - name: Validate merge-gate outcome
251
- id: validate
252
- uses: ./.github/actions/validate-merge-gate-output
253
- with:
254
- output-file: ${{ steps.output.outputs.output-file }}
255
- issue-number: ${{ needs.subject.outputs.issue }}
256
- ci-conclusion: ${{ needs.subject.outputs.conclusion }}
257
- conclude:
258
- needs: [activation, subject, protected_changes, agent, safe_outputs, validate_output]
259
- if: >
260
- needs.agent.result == 'success' &&
261
- needs.safe_outputs.result == 'success' &&
262
- needs.validate_output.outputs.valid == 'true' &&
263
- needs.protected_changes.outputs.requires_review != 'true'
264
- runs-on: RunnerLandingZone
265
- permissions:
266
- contents: write
267
- issues: write
268
- pull-requests: write
269
- steps:
270
- - name: Create bot token
271
- id: app-token
272
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
273
- with:
274
- client-id: ${{ secrets.BOT_APP_ID }}
275
- private-key: ${{ secrets.BOT_PRIVATE_KEY }}
276
- - name: Checkout repository
277
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
278
- with:
279
- token: ${{ steps.app-token.outputs.token }}
280
- fetch-depth: 0
281
- - name: Verify pull request closes the source issue
282
- continue-on-error: true
283
- uses: ./.github/actions/link-pr-to-issue
284
- with:
285
- token: ${{ steps.app-token.outputs.token }}
286
- pr-number: ${{ needs.subject.outputs.pr }}
287
- issue-number: ${{ needs.subject.outputs.issue }}
288
- - name: Apply agent output
289
- uses: ./.github/actions/apply-agent-output
290
- with:
291
- artifact-name: ${{ needs.activation.outputs.artifact_prefix }}agent
292
- token: ${{ steps.app-token.outputs.token }}
293
- push-to-branch: 'true'
294
- apply-labels: 'false'
295
- - name: Merge approved pull request
296
- if: needs.validate_output.outputs.outcome == 'merge'
297
- env:
298
- GH_TOKEN: ${{ steps.app-token.outputs.token }}
299
- REPO: ${{ github.repository }}
300
- PR: ${{ needs.subject.outputs.pr }}
301
- run: |
302
- set -euo pipefail
303
- head_sha=$(gh pr view "$PR" --repo "$REPO" --json headRefOid --jq '.headRefOid')
304
- gh pr merge "$PR" --repo "$REPO" --squash --match-head-commit "$head_sha"
305
- - name: Release remediated issue
306
- if: needs.validate_output.outputs.outcome == 'remediated'
307
- uses: ./.github/actions/remove-issue-labels
308
- with:
309
- token: ${{ steps.app-token.outputs.token }}
310
- issue-number: ${{ needs.subject.outputs.issue }}
311
- labels: ${{ env.WORKING_LABEL }}
312
- - name: Flag review outcome
313
- if: needs.validate_output.outputs.outcome == 'review'
314
- uses: ./.github/actions/add-issue-labels
315
- with:
316
- token: ${{ steps.app-token.outputs.token }}
317
- issue-number: ${{ needs.subject.outputs.issue }}
318
- labels: ${{ env.REVIEW_LABEL }}
319
- - name: Release review outcome
320
- if: needs.validate_output.outputs.outcome == 'review'
321
- uses: ./.github/actions/remove-issue-labels
322
- with:
323
- token: ${{ steps.app-token.outputs.token }}
324
- issue-number: ${{ needs.subject.outputs.issue }}
325
- labels: ${{ env.WORKING_LABEL }}
326
- - name: Clear merged issue labels
327
- if: needs.validate_output.outputs.outcome == 'merge'
328
- uses: ./.github/actions/remove-issue-labels
329
- with:
330
- token: ${{ steps.app-token.outputs.token }}
331
- issue-number: ${{ needs.subject.outputs.issue }}
332
- labels: ${{ env.IMPLEMENT_LABEL }},${{ env.WORKING_LABEL }},${{ env.REVIEW_LABEL }}
333
- incomplete:
334
- needs: [subject, protected_changes, agent, safe_outputs, validate_output]
335
- if: >
336
- always() &&
337
- needs.subject.outputs.found == 'true' &&
338
- needs.protected_changes.outputs.requires_review != 'true' &&
339
- (
340
- needs.agent.result != 'success' ||
341
- needs.safe_outputs.result != 'success' ||
342
- needs.validate_output.outputs.valid != 'true'
343
- )
344
- runs-on: RunnerLandingZone
345
- permissions:
346
- contents: read
347
- issues: write
348
- steps:
349
- - name: Checkout workflow actions
350
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
351
- with:
352
- persist-credentials: false
353
- - name: Create bot token
354
- id: app-token
355
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
356
- with:
357
- client-id: ${{ secrets.BOT_APP_ID }}
358
- private-key: ${{ secrets.BOT_PRIVATE_KEY }}
359
- - name: Release the issue
360
- uses: ./.github/actions/remove-issue-labels
361
- with:
362
- token: ${{ steps.app-token.outputs.token }}
363
- issue-number: ${{ needs.subject.outputs.issue }}
364
- labels: ${{ env.WORKING_LABEL }},${{ env.IMPLEMENT_LABEL }}
365
- - name: Flag for human review
366
- uses: ./.github/actions/add-issue-labels
367
- with:
368
- token: ${{ steps.app-token.outputs.token }}
369
- issue-number: ${{ needs.subject.outputs.issue }}
370
- labels: ${{ env.REVIEW_LABEL }}
371
- - name: Report missing remediation outcome
372
- uses: ./.github/actions/create-issue-comment
373
- with:
374
- token: ${{ steps.app-token.outputs.token }}
375
- issue-number: ${{ needs.subject.outputs.issue }}
376
- body: |
377
- ${{ env.GATE_MARKER }}
378
- Bot could not resolve PR #${{ needs.subject.outputs.pr }} automatically. The `review` label is set: a human must take over.
379
- ${{ env.INCOMPLETE_COMMENT }}
380
- [View this workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
381
-
382
- agent:
383
- # The top-level guard reads both outputs. GitHub Actions does not make a
384
- # dependency's dependencies available through `needs` transitively.
385
- needs: [subject, protected_changes]
386
- if: always() && needs.protected_changes.outputs.requires_review != 'true' && needs.subject.outputs.review_blocked != 'true'
387
-
388
- if: always() && needs.subject.outputs.found == 'true' && needs.protected_changes.outputs.requires_review != 'true' && needs.subject.outputs.review_blocked != 'true'
389
-
390
- runs-on: RunnerLandingZone
391
- runs-on-slim: RunnerLandingZone
392
-
393
- secrets:
394
- OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
395
-
396
- engine:
397
- id: opencode
398
- version: "1.2.14"
399
- env:
400
- OPENAI_BASE_URL: https://forge.plainconcepts.com/v1
401
-
402
- model: openai/glm-5-2
403
-
404
- max-turns: 300
405
- max-turn-cache-misses: 3000
406
- max-ai-credits: 5000
407
-
408
- permissions: read-all
409
-
410
- # push-to-pull-request-branch with target "*" cannot reach a branch the shallow clone
411
- # does not have.
412
- checkout:
413
- fetch: ["*"]
414
- fetch-depth: 0
415
-
416
- # Rung 3. The diff is what the risk assessment reads, and the failing logs are what a fix
417
- # starts from. Both are known from the inputs, so neither costs the agent a turn.
418
- steps:
419
- - name: Load the issue context
420
- uses: ./.github/actions/load-issue-context
421
- with:
422
- token: ${{ github.token }}
423
- issue-number: ${{ needs.subject.outputs.issue }}
424
- output-path: ${{ env.ISSUE_CONTEXT_PATH }}
425
- - name: Fetch the diff and any failing job logs
426
- env:
427
- GH_TOKEN: ${{ github.token }}
428
- REPO: ${{ github.repository }}
429
- PR: ${{ needs.subject.outputs.pr }}
430
- RUN_ID: ${{ inputs.ci-run-id }}
431
- CONCLUSION: ${{ needs.subject.outputs.conclusion }}
432
- run: |
433
- set -euo pipefail
434
- mkdir -p /tmp/gh-aw/agent
435
- gh pr diff "$PR" --repo "$REPO" > /tmp/gh-aw/agent/diff.patch
436
- gh pr view "$PR" --repo "$REPO" --json title,body,files,additions,deletions \
437
- > /tmp/gh-aw/agent/pr.json
438
- if [ "$CONCLUSION" = "failure" ]; then
439
- gh run view "$RUN_ID" --repo "$REPO" --log-failed \
440
- > /tmp/gh-aw/agent/failed-logs.txt 2>/dev/null || \
441
- echo "logs unavailable" > /tmp/gh-aw/agent/failed-logs.txt
442
- gh run view "$RUN_ID" --repo "$REPO" --json jobs \
443
- --jq '[.jobs[] | select(.conclusion == "failure") | {name, conclusion}]' \
444
- > /tmp/gh-aw/agent/failed-jobs.json
445
- fi
446
-
447
- safe-outputs:
448
- staged: true
449
- threat-detection: false
450
- push-to-pull-request-branch:
451
- add-comment:
452
- target: "*"
453
-
454
- timeout-minutes: 60
455
- ---
456
-
457
- 1. You are gating pull request **#${{ needs.subject.outputs.pr }}**, which closes issue
458
- **#${{ needs.subject.outputs.issue }}**. CI concluded
459
- **${{ needs.subject.outputs.conclusion }}**.
460
-
461
- It has already been confirmed that this is an open pull request we authored, that it closes
462
- an issue, and that the issue carries `implement`. Do not re-check any of that, and do not
463
- poll for checks: the conclusion above is the answer.
464
-
465
- 2. Read `${{ env.ISSUE_CONTEXT_PATH }}`. It contains the issue body and its discussion. When
466
- running `/repo-verify`, the acceptance criteria there define what the implementation must
467
- satisfy.
468
-
469
- 3. Branch on the conclusion.
470
-
471
- First check the issue context for `<!-- complexity: trivial -->`.
472
-
473
- **If the trivial marker is present AND CI conclusion is success:**
474
- Skip the risk assessment (step 4). Proceed directly to step 5 (merge).
475
- The change is presentation-only and CI is green — no need for deep risk review.
476
- Trivial changes do not touch business logic, data models, auth, or infrastructure by definition.
477
-
478
- **If the trivial marker is absent OR CI is not success:**
479
- Follow the normal branching below.
480
-
481
- - **success** → step 4.
482
- - **action_required** → CI did not run because the workflow needs approval.
483
- Proceed to review: explain that a maintainer must approve the pending run.
484
- Do not attempt to merge or fix.
485
- - **failure** → step 7.
486
- - **cancelled, timed_out, or anything else** → proceed to review. A cancelled or unknown
487
- run is not evidence of anything.
488
-
489
- Follow repository documentation and established conventions when assessing or remediating
490
- the pull request. Protect secrets, do not bypass checks, and keep remediation focused.
491
- Adhere to ${{ env.REPO_RULES }}.
492
-
493
- 4. Assess the risk of merging, as a reviewer would. Read `/tmp/gh-aw/agent/diff.patch` in full
494
- and `/tmp/gh-aw/agent/pr.json` for the shape of the change. Flag it as risky when any of
495
- these hold, and say which:
496
-
497
- - It touches authentication, authorization, secrets, credentials, or security boundaries.
498
- - It changes a repository-defined integration or cross-platform boundary.
499
- - It changes a public API or a published package's contract.
500
- - It deletes or weakens a test, or lowers a threshold.
501
- - It changes CI, CD or a workflow file.
502
- - It changes a protected file. This is normally handled before you run, but never merge one
503
- if it reaches this gate.
504
- - The diff is materially larger than the issue implied.
505
- - You are simply not confident. Low confidence is itself a flag.
506
-
507
- 5. **Clean assessment** → select the `merge` verdict.
508
-
509
- 6. **Flagged** → select the `review` verdict. Do not merge. Explain exactly which criterion
510
- tripped and what a reviewer should look at. Leave `implement` in place: the work is not
511
- finished until a human merges it.
512
-
513
- 7. **CI failed** → read `/tmp/gh-aw/agent/failed-jobs.json` and
514
- `/tmp/gh-aw/agent/failed-logs.txt`, which are already on disk. Load only skills required to
515
- fix the actual cause. Run these verification commands before a push. Do not weaken a test,
516
- disable a check, or push an unverified guess.
517
-
518
- **If `has_conflicts` is `true` (current value: `${{ needs.reserve.outputs.has_conflicts }}`):** You are already on the PR branch. Resolve the conflict;
519
- it is not a reason to hand the PR to a human. Merge `origin/${{ github.event.repository.default_branch }}`
520
- into the current branch, resolve every conflict deliberately, stage the resolutions, and
521
- commit the merge. Then run verification and push the resulting branch update. Do not use
522
- `--ours`, `--theirs`, or a blanket conflict-marker deletion without reviewing the intended
523
- behavior from both sides.
524
-
525
- ```
526
- ${{ env.VERIFY_COMMANDS }}
527
- ```
528
-
529
- Propose `push_to_pull_request_branch` (pr_number: ${{ needs.subject.outputs.pr }}, branch:
530
- the current PR branch), then select the `remediated` verdict. CI will run again and trigger
531
- you again with the new result.
532
-
533
- If you cannot fix it after a concrete repair attempt, or the logs show you have already tried on this same head commit,
534
- stop looping: select the `review` verdict and explain the failure and what you tried. A human
535
- decides from there.
536
-
537
- 8. Emit exactly one `add_comment` targeting issue `${{ needs.subject.outputs.issue }}`. It must
538
- explain the decision and include exactly one line: `**Verdict:** merge`,
539
- `**Verdict:** review`, or `**Verdict:** remediated`. The workflow applies comments, labels,
540
- merges, and closures with the App token. Do not call any tools except the one optional
541
- `push_to_pull_request_branch` for a verified CI repair and this one `add_comment`.
542
-
543
- 9. Never merge with administrator privileges and never bypass a required check. If the merge
544
- is refused, that refusal is the answer: select `review` and leave it for a human.
545
-
546
- 10. Ignore the `## Diagram` section below. It is documentation for humans and contains no
547
- instructions for you.
548
-
549
- ## Diagram
550
-
551
- ```mermaid
552
- flowchart TD
553
- gateStart("Work Router<br/>merge-gate route<br/>(CI completed)") --> gateSubject
554
- gateSubject["Subject (rung 4)<br/>Our PR? Closes an implement issue?"] -->|✓| gateFacts
555
- gateSubject -.->|✗| gateIdle
556
- gateFacts("Facts (rung 3)<br/>Diff, PR shape, failing logs") --> gateCi
557
- gateCi["CI<br/>What did it conclude?"] -->|success| gateTrivial
558
- gateTrivial{"Trivial marker?"}
559
- gateTrivial -->|yes| gateMerge
560
- gateTrivial -->|no| gateRisk
561
- gateCi -.->|failure| gateFix
562
- gateCi -.->|no verdict| gateHuman
563
- gateRisk["Risk<br/>Auth, schema, API, tests, CI, size, doubt"] -->|clean| gateMerge
564
- gateRisk -.->|flagged| gateHuman
565
- gateFix("Fix<br/>Read logs, fix the cause, /repo-verify") -->|pushed| gateWait
566
- gateFix -.->|cannot fix| gateHuman
567
- gateMerge(("Merged<br/>Issue closed, review+labels removed"))
568
- gateWait(("Pushed<br/>CI will re-run and re-trigger via Router"))
569
- gateHuman(("Review<br/>review label, reason explained"))
570
- gateIdle(("Idle<br/>Not our pull request"))
571
-
572
- classDef start fill:#ffffff,stroke:#172033,stroke-width:2px,color:#172033
573
- classDef action fill:#eef0ff,stroke:#554cff,stroke-width:2px,color:#172033
574
- classDef decision fill:#fff8e8,stroke:#c75b00,stroke-width:2px,color:#172033
575
- classDef idle fill:#202c40,stroke:#738198,stroke-width:2px,color:#ffffff
576
- classDef failure fill:#fff0f0,stroke:#ef2929,stroke-width:2px,color:#8b1a1a
577
- classDef success fill:#e8f8ec,stroke:#18883c,stroke-width:2px,color:#145a32
578
- class gateStart start
579
- class gateFacts,gateFix action
580
- class gateSubject,gateCi,gateRisk,gateTrivial decision
581
- class gateIdle,gateWait idle
582
- class gateHuman failure
583
- class gateMerge success
584
- ```
1
+ ---
2
+ # Managed by @plainconceptsplatform/workflows. Source: loops/workflows/agent-merge-gate.md. Update with `workflows update --force`; consumer edits may be overwritten.
3
+ env:
4
+ VERIFY_COMMANDS: ""
5
+ REPO_RULES: "Make a risk-based merge decision for the selected bot pull request. Merge only when CI is green and no risk indicators are present. Review risk indicators defined in the repository's guardrails or project documentation. Any of these require human review. Do not merge protected file changes."
6
+ WORKING_LABEL: bot-working
7
+ IMPLEMENT_LABEL: implement
8
+ REVIEW_LABEL: review
9
+ PR_PENDING_LABEL: pr-pending
10
+ GATE_MARKER: "<!-- agent-merge-gate -->"
11
+ ATTEMPT_MARKER: "<!-- agent-merge-gate-attempt -->"
12
+ MAX_ATTEMPTS: "6"
13
+ PARK_AT_ATTEMPT: "5"
14
+ INCOMPLETE_COMMENT: "Automated CI failure remediation ended without an outcome. The issue remains for a retry."
15
+ ISSUE_CONTEXT_PATH: /tmp/gh-aw/agent/issue-context.json
16
+ GH_AW_ALLOWED_BOTS: "platform-devbox[bot],github-actions[bot]"
17
+ GIT_AUTHOR_NAME: "github-actions[bot]"
18
+ GIT_AUTHOR_EMAIL: "github-actions[bot]@users.noreply.github.com"
19
+ GIT_COMMITTER_NAME: "github-actions[bot]"
20
+ GIT_COMMITTER_EMAIL: "github-actions[bot]@users.noreply.github.com"
21
+ description: |
22
+ Decides what happens to a bot-authored pull request once CI has reported: merge when the
23
+ risk assessment is clean, hand to a human when it is not, fix CI when it failed. Called by
24
+ the Work Router; does not trigger on public events.
25
+
26
+ The router supplies the CI conclusion and run ID as facts, so there is no polling and no
27
+ timeout branch. The conclusion is read from the inputs instead of filtered at the trigger.
28
+
29
+ name: "Agent: Merge Gate"
30
+
31
+ # Router-only worker. The Work Router owns triggers, classification, and rung 1-2 checks.
32
+ # This workflow receives the classified inputs and runs rung 3+.
33
+ imports:
34
+ - github/gh-aw/.github/workflows/shared/opencode.md@v0.87.5
35
+ - shared/platform-defaults.md
36
+ - shared/opencode-ci.md
37
+
38
+ on:
39
+ workflow_call:
40
+ inputs:
41
+ pr-number:
42
+ description: Pull request number to gate.
43
+ required: true
44
+ type: string
45
+ linked-issue:
46
+ description: Issue number the pull request closes. May be empty.
47
+ required: false
48
+ type: string
49
+ ci-conclusion:
50
+ description: CI conclusion (success, failure, action_required, cancelled, etc.).
51
+ required: true
52
+ type: string
53
+ ci-run-id:
54
+ description: CI workflow run ID for fetching failing logs.
55
+ required: false
56
+ type: string
57
+ attempts_so_far:
58
+ description: Failed gate attempts already made against this CI verdict. Parked when it reaches the cap.
59
+ required: false
60
+ type: string
61
+ default: '0'
62
+ # gh-aw folds the top-level `if:` below into the generated activation job but does not carry
63
+ # the jobs that `if:` reads into activation's `needs`: only prompt-referenced custom jobs with
64
+ # no `needs:` of their own are hoisted (subject). protected_changes needs subject, so without
65
+ # this entry activation read needs.protected_changes.outputs.requires_review before
66
+ # protected_changes had started; the value was '' and the clause was always true
67
+ # (Pliny-Bot run 34042143350: activation finished 18 s before protected_changes began).
68
+ needs: [protected_changes]
69
+
70
+ # Rung 4. Router has classified the event; identify-gate-subject validates PR ownership,
71
+ # resolves the closing issue, and confirms the CI verdict.
72
+ # A custom job, not `on.steps`, because the prompt and the precompute step need these
73
+ # values and `on.steps` outputs do not reach the agent job.
74
+ jobs:
75
+ subject:
76
+ runs-on: agents-arc
77
+ permissions:
78
+ contents: read
79
+ issues: read
80
+ pull-requests: read
81
+ actions: read
82
+ outputs:
83
+ found: ${{ steps.subject.outputs.found }}
84
+ pr: ${{ steps.subject.outputs.pr }}
85
+ issue: ${{ steps.subject.outputs.issue }}
86
+ conclusion: ${{ steps.subject.outputs.conclusion }}
87
+ run-id: ${{ steps.subject.outputs.run-id }}
88
+ review_blocked: ${{ steps.review.outputs.review_blocked }}
89
+ steps:
90
+ - name: Checkout workflow actions
91
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
92
+ with:
93
+ persist-credentials: false
94
+ - name: Identify the pull request, its issue, and the CI verdict
95
+ id: subject
96
+ uses: ./.github/actions/identify-gate-subject
97
+ with:
98
+ token: ${{ github.token }}
99
+ pr-number: ${{ inputs.pr-number }}
100
+ ci-conclusion: ${{ inputs.ci-conclusion }}
101
+ linked-issue: ${{ inputs.linked-issue }}
102
+ require-label: ${{ env.IMPLEMENT_LABEL }}
103
+ - name: Block a pull request with requested changes
104
+ id: review
105
+ env:
106
+ GH_TOKEN: ${{ github.token }}
107
+ REPO: ${{ github.repository }}
108
+ PR: ${{ steps.subject.outputs.pr }}
109
+ run: |
110
+ set -euo pipefail
111
+ # A transient API failure must not kill the gate (the reconcile cron can push the
112
+ # token into secondary rate limits). Three tries, then default to not blocked; the
113
+ # agent re-reads the review state itself before any merge.
114
+ decision=""
115
+ for _ in 1 2 3; do
116
+ if decision=$(gh pr view "$PR" --repo "$REPO" --json reviewDecision --jq '.reviewDecision // ""'); then
117
+ break
118
+ fi
119
+ sleep 5
120
+ done
121
+ echo "review_blocked=$([ "$decision" = 'CHANGES_REQUESTED' ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
122
+
123
+ protected_changes:
124
+ needs: subject
125
+ if: needs.subject.outputs.found == 'true'
126
+ runs-on: agents-arc
127
+ permissions:
128
+ pull-requests: read
129
+ outputs:
130
+ requires_review: ${{ steps.files.outputs.requires_review }}
131
+ files: ${{ steps.files.outputs.files }}
132
+ steps:
133
+ - name: Require review for protected pull request files
134
+ id: files
135
+ env:
136
+ GH_TOKEN: ${{ github.token }}
137
+ REPO: ${{ github.repository }}
138
+ PR: ${{ needs.subject.outputs.pr }}
139
+ run: |
140
+ set -euo pipefail
141
+ files=$(gh api --paginate "repos/$REPO/pulls/$PR/files?per_page=100" --jq '.[].filename')
142
+ protected=$(printf '%s\n' "$files" | grep -E '^(\.|AGENTS\.md$|ARCHITECTURE\.md$|opencode\.jsonc$|package\.json$|pnpm-lock\.yaml$|Directory\.Packages\.props$|global\.json$)' || true)
143
+
144
+ if [ -n "$protected" ]; then
145
+ echo "requires_review=true" >> "$GITHUB_OUTPUT"
146
+ {
147
+ echo 'files<<EOF'
148
+ printf '%s\n' "$protected"
149
+ echo EOF
150
+ } >> "$GITHUB_OUTPUT"
151
+ else
152
+ echo "requires_review=false" >> "$GITHUB_OUTPUT"
153
+ echo "files=" >> "$GITHUB_OUTPUT"
154
+ fi
155
+
156
+ review_required:
157
+ needs: [subject, protected_changes]
158
+ # gh-aw makes the agent depend on custom jobs. Keep this job successful when
159
+ # there are no protected files instead of skipping it and blocking remediation.
160
+ if: always() && needs.subject.outputs.found == 'true'
161
+ runs-on: agents-arc
162
+ permissions:
163
+ contents: read
164
+ issues: write
165
+ steps:
166
+ - name: Checkout workflow actions
167
+ if: needs.protected_changes.outputs.requires_review == 'true' && needs.subject.outputs.conclusion != 'failure'
168
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
169
+ with:
170
+ persist-credentials: false
171
+ - name: Create bot token
172
+ if: needs.protected_changes.outputs.requires_review == 'true' && needs.subject.outputs.conclusion != 'failure'
173
+ id: app-token
174
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
175
+ with:
176
+ client-id: ${{ secrets.BOT_APP_ID }}
177
+ private-key: ${{ secrets.BOT_PRIVATE_KEY }}
178
+ # Only the reservation comes off. pr-pending says a pull request for this issue is open
179
+ # and waiting, which is still true when the gate hands it to a human, so taking it off
180
+ # here left a board where three issues with three open pull requests looked like they
181
+ # had none. The merge path is the one place the label stops being true.
182
+ - name: Release the issue
183
+ if: needs.protected_changes.outputs.requires_review == 'true' && needs.subject.outputs.conclusion != 'failure'
184
+ uses: ./.github/actions/remove-issue-labels
185
+ with:
186
+ token: ${{ steps.app-token.outputs.token }}
187
+ issue-number: ${{ needs.subject.outputs.issue }}
188
+ labels: ${{ env.WORKING_LABEL }}
189
+ - name: Flag human review
190
+ if: needs.protected_changes.outputs.requires_review == 'true' && needs.subject.outputs.conclusion != 'failure'
191
+ uses: ./.github/actions/add-issue-labels
192
+ with:
193
+ token: ${{ steps.app-token.outputs.token }}
194
+ issue-number: ${{ needs.subject.outputs.issue }}
195
+ labels: ${{ env.REVIEW_LABEL }}
196
+ - name: Explain the merge hold
197
+ if: needs.protected_changes.outputs.requires_review == 'true' && needs.subject.outputs.conclusion != 'failure'
198
+ uses: ./.github/actions/create-issue-comment
199
+ with:
200
+ token: ${{ steps.app-token.outputs.token }}
201
+ issue-number: ${{ needs.subject.outputs.issue }}
202
+ body: |
203
+ ${{ env.GATE_MARKER }}
204
+ PR #${{ needs.subject.outputs.pr }} changes protected files and cannot be auto-merged.
205
+ The `review` label is set: a human must merge this PR manually.
206
+
207
+ Protected files:
208
+ ${{ needs.protected_changes.outputs.files }}
209
+
210
+ **Verdict:** review
211
+
212
+ reserve:
213
+ needs: subject
214
+ if: needs.subject.outputs.found == 'true'
215
+ runs-on: agents-arc
216
+ permissions:
217
+ contents: read
218
+ issues: write
219
+ pull-requests: read
220
+ outputs:
221
+ has_conflicts: ${{ steps.conflicts.outputs.has_conflicts || 'false' }}
222
+ steps:
223
+ - name: Checkout workflow actions
224
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
225
+ with:
226
+ persist-credentials: false
227
+ - name: Create bot token
228
+ id: app-token
229
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
230
+ with:
231
+ client-id: ${{ secrets.BOT_APP_ID }}
232
+ private-key: ${{ secrets.BOT_PRIVATE_KEY }}
233
+ - name: Check for merge conflicts
234
+ id: conflicts
235
+ env:
236
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
237
+ REPO: ${{ github.repository }}
238
+ PR: ${{ needs.subject.outputs.pr }}
239
+ run: |
240
+ set -euo pipefail
241
+ mergeable=$(gh pr view "$PR" --repo "$REPO" --json mergeable --jq '.mergeable')
242
+ if [ "$mergeable" = "CONFLICTING" ]; then
243
+ echo "has_conflicts=true" >> "$GITHUB_OUTPUT"
244
+ else
245
+ echo "has_conflicts=false" >> "$GITHUB_OUTPUT"
246
+ fi
247
+ # First attempt only. Retries are recorded by the incomplete job's attempt comment, and
248
+ # every App comment is a router event: one issue collected sixteen of these in a day.
249
+ - name: Comment on issue - problems found, solving them
250
+ if: needs.subject.outputs.conclusion == 'failure' && (inputs.attempts_so_far || '0') == '0'
251
+ uses: ./.github/actions/create-issue-comment
252
+ with:
253
+ token: ${{ steps.app-token.outputs.token }}
254
+ issue-number: ${{ needs.subject.outputs.issue }}
255
+ body: |
256
+ Problems found in PR #${{ needs.subject.outputs.pr }}. ${{ steps.conflicts.outputs.has_conflicts == 'true' && 'Merge conflicts detected.' || 'CI failed.' }}
257
+ Bot is working on fixing it.
258
+ validate_output:
259
+ needs: [activation, subject, agent, safe_outputs]
260
+ if: >
261
+ always() &&
262
+ needs.agent.result == 'success' &&
263
+ needs.safe_outputs.result == 'success'
264
+ runs-on: agents-arc
265
+ permissions:
266
+ contents: read
267
+ outputs:
268
+ valid: ${{ steps.validate.outputs.valid }}
269
+ outcome: ${{ steps.validate.outputs.outcome }}
270
+ steps:
271
+ - name: Checkout workflow actions
272
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
273
+ with:
274
+ persist-credentials: false
275
+ - name: Download agent output
276
+ id: output
277
+ uses: ./.github/actions/download-agent-output
278
+ with:
279
+ artifact-name: ${{ needs.activation.outputs.artifact_prefix }}agent
280
+ - name: Validate merge-gate outcome
281
+ id: validate
282
+ uses: ./.github/actions/validate-merge-gate-output
283
+ with:
284
+ output-file: ${{ steps.output.outputs.output-file }}
285
+ issue-number: ${{ needs.subject.outputs.issue }}
286
+ ci-conclusion: ${{ needs.subject.outputs.conclusion }}
287
+ conclude:
288
+ needs: [activation, subject, protected_changes, agent, safe_outputs, validate_output]
289
+ if: >
290
+ needs.agent.result == 'success' &&
291
+ needs.safe_outputs.result == 'success' &&
292
+ needs.validate_output.outputs.valid == 'true' &&
293
+ (needs.protected_changes.outputs.requires_review != 'true' || needs.validate_output.outputs.outcome != 'merge')
294
+ runs-on: agents-arc
295
+ permissions:
296
+ contents: write
297
+ issues: write
298
+ pull-requests: write
299
+ steps:
300
+ - name: Create bot token
301
+ id: app-token
302
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
303
+ with:
304
+ client-id: ${{ secrets.BOT_APP_ID }}
305
+ private-key: ${{ secrets.BOT_PRIVATE_KEY }}
306
+ - name: Checkout repository
307
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
308
+ with:
309
+ token: ${{ steps.app-token.outputs.token }}
310
+ fetch-depth: 0
311
+ - name: Verify pull request closes the source issue
312
+ continue-on-error: true
313
+ uses: ./.github/actions/link-pr-to-issue
314
+ with:
315
+ token: ${{ steps.app-token.outputs.token }}
316
+ pr-number: ${{ needs.subject.outputs.pr }}
317
+ issue-number: ${{ needs.subject.outputs.issue }}
318
+ - name: Apply agent output
319
+ uses: ./.github/actions/apply-agent-output
320
+ with:
321
+ artifact-name: ${{ needs.activation.outputs.artifact_prefix }}agent
322
+ token: ${{ steps.app-token.outputs.token }}
323
+ push-to-branch: 'true'
324
+ apply-labels: 'false'
325
+ # GITHUB_TOKEN on purpose: an App-token comment on a pull request is an issue_comment
326
+ # event, and GITHUB_TOKEN raises none. The full assessment lives on the issue, where the
327
+ # lifecycle is; this is what a reviewer opening the pull request sees. Carrying the
328
+ # marker and the Verdict line makes the router's verdict detection independent of
329
+ # whether the model remembered the marker.
330
+ - name: Show the verdict on the pull request
331
+ uses: ./.github/actions/create-issue-comment
332
+ with:
333
+ token: ${{ github.token }}
334
+ issue-number: ${{ needs.subject.outputs.pr }}
335
+ body: |
336
+ ${{ env.GATE_MARKER }}
337
+ **Verdict:** ${{ needs.validate_output.outputs.outcome }} (CI concluded ${{ needs.subject.outputs.conclusion }}).
338
+ Full assessment on the linked issue: #${{ needs.subject.outputs.issue }}. [View this workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
339
+ - name: Merge approved pull request
340
+ if: needs.validate_output.outputs.outcome == 'merge'
341
+ env:
342
+ GH_TOKEN: ${{ steps.app-token.outputs.token }}
343
+ REPO: ${{ github.repository }}
344
+ PR: ${{ needs.subject.outputs.pr }}
345
+ run: |
346
+ set -euo pipefail
347
+ head_sha=$(gh pr view "$PR" --repo "$REPO" --json headRefOid --jq '.headRefOid')
348
+ gh pr merge "$PR" --repo "$REPO" --squash --match-head-commit "$head_sha"
349
+ - name: Release remediated issue
350
+ if: needs.validate_output.outputs.outcome == 'remediated'
351
+ uses: ./.github/actions/remove-issue-labels
352
+ with:
353
+ token: ${{ steps.app-token.outputs.token }}
354
+ issue-number: ${{ needs.subject.outputs.issue }}
355
+ labels: ${{ env.WORKING_LABEL }}
356
+ - name: Flag review outcome
357
+ if: needs.validate_output.outputs.outcome == 'review'
358
+ uses: ./.github/actions/add-issue-labels
359
+ with:
360
+ token: ${{ steps.app-token.outputs.token }}
361
+ issue-number: ${{ needs.subject.outputs.issue }}
362
+ labels: ${{ env.REVIEW_LABEL }}
363
+ # The reservation only. The pull request is still open and still waiting, so pr-pending
364
+ # stays until the merge path below retires it.
365
+ - name: Release review outcome
366
+ if: needs.validate_output.outputs.outcome == 'review'
367
+ uses: ./.github/actions/remove-issue-labels
368
+ with:
369
+ token: ${{ steps.app-token.outputs.token }}
370
+ issue-number: ${{ needs.subject.outputs.issue }}
371
+ labels: ${{ env.WORKING_LABEL }}
372
+ - name: Clear merged issue labels
373
+ if: needs.validate_output.outputs.outcome == 'merge'
374
+ uses: ./.github/actions/remove-issue-labels
375
+ with:
376
+ token: ${{ steps.app-token.outputs.token }}
377
+ issue-number: ${{ needs.subject.outputs.issue }}
378
+ labels: |
379
+ ${{ env.IMPLEMENT_LABEL }}
380
+ ${{ env.WORKING_LABEL }}
381
+ ${{ env.REVIEW_LABEL }}
382
+ ${{ env.PR_PENDING_LABEL }}
383
+ incomplete:
384
+ needs: [subject, protected_changes, agent, safe_outputs, validate_output]
385
+ if: >
386
+ always() &&
387
+ needs.subject.outputs.found == 'true' &&
388
+ (needs.protected_changes.outputs.requires_review != 'true' || needs.subject.outputs.conclusion == 'failure') &&
389
+ (
390
+ needs.agent.result != 'success' ||
391
+ needs.safe_outputs.result != 'success' ||
392
+ needs.validate_output.outputs.valid != 'true'
393
+ )
394
+ runs-on: agents-arc
395
+ permissions:
396
+ contents: read
397
+ issues: write
398
+ steps:
399
+ - name: Checkout workflow actions
400
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
401
+ with:
402
+ persist-credentials: false
403
+ - name: Create bot token
404
+ id: app-token
405
+ uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
406
+ with:
407
+ client-id: ${{ secrets.BOT_APP_ID }}
408
+ private-key: ${{ secrets.BOT_PRIVATE_KEY }}
409
+ # The attempt record comes first. The belt bounds its retries by counting attempt comments
410
+ # newer than the CI verdict, not by labels; releasing the labels before the record existed
411
+ # meant a failure in either step below un-reserved the issue with nothing to count, and the
412
+ # belt re-dispatched the same crash every cycle. The steps stay sequential on purpose: an
413
+ # always() release after a failed park would strip bot-working from an issue that was
414
+ # meant to be parked with review.
415
+ # attempts_so_far is a workflow_call input and arrives as '' when the caller passes an
416
+ # empty expression, declared default or not; fromJson('') is a hard failure, so the empty
417
+ # case reads as 0.
418
+ - name: Report the failed attempt
419
+ if: fromJson(inputs.attempts_so_far || '0') < fromJson(env.PARK_AT_ATTEMPT)
420
+ uses: ./.github/actions/create-issue-comment
421
+ with:
422
+ token: ${{ steps.app-token.outputs.token }}
423
+ issue-number: ${{ needs.subject.outputs.issue }}
424
+ body: |
425
+ ${{ env.ATTEMPT_MARKER }}
426
+ Attempt ${{ inputs.attempts_so_far || '0' }} of ${{ env.MAX_ATTEMPTS }} on PR #${{ needs.subject.outputs.pr }} ended without an outcome.
427
+ The issue keeps `implement`; the merge belt will retry.
428
+ [View this workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
429
+ - name: Report the exhausted attempt budget
430
+ if: fromJson(inputs.attempts_so_far || '0') >= fromJson(env.PARK_AT_ATTEMPT)
431
+ uses: ./.github/actions/create-issue-comment
432
+ with:
433
+ token: ${{ steps.app-token.outputs.token }}
434
+ issue-number: ${{ needs.subject.outputs.issue }}
435
+ body: |
436
+ ${{ env.ATTEMPT_MARKER }}
437
+ Attempt ${{ inputs.attempts_so_far || '0' }} of ${{ env.MAX_ATTEMPTS }} on PR #${{ needs.subject.outputs.pr }} ended without an outcome.
438
+ The attempt budget for this CI verdict is exhausted. The review label is set: a human must take over.
439
+ [View this workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
440
+ - name: Park the issue for a human
441
+ if: fromJson(inputs.attempts_so_far || '0') >= fromJson(env.PARK_AT_ATTEMPT)
442
+ uses: ./.github/actions/add-issue-labels
443
+ with:
444
+ token: ${{ steps.app-token.outputs.token }}
445
+ issue-number: ${{ needs.subject.outputs.issue }}
446
+ labels: ${{ env.REVIEW_LABEL }}
447
+ # The reservation only. A failed attempt does not close the pull request, so pr-pending
448
+ # is still true and the board should keep saying so.
449
+ - name: Release the issue
450
+ uses: ./.github/actions/remove-issue-labels
451
+ with:
452
+ token: ${{ steps.app-token.outputs.token }}
453
+ issue-number: ${{ needs.subject.outputs.issue }}
454
+ labels: ${{ env.WORKING_LABEL }}
455
+
456
+ agent:
457
+ # The top-level guard reads both outputs. GitHub Actions does not make a
458
+ # dependency's dependencies available through `needs` transitively.
459
+ needs: [subject, protected_changes]
460
+ if: always() && (needs.protected_changes.outputs.requires_review != 'true' || needs.subject.outputs.conclusion == 'failure') && needs.subject.outputs.review_blocked != 'true'
461
+
462
+ if: always() && needs.subject.outputs.found == 'true' && (needs.protected_changes.outputs.requires_review != 'true' || needs.subject.outputs.conclusion == 'failure') && needs.subject.outputs.review_blocked != 'true'
463
+
464
+ runs-on: agents-arc
465
+ runs-on-slim: agents-arc
466
+
467
+ secrets:
468
+ OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
469
+
470
+ engine:
471
+ id: opencode
472
+ version: "1.2.14"
473
+ env:
474
+ OPENAI_BASE_URL: https://forge.plainconcepts.com/v1
475
+
476
+ model: openai/glm-5-3
477
+
478
+ max-turns: 300
479
+ max-turn-cache-misses: 3000
480
+ max-ai-credits: 5000
481
+
482
+ permissions: read-all
483
+
484
+ # push-to-pull-request-branch with target "*" cannot reach a branch the shallow clone
485
+ # does not have.
486
+ checkout:
487
+ fetch: ["*"]
488
+ fetch-depth: 0
489
+
490
+ # Rung 3. The diff is what the risk assessment reads, and the failing logs are what a fix
491
+ # starts from. Both are known from the inputs, so neither costs the agent a turn.
492
+ steps:
493
+ # gh-aw checks out the router's ref. Its own "Checkout PR branch" step runs only when the event
494
+ # carries a pull request, which a router dispatch does not, so the agent would start on main.
495
+ # apply-agent-output fast-forwards origin/<branch> to the bundle tip and refuses anything else,
496
+ # and gh-aw builds that bundle from what the agent committed on top of the checkout; both need
497
+ # the agent to start on the branch it pushes to.
498
+ - name: Check out the pull request branch
499
+ env:
500
+ GH_TOKEN: ${{ github.token }}
501
+ REPO: ${{ github.repository }}
502
+ PR: ${{ needs.subject.outputs.pr }}
503
+ run: |
504
+ set -euo pipefail
505
+ branch=$(gh pr view "$PR" --repo "$REPO" --json headRefName --jq '.headRefName')
506
+ git switch --track "origin/$branch" 2>/dev/null || git switch "$branch"
507
+ echo "On $(git branch --show-current) at $(git rev-parse --short HEAD)"
508
+ # Every merge into the default branch invalidates every other open pull request that added a
509
+ # changelog entry, because they all insert at the top of the same list. The conflict is real
510
+ # and never interesting: both entries belong, newest first. Without a driver it costs a model
511
+ # run per sibling pull request, and it recurs on every merge while more than one is in flight.
512
+ # A consumer opts in by naming its own changelog in .gitattributes with `merge=changelog`;
513
+ # repositories that do not are unaffected, because git only calls a driver a path asks for.
514
+ - name: Teach git how to merge a changelog
515
+ run: |
516
+ set -euo pipefail
517
+ git config merge.changelog.name "newest-first changelog entries"
518
+ git config merge.changelog.driver "node $GITHUB_WORKSPACE/scripts/merge-changelog.mjs %O %A %B"
519
+ - name: Load the issue context
520
+ uses: ./.github/actions/load-issue-context
521
+ with:
522
+ token: ${{ github.token }}
523
+ issue-number: ${{ needs.subject.outputs.issue }}
524
+ output-path: ${{ env.ISSUE_CONTEXT_PATH }}
525
+ - name: Fetch the diff and any failing job logs
526
+ env:
527
+ GH_TOKEN: ${{ github.token }}
528
+ REPO: ${{ github.repository }}
529
+ PR: ${{ needs.subject.outputs.pr }}
530
+ RUN_ID: ${{ needs.subject.outputs.run-id }}
531
+ CONCLUSION: ${{ needs.subject.outputs.conclusion }}
532
+ run: |
533
+ set -euo pipefail
534
+ mkdir -p /tmp/gh-aw/agent
535
+ gh pr diff "$PR" --repo "$REPO" > /tmp/gh-aw/agent/diff.patch
536
+ gh pr view "$PR" --repo "$REPO" --json title,body,files,additions,deletions \
537
+ > /tmp/gh-aw/agent/pr.json
538
+ if [ "$CONCLUSION" = "failure" ] && [ -n "$RUN_ID" ]; then
539
+ gh run view "$RUN_ID" --repo "$REPO" --log-failed \
540
+ > /tmp/gh-aw/agent/failed-logs.txt 2>/dev/null || \
541
+ echo "logs unavailable" > /tmp/gh-aw/agent/failed-logs.txt
542
+ gh run view "$RUN_ID" --repo "$REPO" --json jobs \
543
+ --jq '[.jobs[] | select(.conclusion == "failure") | {name, conclusion}]' \
544
+ > /tmp/gh-aw/agent/failed-jobs.json
545
+ elif [ "$CONCLUSION" = "failure" ]; then
546
+ echo "[]" > /tmp/gh-aw/agent/failed-jobs.json
547
+ echo "CI run ID unavailable, cannot fetch logs" > /tmp/gh-aw/agent/failed-logs.txt
548
+ fi
549
+
550
+ safe-outputs:
551
+ # Path B. Without this, gh-aw's own safe_outputs job writes as well as the conclude job, and
552
+ # it runs first: it pushed a flattened, single-parent commit with GITHUB_TOKEN while conclude
553
+ # was still waiting, so the agent's merge commit was lost, the pull request stayed
554
+ # conflicting, and GITHUB_TOKEN raises no events, so no CI ran on the new head and the belt
555
+ # stalled (Pliny-Bot run 34051821011). Staged runs everything and writes nothing; conclude
556
+ # applies the bundle and the comment with the App token, which does start CI.
557
+ staged: true
558
+ # A failed run is already a red run. An issue per failure buries the real backlog
559
+ # under noise nobody closes.
560
+ report-failure-as-issue: false
561
+ threat-detection: false
562
+ # target "*" because these workers are dispatched, not triggered by the pull request:
563
+ # the default "triggering" target has no pull request in context and rejects the push
564
+ # with "requires pull request context", so the agent's fix is computed and discarded.
565
+ push-to-pull-request-branch:
566
+ target: "*"
567
+ required-title-prefix: "[bot] "
568
+ # A failed bot PR may already contain protected files. Permit a verified repair push,
569
+ # but protected_changes still prevents the later green-CI cycle from auto-merging it.
570
+ protected-files: allowed
571
+ add-comment:
572
+ target: "*"
573
+
574
+ timeout-minutes: 60
575
+ ---
576
+
577
+ 1. You are gating pull request **#${{ needs.subject.outputs.pr }}**, which closes issue
578
+ **#${{ needs.subject.outputs.issue }}**. CI concluded
579
+ **${{ needs.subject.outputs.conclusion }}**.
580
+
581
+ It has already been confirmed that this is an open pull request we authored, that it closes
582
+ an issue, and that the issue carries `implement`. Do not re-check any of that, and do not
583
+ poll for checks: the conclusion above is the answer.
584
+
585
+ You are on the pull request branch. Never rebase, reset, amend or otherwise rewrite
586
+ history: the workflow applies your commits as a bundle with a fast-forward-only push and
587
+ discards anything that is not a descendant of the branch tip. The
588
+ `push_to_pull_request_branch` tool's own description recommends rebasing; in this
589
+ repository that advice is wrong. Merge, commit, and let the workflow push.
590
+
591
+ 2. Read `${{ env.ISSUE_CONTEXT_PATH }}`. It contains the issue body and its discussion. When
592
+ running `/repo-verify`, the acceptance criteria there define what the implementation must
593
+ satisfy.
594
+
595
+ 3. Branch on the conclusion.
596
+
597
+ First check the issue context for `<!-- complexity: trivial -->`.
598
+
599
+ **If the trivial marker is present AND CI conclusion is success:**
600
+ Skip the full assessment (step 5). Emit a minimal assessment table with all checks marked
601
+ ✅ and the note "Trivial change, CI green — deep risk review skipped." Then proceed directly
602
+ to step 8 (merge verdict).
603
+
604
+ **If the trivial marker is absent OR CI is not success:**
605
+ Follow the normal branching below.
606
+
607
+ - **success** → step 4, then step 5 (full assessment).
608
+ - **action_required** → CI did not run because the workflow needs approval.
609
+ Emit the assessment table with ❌ on CI Status and note that a maintainer must approve
610
+ the pending run. Select the `review` verdict.
611
+ - **failure** → step 4, then step 6 (CI remediation).
612
+ - **cancelled, timed_out, or anything else** → Emit the assessment table with ❌ on CI
613
+ Status and select the `review` verdict. A cancelled or unknown run is not evidence of
614
+ anything.
615
+
616
+ Follow repository documentation and established conventions when assessing or remediating
617
+ the pull request. Protect secrets, do not bypass checks, and keep remediation focused.
618
+ Adhere to ${{ env.REPO_RULES }}.
619
+
620
+ 4. Read the diff and PR metadata. Read `/tmp/gh-aw/agent/diff.patch` in full and
621
+ `/tmp/gh-aw/agent/pr.json` for the shape of the change. If CI failed, also read
622
+ `/tmp/gh-aw/agent/failed-jobs.json` and `/tmp/gh-aw/agent/failed-logs.txt`.
623
+
624
+ These files are the factual basis for every check below. Do not guess — cite what you read.
625
+
626
+ 4b. **Merge conflict when CI is green.** If the conclusion is `success` and
627
+ `has_conflicts` is `true` (current value: `${{ needs.reserve.outputs.has_conflicts }}`),
628
+ resolve the conflict before assessing risk. You are already on the PR branch.
629
+ Merge `origin/${{ github.event.repository.default_branch }}` into it
630
+ (`git merge origin/${{ github.event.repository.default_branch }}`), resolve every
631
+ conflict deliberately, commit the merge, and run the verification commands below. Do not
632
+ use `--ours`, `--theirs`, or a blanket conflict-marker deletion without reviewing the
633
+ intended behavior from both sides, and never rebase: the push is fast-forward only.
634
+
635
+ Scope verification to the files the merge touched: pass changed file paths to
636
+ lint/format tools instead of running them repository-wide (see step 6's scoped
637
+ verification guidance).
638
+
639
+ ```
640
+ ${{ env.VERIFY_COMMANDS }}
641
+ ```
642
+
643
+ Push the merged branch using `push_to_pull_request_branch` (pr_number: ${{ needs.subject.outputs.pr }},
644
+ branch: the current PR branch), then emit the `add_comment` with
645
+ **Verdict:** remediated. CI will re-run on the updated branch and the merge gate
646
+ will be triggered again — the next cycle will see a clean, conflict-free PR and can
647
+ make a proper merge or review decision.
648
+
649
+ If the merge cannot be completed or the conflicts are genuinely ambiguous, select the `review`
650
+ verdict instead and explain which conflicts could not be resolved safely.
651
+
652
+ If the conclusion is `success` and `has_conflicts` is `false`, skip this step and
653
+ proceed to step 5.
654
+
655
+ 5. Run each of these 10 checks. For each, determine a status and a short detail line.
656
+
657
+ **Check 1 — CI Status.** What did CI conclude? Success means all required checks passed.
658
+ Failure means at least one job failed. Action required means a workflow needs approval.
659
+ Flag any non-success conclusion.
660
+
661
+ **Check 2 — Auth & Security.** Does the diff touch authentication, authorization, secrets,
662
+ credentials, or security boundaries? Flag any change to auth middleware, permission checks,
663
+ token issuance, or security-related config.
664
+
665
+ **Check 3 — API & Contracts.** Does the diff change a public API or a published package's
666
+ contract? Flag changes to endpoint signatures, DTO shapes, exported interfaces, or
667
+ serialization formats that could break consumers.
668
+
669
+ **Check 4 — Tests.** Does the diff delete, weaken, or lower a threshold in a test? Flag
670
+ removed assertions, skipped tests, lowered coverage bars, or deleted test files.
671
+
672
+ **Check 5 — CI/CD & Workflow files.** Does the diff change CI, CD, or workflow files?
673
+ Flag changes to `.github/workflows/`, Dockerfiles, deployment scripts, or infrastructure
674
+ configuration.
675
+
676
+ **Check 6 — Protected files.** Does the diff change a protected file? This is normally
677
+ handled before you run, but never merge one if it reaches this gate. Flag any match against
678
+ the repository's protected file list.
679
+
680
+ **Check 7 — Scope.** Is the diff size consistent with what the issue implied? Compare the
681
+ number of files changed and lines added/removed against the complexity the issue described.
682
+ Flag if the diff is materially larger or smaller than expected.
683
+
684
+ **Check 8 — Repository risk indicators.** Does the diff touch any risk indicator defined in
685
+ ${{ env.REPO_RULES }}? Review the repository guardrails for domain-specific risk areas such
686
+ as calculation engines, audit chains, authentication, database migrations, or money handling.
687
+ Flag any
688
+ match and name the specific indicator.
689
+
690
+ **Check 9 — Mergeability.** Can the PR be merged cleanly? The value is
691
+ `${{ needs.reserve.outputs.has_conflicts }}`. If conflicts exist, this is ❌ but not a
692
+ blocking verdict — proceed to remediation (step 6). If no conflicts, ✅.
693
+
694
+ **Check 10 — Confidence.** Are you confident in the merge decision? Low confidence is
695
+ itself a flag. If you are unsure about the impact of the change, mark ⚠️ and explain what
696
+ is uncertain. A human should review when confidence is low.
697
+
698
+ 6. **CI failed** → read `/tmp/gh-aw/agent/failed-jobs.json` and
699
+ `/tmp/gh-aw/agent/failed-logs.txt`, which are already on disk. Load only skills required to
700
+ fix the actual cause. Run these verification commands before a push. Do not weaken a test,
701
+ disable a check, or push an unverified guess.
702
+
703
+ **Empty failure evidence is not a reason to ask for review.** If `failed-jobs.json` is `[]`
704
+ or the logs say they were unavailable, then no CI run judged this head. That is the normal
705
+ state of a conflicting pull request: GitHub cannot build `refs/pull/N/merge` while the
706
+ conflict lasts, so no `pull_request` CI can run on it and there is nothing to read. The
707
+ conflict is the failure to fix. Resolve it as described above, push, and select
708
+ `remediated`; CI runs on the result and the next cycle gets a real verdict. Select `review`
709
+ for missing evidence only when `has_conflicts` is `false`, because then there is genuinely
710
+ nothing to act on.
711
+
712
+ **Scoped verification.** The commands below are the full suite. This runner has limited
713
+ memory, and a whole-repo lint or build can be killed mid-run. Scope verification to the
714
+ files you actually changed first, and only escalate to the full suite when the scoped run
715
+ passes and you are still unsure:
716
+ - Lint/format (biome, eslint, prettier, ruff, etc.): pass the changed file paths as
717
+ arguments so the tool checks only those files (e.g. `pnpm exec biome check <files>`),
718
+ never the whole repository.
719
+ - Build: prefer building only the project(s) containing the changed files; use the full
720
+ solution build only when the change crosses project boundaries.
721
+ - Tests: run the test project covering the changed files; run the full suite only when
722
+ the change is cross-cutting.
723
+ If verification of exactly the CI-failing job is what you need, reproduce just that job's
724
+ command, not the entire pipeline.
725
+
726
+ A PR that already contains protected files still requires remediation. You may include those
727
+ files in the verified repair push, but the next green-CI cycle will require human review and
728
+ must not auto-merge the PR.
729
+
730
+ **If `has_conflicts` is `true` (current value: `${{ needs.reserve.outputs.has_conflicts }}`):** You are already on the PR branch. Resolve the conflict;
731
+ it is not a reason to hand the PR to a human. Merge `origin/${{ github.event.repository.default_branch }}`
732
+ into the current branch, resolve every conflict deliberately, stage the resolutions, and
733
+ commit the merge. Then run verification and push the resulting branch update. Do not use
734
+ `--ours`, `--theirs`, or a blanket conflict-marker deletion without reviewing the intended
735
+ behavior from both sides.
736
+
737
+ ```
738
+ ${{ env.VERIFY_COMMANDS }}
739
+ ```
740
+
741
+ Propose `push_to_pull_request_branch` (pr_number: ${{ needs.subject.outputs.pr }}, branch:
742
+ the current PR branch), then select the `remediated` verdict. CI will run again and trigger
743
+ you again with the new result.
744
+
745
+ Before pushing, run the project's lint fix command (e.g. `pnpm lint:fix` or
746
+ `pnpm exec biome check --write <changed-files>`) to auto-format. If lint:fix is not
747
+ available, fix formatting manually. Never push code with lint errors.
748
+
749
+ If you cannot fix it after a concrete repair attempt, or the logs show you have already tried on this same head commit,
750
+ stop looping: select the `review` verdict and explain the failure and what you tried. A human
751
+ decides from there.
752
+
753
+ 7. Decide the verdict based on the assessment table:
754
+
755
+ - **All checks ✅ → `merge`.** The PR is safe to merge. CI is green, no risk indicators
756
+ triggered, tests are intact, scope matches, mergeability is clean.
757
+ - **Any check ⚠️ or ❌ (except CI failure) → `review`.** Do not merge. Explain exactly which
758
+ check tripped, why, and what a reviewer should look at. Leave `implement` in place: the
759
+ work is not finished until a human merges it.
760
+ - **CI failed and you fixed it → `remediated`.** You pushed a verified fix and CI will
761
+ re-run.
762
+ - **CI failed and you cannot fix it → `review`.** Explain the failure and what you tried.
763
+
764
+ Never merge with administrator privileges and never bypass a required check. If the merge
765
+ is refused, that refusal is the answer: select `review` and leave it for a human.
766
+
767
+ 8. Emit exactly one `add_comment` targeting issue `${{ needs.subject.outputs.issue }}` with:
768
+ 1. `${{ env.GATE_MARKER }}`
769
+ 2. A heading: `## Merge gate decision for PR #${{ needs.subject.outputs.pr }}`
770
+ 3. A structured assessment table with all 10 check results
771
+ 4. A one-line detail per check (what was found and why it passed or flagged)
772
+ 5. A line `**Verdict:** merge`, `**Verdict:** review`, or `**Verdict:** remediated`
773
+
774
+ The workflow applies comments, labels, merges, and closures with the App token. Do not call
775
+ any tools except the one optional `push_to_pull_request_branch` for a verified CI repair
776
+ and this one `add_comment`.
777
+
778
+ Format the checks as a table with status indicators:
779
+
780
+ ```
781
+ ### Assessment
782
+
783
+ # Check Result
784
+ 1 CI Status ✅ Success / ❌ Failure: [job name] / ⚠️ Action required
785
+ 2 Auth & Security ✅ No changes / ⚠️ Touched: [area]
786
+ 3 API & Contracts ✅ No changes / ⚠️ Changed: [area]
787
+ 4 Tests ✅ Not weakened / ⚠️ Weakened: [file]
788
+ 5 CI/CD & Workflow ✅ No changes / ⚠️ Changed: [file]
789
+ 6 Protected files ✅ None touched / ❌ Touched: [file]
790
+ 7 Scope ✅ Appropriately scoped / ⚠️ [too large/small: reason]
791
+ 8 Risk indicators ✅ None triggered / ⚠️ Triggered: [indicator]
792
+ 9 Mergeability ✅ Clean / ⚠️ Conflicts
793
+ 10 Confidence ✅ High / ⚠️ Low: [reason]
794
+ ```
795
+
796
+ Then a line `**Verdict:** merge` / `**Verdict:** review` / `**Verdict:** remediated`
797
+
798
+ 9. Ignore the `## Diagram` section below. It is documentation for humans and contains no
799
+ instructions for you.
800
+
801
+ ## Diagram
802
+
803
+ ```mermaid
804
+ flowchart TD
805
+ gateStart("Work Router<br/>merge-gate route<br/>(CI completed)") --> gateSubject
806
+ gateSubject["Subject (rung 4)<br/>Our PR? Closes an implement issue?"] -->|✓| gateFacts
807
+ gateSubject -.->|✗| gateIdle
808
+ gateFacts("Facts (rung 3)<br/>Diff, PR shape, failing logs") --> gateCi
809
+ gateCi["CI<br/>What did it conclude?"] -->|success| gateProtected
810
+ gateProtected{"Protected files?"}
811
+ gateProtected -.->|yes| gateHuman
812
+ gateProtected -->|no| gateConflict
813
+ gateConflict{"Merge conflicts?"}
814
+ gateConflict -->|yes| gateRebase
815
+ gateConflict -->|no| gateTrivial
816
+ gateRebase("Merge main in<br/>Resolve conflicts, /repo-verify") -->|pushed| gateWait
817
+ gateRebase -.->|cannot resolve| gateHuman
818
+ gateTrivial{"Trivial marker?"}
819
+ gateTrivial -->|yes| gateMerge
820
+ gateTrivial -->|no| gateAssess
821
+ gateCi -.->|failure| gateFix
822
+ gateCi -.->|no verdict| gateHuman
823
+ gateAssess["Assessment (10 checks)<br/>CI, Auth, API, Tests, CI/CD<br/>Protected, Scope, Risk, Merge, Confidence"] -->|all ✅| gateMerge
824
+ gateAssess -.->|any ⚠️/❌| gateHuman
825
+ gateFix("Fix<br/>Read logs, fix the cause, /repo-verify") -->|pushed| gateWait
826
+ gateFix -.->|cannot fix| gateHuman
827
+ gateMerge(("Merged<br/>Issue closed, review+labels removed"))
828
+ gateWait(("Pushed<br/>CI will re-run and re-trigger via Router"))
829
+ gateHuman(("Review<br/>review label, reason explained"))
830
+ gateIdle(("Idle<br/>Not our pull request"))
831
+
832
+ classDef start fill:#ffffff,stroke:#172033,stroke-width:2px,color:#172033
833
+ classDef action fill:#eef0ff,stroke:#554cff,stroke-width:2px,color:#172033
834
+ classDef decision fill:#fff8e8,stroke:#c75b00,stroke-width:2px,color:#172033
835
+ classDef idle fill:#202c40,stroke:#738198,stroke-width:2px,color:#ffffff
836
+ classDef failure fill:#fff0f0,stroke:#ef2929,stroke-width:2px,color:#8b1a2a
837
+ classDef success fill:#e8f8ec,stroke:#18883c,stroke-width:2px,color:#145a32
838
+ class gateStart start
839
+ class gateFacts,gateFix,gateRebase action
840
+ class gateSubject,gateCi,gateAssess,gateTrivial,gateConflict,gateProtected decision
841
+ class gateIdle,gateWait idle
842
+ class gateHuman failure
843
+ class gateMerge success
844
+ ```