forgedock 1.37.0 → 1.38.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 (81) hide show
  1. package/bin/engine/outcome-codes.mjs +12 -3
  2. package/bin/engine/telemetry-seam.mjs +5 -0
  3. package/bin/engine-cli.mjs +97 -18
  4. package/bin/forgedock.mjs +13 -2
  5. package/bin/lean/activation.mjs +76 -0
  6. package/bin/lean/activation.test.mjs +75 -0
  7. package/bin/lean/admission.mjs +17 -1
  8. package/bin/lean/batch.mjs +51 -21
  9. package/bin/lean/batch.test.mjs +95 -5
  10. package/bin/lean/conformance.mjs +53 -4
  11. package/bin/lean/conformance.test.mjs +24 -1
  12. package/bin/lean/decision-engine.mjs +217 -0
  13. package/bin/lean/decision-engine.test.mjs +159 -0
  14. package/bin/lean/effects.mjs +39 -13
  15. package/bin/lean/execution.mjs +74 -5
  16. package/bin/lean/execution.test.mjs +64 -1
  17. package/bin/lean/explore.test.mjs +1 -1
  18. package/bin/lean/guards.mjs +3 -2
  19. package/bin/lean/guards.test.mjs +24 -3
  20. package/bin/lean/heavy.mjs +15 -2
  21. package/bin/lean/heavy.test.mjs +31 -2
  22. package/bin/lean/issuewatch-release.mjs +245 -0
  23. package/bin/lean/issuewatch-release.test.mjs +244 -0
  24. package/bin/lean/issuewatch.mjs +386 -0
  25. package/bin/lean/issuewatch.test.mjs +280 -0
  26. package/bin/lean/lane.mjs +4 -3
  27. package/bin/lean/lane.test.mjs +12 -0
  28. package/bin/lean/lean.mjs +103 -16
  29. package/bin/lean/lean.test.mjs +127 -5
  30. package/bin/lean/needs-human-premise.mjs +177 -0
  31. package/bin/lean/needs-human-premise.test.mjs +136 -0
  32. package/bin/lean/orchestrate-blocked.test.mjs +71 -0
  33. package/bin/lean/orchestrate.mjs +93 -21
  34. package/bin/lean/postdeploy-check.mjs +88 -2
  35. package/bin/lean/postdeploy-check.test.mjs +78 -0
  36. package/bin/lean/prodwatch-sources.mjs +165 -0
  37. package/bin/lean/prodwatch-sources.test.mjs +108 -0
  38. package/bin/lean/prompts.mjs +9 -3
  39. package/bin/lean/recovery.test.mjs +14 -0
  40. package/bin/lean/relay.mjs +182 -0
  41. package/bin/lean/relay.test.mjs +214 -0
  42. package/bin/lean/sandbox-provider.contract.test.mjs +13 -1
  43. package/bin/lean/sandbox-remote.mjs +53 -9
  44. package/bin/lean/sched.test.mjs +30 -0
  45. package/bin/lean/schedd-health.mjs +69 -0
  46. package/bin/lean/schedd-health.test.mjs +51 -0
  47. package/bin/lean/schedd.mjs +29 -12
  48. package/bin/lean/schedd.test.mjs +40 -4
  49. package/bin/lean/sequence.mjs +57 -24
  50. package/bin/lean/sequence.test.mjs +71 -0
  51. package/bin/pool/agent.mjs +15 -1
  52. package/bin/pool/router.mjs +43 -5
  53. package/bin/runner.mjs +18 -1
  54. package/commands/deploy-pr.md +12 -0
  55. package/commands/forgedock-init.md +1 -0
  56. package/commands/orchestrate/phase-4-execution.md +1 -0
  57. package/commands/orchestrate.md +1 -0
  58. package/commands/review-pr.md +17 -13
  59. package/docs/CONFIG.md +73 -2
  60. package/docs/DECISIONS.md +32 -0
  61. package/docs/ISSUE-WATCH.md +95 -0
  62. package/docs/NORTHSTAR-TEMPLATE.md +21 -0
  63. package/docs/OUTCOME-CODES.md +2 -1
  64. package/docs/TELEMETRY.md +7 -0
  65. package/package.json +1 -2
  66. package/pool/README.md +1 -1
  67. package/pool/image/Dockerfile +2 -1
  68. package/pool/image/cs-relay +31 -0
  69. package/pool/image/entrypoint.sh +10 -0
  70. package/pool/install/install-schedd.sh +22 -0
  71. package/pool/install/unit-hardening.sh +6 -0
  72. package/scripts/postdeploy-rollup-link.sh +40 -0
  73. package/scripts/postdeploy-rollup-link.test.sh +46 -0
  74. package/scripts/refresh-bot-token.sh +122 -0
  75. package/scripts/review-delta.sh +14 -4
  76. package/scripts/review-delta.test.sh +21 -0
  77. package/scripts/review-finalize.sh +69 -25
  78. package/scripts/review-finalize.test.sh +32 -0
  79. package/scripts/review-pr-arguments.test.sh +10 -0
  80. package/scripts/review-pr-changed-verification.test.sh +54 -0
  81. package/scripts/review-pr-delta-wiring.test.sh +1 -1
@@ -28,6 +28,16 @@ if [ -n "${CS_CRED_BASE:-}" ]; then
28
28
  elif [ -n "${GH_TOKEN:-}" ]; then
29
29
  gh auth setup-git >/dev/null 2>&1 || true
30
30
  fi
31
+ # #4778: allowlisted read-only host wrappers (e.g. obs-psql) run through cs-relay on the dispatching host, unchanged argv.
32
+ if [ -n "${CS_RELAY_COMMANDS:-}" ]; then
33
+ mkdir -p /opt/cs/bin
34
+ IFS=',' read -ra relay_cmds <<<"$CS_RELAY_COMMANDS"
35
+ for c in "${relay_cmds[@]}"; do
36
+ [[ "$c" =~ ^[A-Za-z0-9._-]+$ ]] || continue
37
+ printf '#!/usr/bin/env bash\nexec cs-relay %s "$@"\n' "$c" > "/opt/cs/bin/$c"
38
+ chmod 0755 "/opt/cs/bin/$c"
39
+ done
40
+ fi
31
41
  git config --global user.name "${GIT_AUTHOR_NAME:-forgedock}"
32
42
  git config --global user.email "${GIT_AUTHOR_EMAIL:-forgedock@localhost}"
33
43
 
@@ -16,13 +16,35 @@ $(unit_start_limit)
16
16
  [Service]
17
17
  ExecStart=$NODE $REPO_ROOT/bin/forgedock.mjs schedd
18
18
  $(unit_hardening user)
19
+ $(unit_priority user)
19
20
 
20
21
  [Install]
21
22
  WantedBy=default.target
22
23
  UNIT
24
+ # #4780: a wedged daemon is alive, so Restart=always never fires; this timer signals one whose heartbeat went stale.
25
+ cat > "$HOME/.config/systemd/user/forgedock-schedd-watchdog.service" <<UNIT
26
+ [Unit]
27
+ Description=forgedock schedd watchdog
28
+
29
+ [Service]
30
+ Type=oneshot
31
+ ExecStart=$NODE $REPO_ROOT/bin/forgedock.mjs schedd watchdog
32
+ UNIT
33
+ cat > "$HOME/.config/systemd/user/forgedock-schedd-watchdog.timer" <<UNIT
34
+ [Unit]
35
+ Description=forgedock schedd watchdog
36
+
37
+ [Timer]
38
+ OnBootSec=60
39
+ OnUnitActiveSec=30s
40
+
41
+ [Install]
42
+ WantedBy=timers.target
43
+ UNIT
23
44
  systemctl --user daemon-reload
24
45
  systemctl --user enable --now forgedock-schedd >/dev/null
25
46
  systemctl --user restart forgedock-schedd
47
+ systemctl --user enable --now forgedock-schedd-watchdog.timer >/dev/null
26
48
  unit_oom_hint forgedock-schedd
27
49
  loginctl enable-linger "$USER" 2>/dev/null || true
28
50
  echo "[forgedock] schedd unit installed"
@@ -18,6 +18,12 @@ unit_hardening() {
18
18
  printf 'OOMScoreAdjust=%s\nRestart=always\nRestartSec=5\n' "$(unit_oom_score_adj "${1:-user}")"
19
19
  }
20
20
 
21
+ # unit_priority user|system: [Service] lines giving a scheduler daemon CPU priority over the lanes it launches (#4780).
22
+ # An unprivileged user manager cannot set a negative Nice (needs CAP_SYS_NICE), so only a system unit gets one; the daemon also reniced itself best-effort.
23
+ unit_priority() {
24
+ if [ "${1:-user}" = system ]; then printf 'Nice=-5\nCPUWeight=500\n'; else printf 'CPUWeight=500\n'; fi
25
+ }
26
+
21
27
  # unit_start_limit: the [Unit] line that disables the start rate limit. systemd honours StartLimitIntervalSec only in [Unit], never in [Service].
22
28
  unit_start_limit() {
23
29
  printf 'StartLimitIntervalSec=0\n'
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env bash
2
+ # postdeploy-rollup-link.sh — print the deploy PR's link to the release lane's post-deploy rollup (#4727).
3
+ # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
4
+ # SPDX-License-Identifier: AGPL-3.0-or-later
5
+ #
6
+ # Usage: postdeploy-rollup-link.sh --repo OWNER/REPO
7
+ # Finds the lowest open, trusted, non-PR issue carrying <!-- FORGE:POSTDEPLOY_ROLLUP: <lane> --> (same search and trust
8
+ # rule as find_rollup in file-deferred-followups.sh) and prints `Post-deploy checklist: #N`.
9
+ # Prints nothing and exits 0 when there is none or a lookup fails: a missing link never blocks a deploy.
10
+ # Env: FORGE_RELEASE_LANE (default `default`), FORGE_TRAIL_TRUSTED_ASSOCIATIONS (default OWNER,MEMBER,COLLABORATOR),
11
+ # FORGE_TRAIL_TRUSTED_LOGINS (default empty). bash 3.2 portable.
12
+
13
+ set -uo pipefail
14
+ REPO=""
15
+ while [ $# -gt 0 ]; do
16
+ case "$1" in
17
+ --repo) [ $# -ge 2 ] || { echo "postdeploy-rollup-link: --repo requires a value" >&2; exit 2; }; REPO="$2"; shift 2 ;;
18
+ *) echo "usage: postdeploy-rollup-link.sh --repo OWNER/REPO" >&2; exit 2 ;;
19
+ esac
20
+ done
21
+ [ -n "$REPO" ] || { echo "postdeploy-rollup-link: --repo required" >&2; exit 2; }
22
+
23
+ LANE="${FORGE_RELEASE_LANE:-default}"
24
+ MARKER="<!-- FORGE:POSTDEPLOY_ROLLUP: ${LANE} -->"
25
+ TRUSTED_ASSOC="${FORGE_TRAIL_TRUSTED_ASSOCIATIONS-OWNER,MEMBER,COLLABORATOR}"
26
+ TRUSTED_LOGINS="${FORGE_TRAIL_TRUSTED_LOGINS-}"
27
+ JQ_PRE='def lst: split(",") | map(gsub("^\\s+|\\s+$"; "")) | map(select(length > 0));
28
+ def trusted: ((.author_association // "") as $x | ($assoc | lst) | index($x) != null)
29
+ or ((.user.type // "") == "Bot")
30
+ or ((.user.login // "") as $x | ($logins | lst) | index($x) != null);'
31
+
32
+ cands=$(gh api -X GET search/issues -f per_page=50 -f q="\"FORGE:POSTDEPLOY_ROLLUP: ${LANE}\" in:body repo:${REPO} is:issue is:open" 2>/dev/null \
33
+ | jq -r '[.items[].number] | sort_by(.) | .[]' 2>/dev/null) || exit 0
34
+ for n in $cands; do
35
+ out=$(gh api "repos/${REPO}/issues/${n}" 2>/dev/null) || exit 0
36
+ hit=$(printf '%s' "$out" | jq -r --arg assoc "$TRUSTED_ASSOC" --arg logins "$TRUSTED_LOGINS" --arg m "$MARKER" "$JQ_PRE"'
37
+ select(.pull_request == null) | select(trusted) | select(.state == "open") | select((.body // "") | contains($m)) | .number' 2>/dev/null) || exit 0
38
+ if [ -n "$hit" ]; then echo "Post-deploy checklist: #${hit}"; exit 0; fi
39
+ done
40
+ exit 0
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env bash
2
+ # postdeploy-rollup-link.test.sh — stubbed-gh tests for scripts/postdeploy-rollup-link.sh
3
+ # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
4
+ # SPDX-License-Identifier: AGPL-3.0-or-later
5
+ set -uo pipefail
6
+ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
+ S="$HERE/postdeploy-rollup-link.sh"
8
+ T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
9
+ mkdir "$T/bin"; export T_DIR="$T"
10
+ cat > "$T/bin/gh" <<'MOCK'
11
+ #!/usr/bin/env bash
12
+ if [ "$1 $2" = "api -X" ]; then [ -n "${LOOKUP_FAIL:-}" ] && exit 1; cat "$T_DIR/search.json"; exit 0; fi
13
+ n="${2##*/}"; [ -f "$T_DIR/issue.$n.json" ] && { cat "$T_DIR/issue.$n.json"; exit 0; }
14
+ echo "HTTP 404: Not Found" >&2; exit 1
15
+ MOCK
16
+ chmod +x "$T/bin/gh"; export PATH="$T/bin:$PATH"
17
+ PASS=0; FAIL=0
18
+ check() { if eval "$2"; then PASS=$((PASS+1)); echo "PASS: $1"; else FAIL=$((FAIL+1)); echo "FAIL: $1"; fi; }
19
+ M='<!-- FORGE:POSTDEPLOY_ROLLUP: default -->'
20
+ issue() { printf '{"number":%s,"state":"%s","author_association":"%s","user":{"type":"User"},"body":"%s"%s}\n' "$1" "$2" "$3" "$M" "${4:-}" > "$T/issue.$1.json"; }
21
+ reset() { rm -f "$T"/issue.*.json; unset LOOKUP_FAIL; echo '{"items":[{"number":9},{"number":5}]}' > "$T/search.json"; }
22
+
23
+ reset; issue 5 open OWNER; issue 9 open OWNER
24
+ OUT=$(bash "$S" --repo o/r); RC=$?
25
+ check "link: lowest open trusted rollup" "[ $RC -eq 0 ] && [ \"\$OUT\" = 'Post-deploy checklist: #5' ]"
26
+
27
+ reset; issue 5 open NONE; issue 9 open OWNER
28
+ OUT=$(bash "$S" --repo o/r)
29
+ check "untrusted author skipped, next candidate used" "[ \"\$OUT\" = 'Post-deploy checklist: #9' ]"
30
+
31
+ reset; issue 5 closed OWNER; issue 9 open OWNER ',"pull_request":{}'
32
+ OUT=$(bash "$S" --repo o/r); RC=$?
33
+ check "closed issue and PR ignored: empty, rc 0" "[ $RC -eq 0 ] && [ -z \"\$OUT\" ]"
34
+
35
+ reset; echo '{"items":[]}' > "$T/search.json"
36
+ OUT=$(bash "$S" --repo o/r); RC=$?
37
+ check "no rollup: empty, rc 0" "[ $RC -eq 0 ] && [ -z \"\$OUT\" ]"
38
+
39
+ reset; issue 5 open OWNER; OUT=$(LOOKUP_FAIL=1 bash "$S" --repo o/r); RC=$?
40
+ check "lookup failure: empty, rc 0" "[ $RC -eq 0 ] && [ -z \"\$OUT\" ]"
41
+
42
+ reset; issue 5 open OWNER; OUT=$(FORGE_RELEASE_LANE=other bash "$S" --repo o/r)
43
+ check "other lane marker does not match" "[ -z \"\$OUT\" ]"
44
+
45
+ bash "$S" >/dev/null 2>&1; check "missing --repo: exit 2" "[ $? -eq 2 ]"
46
+ echo "passed=$PASS failed=$FAIL"; [ "$FAIL" -eq 0 ]
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env bash
2
+ # SPDX-FileCopyrightText: Copyright (c) RapierCraft Studios
3
+ # SPDX-License-Identifier: AGPL-3.0-or-later
4
+ #
5
+ # scripts/refresh-bot-token.sh — refresh the rapiercraft-forgedock[bot] installation token.
6
+ #
7
+ # Generates a JWT from the app's private key, exchanges it for a 1-hour
8
+ # installation token, and re-auths the gh CLI. Idempotent — safe to run
9
+ # on every session start or from cron.
10
+ #
11
+ # Supports two installations:
12
+ # RapierCraftStudios (org) — installation 144998831 (default)
13
+ # RapierCraft (personal) — installation 140233364
14
+ #
15
+ # Usage: scripts/refresh-bot-token.sh [--pem /path/to/key.pem] [--personal]
16
+ #
17
+ # Env: FORGEDOCK_APP_PEM — path to private key (default: secrets/rapiercraft-forgedock.pem)
18
+
19
+ set -euo pipefail
20
+
21
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
22
+ FORGE_HOME="$(cd "$SCRIPT_DIR/.." && pwd)"
23
+
24
+ APP_ID="4051319"
25
+ ORG_INSTALLATION_ID="144998831"
26
+ PERSONAL_INSTALLATION_ID="140233364"
27
+ DEFAULT_PEM="$FORGE_HOME/secrets/rapiercraft-forgedock.pem"
28
+
29
+ # --- Parse args ---
30
+ PEM_PATH="${FORGEDOCK_APP_PEM:-$DEFAULT_PEM}"
31
+ INSTALLATION_ID="$ORG_INSTALLATION_ID"
32
+ while [[ $# -gt 0 ]]; do
33
+ case "$1" in
34
+ --pem) PEM_PATH="$2"; shift 2 ;;
35
+ --personal) INSTALLATION_ID="$PERSONAL_INSTALLATION_ID"; shift ;;
36
+ *) echo "Unknown arg: $1" >&2; exit 1 ;;
37
+ esac
38
+ done
39
+
40
+ if [[ ! -f "$PEM_PATH" ]]; then
41
+ echo "ERROR: Private key not found at $PEM_PATH" >&2
42
+ echo " Set FORGEDOCK_APP_PEM or pass --pem /path/to/key.pem" >&2
43
+ exit 1
44
+ fi
45
+
46
+ # --- Generate JWT and exchange for installation token ---
47
+ INSTALL_TOKEN=$(node -e "
48
+ var crypto = require('crypto');
49
+ var fs = require('fs');
50
+ var https = require('https');
51
+ var pem = fs.readFileSync(process.argv[1], 'utf8');
52
+ var now = Math.floor(Date.now() / 1000);
53
+ var h = Buffer.from(JSON.stringify({alg:'RS256',typ:'JWT'})).toString('base64url');
54
+ var p = Buffer.from(JSON.stringify({iat:now-60,exp:now+(9*60),iss:process.argv[2]})).toString('base64url');
55
+ var s = crypto.createSign('RSA-SHA256');
56
+ s.update(h+'.'+p);
57
+ var jwt = h+'.'+p+'.'+s.sign(pem,'base64url');
58
+ var opts = {
59
+ hostname: 'api.github.com',
60
+ path: '/app/installations/'+process.argv[3]+'/access_tokens',
61
+ method: 'POST',
62
+ headers: {
63
+ 'Authorization': 'Bearer '+jwt,
64
+ 'Accept': 'application/vnd.github+json',
65
+ 'User-Agent': 'forgedock-refresh'
66
+ }
67
+ };
68
+ var req = https.request(opts, function(res) {
69
+ var body = '';
70
+ res.on('data', function(c) { body += c; });
71
+ res.on('end', function() {
72
+ var t = JSON.parse(body).token;
73
+ if (!t) { process.stderr.write('API error: '+body); process.exit(1); }
74
+ process.stdout.write(t);
75
+ });
76
+ });
77
+ req.end();
78
+ " "$PEM_PATH" "$APP_ID" "$INSTALLATION_ID")
79
+
80
+ if [[ -z "$INSTALL_TOKEN" ]]; then
81
+ echo "ERROR: Failed to obtain installation token" >&2
82
+ exit 1
83
+ fi
84
+
85
+ # --- Auth gh CLI ---
86
+ # gh rewrites hosts.yml in place, and concurrent lanes read it (#4507): run the auth in a staging config dir next to
87
+ # the real one, then rename hosts.yml into place (same filesystem, so readers see the old or the new file, never half).
88
+ GH_CFG="${GH_CONFIG_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/gh}"
89
+ mkdir -p "$GH_CFG"
90
+ STAGE=$(mktemp -d "$GH_CFG/.hosts-stage.XXXXXX")
91
+ trap 'rm -rf "$STAGE"' EXIT
92
+ for f in config.yml hosts.yml; do
93
+ if [[ -f "$GH_CFG/$f" ]]; then cp -p "$GH_CFG/$f" "$STAGE/$f"; fi
94
+ done
95
+
96
+ echo "$INSTALL_TOKEN" | GH_CONFIG_DIR="$STAGE" gh auth login --with-token 2>/dev/null
97
+
98
+ # --- Clean up stale old bot if present ---
99
+ if GH_CONFIG_DIR="$STAGE" gh auth status 2>&1 | grep -q "rapiercraft-forge\[bot\]"; then
100
+ GH_CONFIG_DIR="$STAGE" gh auth logout -h github.com -u "rapiercraft-forge[bot]" 2>/dev/null || true
101
+ fi
102
+
103
+ if [[ ! -f "$STAGE/hosts.yml" ]]; then
104
+ echo "ERROR: gh auth login wrote no hosts.yml" >&2
105
+ exit 1
106
+ fi
107
+ mv -f "$STAGE/hosts.yml" "$GH_CFG/hosts.yml"
108
+
109
+ # #4662: record the refresh so `forgedock doctor` can report the token's lifetime (installation tokens last 1h).
110
+ STAMP_DIR="${FORGE_HOME_DIR:-$HOME/.forge}"
111
+ if mkdir -p "$STAMP_DIR" 2>/dev/null; then
112
+ _now=$(date +%s)
113
+ printf '{"refreshedAt":"%s","expiresAt":"%s"}\n' "$(date -u -d "@$_now" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -r "$_now" +%Y-%m-%dT%H:%M:%SZ)" \
114
+ "$(date -u -d "@$((_now + 3600))" +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -r "$((_now + 3600))" +%Y-%m-%dT%H:%M:%SZ)" > "$STAMP_DIR/.bot-token.json.$$" \
115
+ && mv -f "$STAMP_DIR/.bot-token.json.$$" "$STAMP_DIR/bot-token.json" || rm -f "$STAMP_DIR/.bot-token.json.$$"
116
+ fi
117
+
118
+ if [[ "$INSTALLATION_ID" == "$ORG_INSTALLATION_ID" ]]; then
119
+ echo "rapiercraft-forgedock[bot] token refreshed — org (RapierCraftStudios) ~1h"
120
+ else
121
+ echo "rapiercraft-forgedock[bot] token refreshed — personal (RapierCraft) ~1h"
122
+ fi
@@ -31,7 +31,10 @@
31
31
  # - Checkpoint = newest full 40/64-hex `Reviewed-SHA:` on a trusted, complete-shape FORGE:REVIEW-AGENT body that
32
32
  # also has a post-panel-guard proof (a synthesized body naming the SHA, or a `# PR Review Summary` whose
33
33
  # **Reviewed commit** is the SHA and whose **Agents** count equals the distinct domains that posted). The
34
- # FORGE:REVIEW_ROUTE sha= value is 7 chars and is never a checkpoint. A trusted review-panel-integrity gate
34
+ # A head whose panel never reached Phase 7 (no synthesized body or summary, e.g. a fix commit pushed mid-review) is
35
+ # also proven when the nearest trusted FORGE:REVIEW_TIER comment before its first agent body lists a roster
36
+ # (`Roster: a b c.`) and every listed domain posted a complete-shape agent body at that SHA (forge#4771).
37
+ # The FORGE:REVIEW_ROUTE sha= value is 7 chars and is never a checkpoint. A trusted review-panel-integrity gate
35
38
  # failure / REVIEW_DEGRADED / REVIEW_BLOCKED marker posted after a SHA's first agent body disqualifies it.
36
39
  # - FULL also when forge.yaml, the review specs, this script, the trust script, the phase-trail gate, the review
37
40
  # protocol doc or the finding classifier changed in reviewed..head.
@@ -93,7 +96,7 @@ fi
93
96
  case ",${LABELS}," in *,review-degraded,*) full ;; esac
94
97
 
95
98
  # ---- checkpoint: newest SHA with a trusted, complete, proven panel ---------------------------------------------
96
- RE='^(?=[\s\S]*<!-- REVIEW-FINDINGS-START -->)<!-- FORGE:REVIEW-AGENT:[a-z-]+ -->|^<!-- REVIEW-FINDINGS-SYNTHESIZED-START -->|# PR Review Summary|<!-- FORGE:GATE_FAILURE:TYPE=review-panel-integrity|<!-- FORGE:REVIEW_DEGRADED|<!-- FORGE:REVIEW_BLOCKED'
99
+ RE='^(?=[\s\S]*<!-- REVIEW-FINDINGS-START -->)<!-- FORGE:REVIEW-AGENT:[a-z-]+ -->|^<!-- REVIEW-FINDINGS-SYNTHESIZED-START -->|# PR Review Summary|<!-- FORGE:GATE_FAILURE:TYPE=review-panel-integrity|<!-- FORGE:REVIEW_DEGRADED|<!-- FORGE:REVIEW_BLOCKED|^<!-- FORGE:REVIEW_TIER '
97
100
  BODIES=$(bash "$TRUSTED" bodies "$RE" 2>/dev/null <<< "$COMMENTS_JSON"); rc=$?
98
101
  [ "$rc" -eq 0 ] || full
99
102
 
@@ -120,12 +123,19 @@ JQ_PROG='
120
123
  | one(shas($t; "\\*\\*Agents\\*\\*: ([0-9]+)")) as $n
121
124
  | select($s != null and $n != null)
122
125
  | {i: $i, sha: $s, n: ($n | tonumber)} ]) as $SU
126
+ | ([ $E[] | .key as $i | .value as $t
127
+ | select($t | startswith("<!-- FORGE:REVIEW_TIER "))
128
+ | ([ $t | scan("Roster: ([a-z0-9][a-z0-9 -]*)\\.") | .[0] ] | last) as $r
129
+ | select($r != null)
130
+ | {i: $i, roster: ($r | split(" ") | map(select(length > 0)) | unique)} ]) as $TI
123
131
  | ([ $AG | group_by(.sha)[]
124
- | {sha: .[0].sha, first: (map(.i) | min), domains: (map(.d) | unique | length)}
132
+ | {sha: .[0].sha, first: (map(.i) | min), domains: (map(.d) | unique | length), ds: (map(.d) | unique)}
125
133
  | . as $g
126
134
  | select(
127
135
  (($SY | map(select(.sha == $g.sha)) | length) > 0
128
- or ($SU | map(select(.sha == $g.sha and .n == $g.domains)) | length) > 0)
136
+ or ($SU | map(select(.sha == $g.sha and .n == $g.domains)) | length) > 0
137
+ or (($TI | map(select(.i < $g.first)) | last) as $t
138
+ | $t != null and ($t.roster | length) > 0 and (($t.roster - $g.ds) | length) == 0))
129
139
  and (($DEG | map(select(. > $g.first)) | length) == 0))
130
140
  | . + {last: ([ ($AG[] | select(.sha == $g.sha) | .i), ($SY[] | select(.sha == $g.sha) | .i),
131
141
  ($SU[] | select(.sha == $g.sha) | .i) ] | max)} ]) as $OK
@@ -42,6 +42,7 @@ base_advance() { # file content -> new commit on origin/main, fetched
42
42
  body_agent() { printf '<!-- FORGE:REVIEW-AGENT:%s -->\nReviewed-SHA: %s\n\n<!-- REVIEW-FINDINGS-START -->\nNo findings.\n<!-- REVIEW-FINDINGS-END -->' "$1" "$2"; }
43
43
  body_synth() { printf '<!-- REVIEW-FINDINGS-SYNTHESIZED-START -->\nReviewed-SHA: %s\n\nsynth' "$1"; }
44
44
  body_summary() { printf '# PR Review Summary\n\n**Reviewed commit**: `%s` | **Current HEAD**: `%s` | **Status**: CURRENT\n**Domains**: x | **Agents**: %s (x)\n' "$1" "$1" "$2"; }
45
+ body_tier() { printf '<!-- FORGE:REVIEW_TIER tier=standard spec=review-pr.md -->\nReviewer roster tier `standard`: 2 domains. Roster: %s.' "$1"; }
45
46
  cm() { jq -n --arg b "$1" --arg t "${2:-Bot}" --arg a "${3:-NONE}" '{"body":$b,"author_association":$a,"user":{"type":$t,"login":"x"}}'; }
46
47
  # comments <comment-json>... -> JSON array file path in $CF
47
48
  comments() { CF="$TMP/c$CASE.json"; printf '%s\n' "$@" | jq -s '.' > "$CF"; }
@@ -175,6 +176,26 @@ expect "review-degraded label" "FULL" 0 --labels "needs-human,review-degraded"
175
176
  out=$(cd "$W" && bash "$RD" --pr 1 --head "$HEAD" --base main --trusted-script "$TC" --comments-file "$CF" --labels "bug,docs" 2>&1 | sed -n 1p)
176
177
  [ "$out" = "DELTA $R..$HEAD" ] && ok || bad "unrelated labels must not force FULL (got $out)"
177
178
 
179
+ # 8b. forge#4771: a complete panel with no Phase 7 artefact (a fix commit pushed mid-review) is proven by the tier roster
180
+ mkrepo; R=$(sha HEAD); commit pr.txt "pr2" "pr2"; HEAD=$(sha HEAD)
181
+ comments "$(cm "$(body_tier "security api")" User MEMBER)" "$(cm "$(body_agent security "$R")" User MEMBER)" "$(cm "$(body_agent api "$R")" User MEMBER)"
182
+ expect "complete roster panel, no synthesis" "DELTA $R..$HEAD" 1
183
+ comments "$(cm "$(body_tier "security api")")" "$(cm "$(body_agent security "$R")")"
184
+ expect "roster domain missing" "FULL" 0
185
+ comments "$(cm "$(body_agent security "$R")")" "$(cm "$(body_agent api "$R")")"
186
+ expect "no tier comment" "FULL" 0
187
+ comments "$(cm "$(body_tier "security api")" User NONE)" "$(cm "$(body_agent security "$R")")" "$(cm "$(body_agent api "$R")")"
188
+ expect "untrusted tier comment" "FULL" 0
189
+ comments "$(cm "$(body_agent security "$R")")" "$(cm "$(body_agent api "$R")")" "$(cm "$(body_tier "security api")")"
190
+ expect "tier comment after the agents" "FULL" 0
191
+ comments "$(cm "<!-- FORGE:REVIEW_TIER tier=standard spec=review-pr.md -->
192
+ Roster: none (carried or full union, see context).")" "$(cm "$(body_agent security "$R")")"
193
+ expect "tier comment without a roster" "FULL" 0
194
+ comments "$(cm "$(body_tier "security api")")" "$(cm "$(body_agent security "$R")")" "$(cm "$(body_agent api "$R")")" "$(cm "<!-- FORGE:REVIEW_DEGRADED -->")"
195
+ expect "degraded marker after roster panel" "FULL" 0
196
+ comments "$(cm "$(body_tier "security api")")" "$(cm "$(body_agent security "$R")")" "$(cm "$(body_agent api "$R")")"
197
+ expect "review-degraded label with roster panel" "FULL" 0 --labels "review-degraded"
198
+
178
199
  # 9. FULL_ROUNDS
179
200
  mkrepo; R1=$(sha HEAD); commit pr.txt "pr2" "pr2"; R2=$(sha HEAD); commit pr.txt "pr3" "pr3"; HEAD=$(sha HEAD)
180
201
  comments "$(cm "$(body_agent security "$R1")")" "$(cm "$(body_synth "$R1")")" \
@@ -53,7 +53,8 @@
53
53
  # [--intensity-tier T] [--table-cell-key K] [--trust-shadow-mode B] [--other-blocking true|false] [--out-dir D] [--dry-run]
54
54
  # (--other-blocking: the reviewer's criterion 1/2/3/5 result; resolved and persisted to OUT_DIR/other-blocking.txt, which merge-gate ORs in)
55
55
  # calibrate: [--intensity-tier T] [--table-cell-key K] [--trust-shadow-mode B] [--trust-needs-human B] [--dry-run]; the issue is context contract.issue or --issue N
56
- # merge-gate: --verdict "APPROVED|CHANGES REQUESTED" --has-purpose-regression B --calibration-needs-human B --trust-needs-human B
56
+ # merge-gate: [--manual-pr [--owner-requested]] (hand-built PR: skips ONLY the phase-trail preflight, recorded as FORGE:PHASE_TRAIL_SKIPPED; refused for a pipeline issue, see manual_pr_eligibility)
57
+ # --verdict "APPROVED|CHANGES REQUESTED" --has-purpose-regression B --calibration-needs-human B --trust-needs-human B
57
58
  # --base-conflict B --other-blocking B [--calibration-note-file F | --calibration-note T] [--table-cell-key K] [--base B] [--issue N]
58
59
  # (every B is true|false; an empty or other value aborts the merge: the guard state must be bound)
59
60
  # Free text (purpose findings, agents, calibration note) derives from PR content: pass it through the *-file flags (a file written with the
@@ -83,7 +84,7 @@ PR_NUMBER=""; REPO=""; CONTEXT=""; OUT_DIR=""; IN_FILE=""; OUT_FILE=""; AUTO_MER
83
84
  REVIEW_SHA_OPT=""; REVIEW_MODE_OPT=""; BASE_OPT=""; HEAD_BRANCH=""; ISSUE_OPT=""; VERDICT=""; HAS_PURPOSE_REGRESSION=""; CALIBRATION_NEEDS_HUMAN=""; CALIBRATION_NOTE=""; TRUST_NEEDS_HUMAN=""
84
85
  BASE_CONFLICT=""; OTHER_BLOCKING=""; INTENSITY_TIER=""; TABLE_CELL_KEY=""; TRUST_SHADOW_MODE=""; MERGE_HEALTH=""; MERGE_HEALTH_STATE=""; RESULT=""
85
86
  AGENTS_TEXT=""; FINDINGS_COUNT=""; BLOCKING_COUNT=""; PURPOSE_FINDINGS=""; IS_MILESTONE="false"; MERGE_STATE_IN=""
86
- CALIBRATION_NOTE_FILE=""; AGENTS_FILE=""; PURPOSE_FINDINGS_FILE=""
87
+ CALIBRATION_NOTE_FILE=""; AGENTS_FILE=""; PURPOSE_FINDINGS_FILE=""; MANUAL_PR="false"; OWNER_REQUESTED="false"
87
88
  while [ $# -gt 0 ]; do
88
89
  case "$1" in
89
90
  --pr|--repo|--context|--out-dir|--findings|--out|--auto-merge|--notes-fixed|--notes-dropped|--patterns|--base|--head-branch|--issue|--verdict|--has-purpose-regression|--calibration-needs-human|--calibration-note|--calibration-note-file|--agents-file|--purpose-findings-file|--trust-needs-human|--base-conflict|--other-blocking|--intensity-tier|--table-cell-key|--trust-shadow-mode|--merge-health|--merge-health-state|--result|--agents|--findings-count|--blocking-count|--purpose-findings|--is-milestone|--merge-state|--review-sha|--review-mode|--scope-files|--prior-prs)
@@ -130,6 +131,8 @@ while [ $# -gt 0 ]; do
130
131
  --scope-files) SCOPE_FILES="${2:-}"; shift 2 ;;
131
132
  --prior-prs) PRIOR_PRS="${2:-}"; BUNDLE="true"; shift 2 ;;
132
133
  --dry-run) DRY_RUN="true"; shift ;;
134
+ --manual-pr) MANUAL_PR="true"; shift ;;
135
+ --owner-requested) OWNER_REQUESTED="true"; shift ;;
133
136
  *) echo "review-finalize: unknown argument: $1" >&2; exit 2 ;;
134
137
  esac
135
138
  done
@@ -1259,6 +1262,36 @@ do_calibrate() {
1259
1262
  # ======================================================================================================================
1260
1263
  # Every refusal prints the REVIEW_RESULT line and exits 3 (4 for PHASE_TRAIL_FAILED, which carries the MISSING lines). A parked or
1261
1264
  # routed outcome (base-conflict, awaiting-merge) is reported through MERGE_OUTCOME. Nothing below a failed gate ever runs.
1265
+ # A hand-built PR has no pipeline issue: gate notices and labels go to the PR itself (--manual-pr only; MERGE_ISSUE is otherwise always set).
1266
+ gate_comment() {
1267
+ if [ -n "${MERGE_ISSUE:-}" ]; then gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "$1"; else gh pr comment "$PR_NUMBER" -R "$REPO" --body "$1"; fi # allowlist:check-command-side-effects
1268
+ }
1269
+ gate_label() {
1270
+ if [ -n "${MERGE_ISSUE:-}" ]; then gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "$1"; else gh pr edit "$PR_NUMBER" -R "$REPO" --add-label "$1"; fi # allowlist:check-command-side-effects
1271
+ }
1272
+ # is_pipeline_issue N: 0 when N is a /work-on or /orchestrate issue (a workflow:* label, or a FORGE:STATE / FORGE:STARTED marker); an unreadable issue counts as one (fail closed).
1273
+ is_pipeline_issue() {
1274
+ local v
1275
+ v=$(gh issue view "$1" -R "$REPO" --json body,comments,labels \
1276
+ --jq '([.labels[].name | startswith("workflow:")] + [.body | contains("<!-- FORGE:STATE")] + [.comments[].body | contains("FORGE:STARTED") or contains("<!-- FORGE:STATE")]) | any' 2>/dev/null) || return 0
1277
+ [ "$v" != "false" ]
1278
+ }
1279
+ # manual_pr_eligibility: --manual-pr never applies to a pipeline lane. An explicit --issue that is a pipeline issue is always refused;
1280
+ # a closing reference to one is refused unless the caller passed --owner-requested. Any unreadable lookup refuses.
1281
+ manual_pr_eligibility() {
1282
+ local refs n
1283
+ if [ -n "${MERGE_ISSUE:-}" ] && is_pipeline_issue "$MERGE_ISSUE"; then
1284
+ echo "MANUAL PR: #${MERGE_ISSUE} is a pipeline issue — --manual-pr never applies to a /work-on or /orchestrate lane" >&2
1285
+ blocked "manual-pr refused: #${MERGE_ISSUE} is a pipeline issue"
1286
+ fi
1287
+ refs=$(gh pr view "$PR_NUMBER" -R "$REPO" --json closingIssuesReferences --jq '.closingIssuesReferences[].number' 2>/dev/null) || blocked "manual-pr refused: closing references unreadable"
1288
+ for n in $refs; do
1289
+ if is_pipeline_issue "$n" && [ "$OWNER_REQUESTED" != "true" ]; then
1290
+ echo "MANUAL PR: the PR closes pipeline issue #${n}; pass --owner-requested only when the owner explicitly asked for this merge" >&2
1291
+ blocked "manual-pr refused: PR closes pipeline issue #${n}"
1292
+ fi
1293
+ done
1294
+ }
1262
1295
  do_merge_gate() {
1263
1296
  BASE="${BASE_OPT:-$CTX_BASE_BRANCH}"
1264
1297
  # --- note-disposition preflight: fail closed on an unreadable comment list ---
@@ -1300,7 +1333,13 @@ do_merge_gate() {
1300
1333
  fi
1301
1334
 
1302
1335
  # --- phase-trail preflight: a reviewer verdict alone must not merge work whose earlier phases were skipped ---
1303
- if [ -z "${MERGE_ISSUE:-}" ]; then
1336
+ if [ "$MANUAL_PR" = "true" ]; then
1337
+ manual_pr_eligibility
1338
+ gate_comment "<!-- FORGE:PHASE_TRAIL_SKIPPED -->
1339
+ Phase-trail preflight skipped for PR #${PR_NUMBER}: manual-PR mode (hand-built PR${MERGE_ISSUE:+, linked #${MERGE_ISSUE}}; owner-requested=${OWNER_REQUESTED}). Every other merge gate still runs." 2>/dev/null || true
1340
+ TRAIL_RC=0; TRAIL_SKIPPED=true
1341
+ fi
1342
+ if [ "${TRAIL_SKIPPED:-false}" != "true" ] && [ -z "${MERGE_ISSUE:-}" ]; then
1304
1343
  echo "PHASE TRAIL: auto-merge requested without --issue — the issue is never inferred from PR-author-controlled text, so the phase trail cannot be verified; refusing to merge (fail closed)" >&2
1305
1344
  gh pr comment "$PR_NUMBER" -R "$REPO" --body "Auto-merge skipped: no --issue was given, so the phase trail cannot be verified. Re-run \`/review-pr ${PR_NUMBER} --auto-merge --issue <N>\` or merge manually." 2>/dev/null || true # allowlist:check-command-side-effects
1306
1345
  # Not a PHASE_TRAIL_FAILED (nothing to re-run).
@@ -1319,7 +1358,9 @@ do_merge_gate() {
1319
1358
  CODE_DIFF_FLAG="--code-diff"
1320
1359
  if [ -n "$DOCS_ONLY_FLAG" ]; then CODE_DIFF_FLAG=""; fi
1321
1360
  OVERRIDE_BOUND_HEAD=""
1322
- if [ -z "$TRAIL_SCRIPT" ]; then
1361
+ if [ "${TRAIL_SKIPPED:-false}" = "true" ]; then
1362
+ : # manual PR: preflight skipped and recorded above
1363
+ elif [ -z "$TRAIL_SCRIPT" ]; then
1323
1364
  # Fail closed: an unresolvable verifier is NOT a pass (never fall back to the consumer repo).
1324
1365
  echo "PHASE TRAIL: verify-phase-trail.sh not resolvable (set FORGEDOCK_HOME to the ForgeDock install) — refusing to merge" >&2
1325
1366
  TRAIL="PHASE_TRAIL: ERROR (verifier not resolvable)"; TRAIL_RC=127
@@ -1348,9 +1389,9 @@ ${TRAIL}
1348
1389
  \`\`\`
1349
1390
 
1350
1391
  Fix the cause (gh auth/API outage, \`FORGE_TRAIL_QG_SINCE\`/runner clock, or set \`FORGEDOCK_HOME\` when the verifier is unresolvable), then re-run /review-pr."
1351
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "$TRAIL_ERR_BODY" # <!-- allowlist:check-command-side-effects -->
1392
+ gate_comment "$TRAIL_ERR_BODY" # <!-- allowlist:check-command-side-effects -->
1352
1393
  # Nothing can resume this automatically, so park it for a human instead of leaving workflow:in-review.
1353
- gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "needs-human" 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1394
+ gate_label "needs-human" 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1354
1395
  # The PR stays open and unmerged; callers must NOT fall back to a manual merge.
1355
1396
  blocked "phase trail unreadable (rc=${TRAIL_RC})"
1356
1397
  elif [ "$TRAIL_RC" -ne 0 ]; then
@@ -1362,7 +1403,7 @@ ${TRAIL}
1362
1403
  \`\`\`
1363
1404
 
1364
1405
  Re-run each missing phase via its Skill (see the \`->\` action on each MISSING line), then re-run /review-pr."
1365
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "$TRAIL_FAIL_BODY" # <!-- allowlist:check-command-side-effects -->
1406
+ gate_comment "$TRAIL_FAIL_BODY" # <!-- allowlist:check-command-side-effects -->
1366
1407
  # rc 1 only; the work-on review phase (work-on/review.md R4) is the single owner of re-dispatching the named phases. Not an immediate needs-human escalation.
1367
1408
  echo "REVIEW_RESULT: status: PHASE_TRAIL_FAILED"
1368
1409
  printf '%s\n' "$TRAIL"
@@ -1375,6 +1416,7 @@ Re-run each missing phase via its Skill (see the \`->\` action on each MISSING l
1375
1416
  # issue name the degraded checks. Each one must be named in a trusted `### Degraded Paths Reviewed` section on the PR; a generic section
1376
1417
  # does not satisfy it. Unreadable comments fail closed. Only trusted-comments.sh ever reads these comments, so an untrusted comment can
1377
1418
  # neither forge a DEGRADED marker nor clear one.
1419
+ if [ -n "${MERGE_ISSUE:-}" ]; then # a hand-built PR has no issue gate comments to read
1378
1420
  DEG_ISSUE_JSON=$(gh api --paginate "repos/${REPO}/issues/${MERGE_ISSUE}/comments" 2>/dev/null) || DEG_ISSUE_JSON=""
1379
1421
  if [ -z "$DEG_ISSUE_JSON" ] || [ -z "$TRUSTED_SCRIPT" ]; then
1380
1422
  echo "DEGRADED GATE: issue comments or trusted-comments.sh unreadable — refusing to merge (fail closed)" >&2
@@ -1441,14 +1483,15 @@ Re-run each missing phase via its Skill (see the \`->\` action on each MISSING l
1441
1483
  fi
1442
1484
  if [ -n "$DEG_MISSING" ]; then
1443
1485
  echo "DEGRADED GATE: the build's gate is DEGRADED (${DEG_NAMES}) and the review does not cover it (${DEG_MISSING})" >&2
1444
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "<!-- FORGE:DEGRADED_GATE_UNREVIEWED -->
1486
+ gate_comment "<!-- FORGE:DEGRADED_GATE_UNREVIEWED -->
1445
1487
  Auto-merge refused for PR #${PR_NUMBER}: the build's verification was DEGRADED (a check ran nothing or did not complete): ${DEG_NAMES}.
1446
1488
 
1447
1489
  The review must add a \`### Degraded Paths Reviewed\` section that names each degraded check and states how its path was reviewed (${DEG_MISSING}). Then re-run /review-pr." 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1448
- gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "needs-human" 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1490
+ gate_label "needs-human" 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1449
1491
  blocked "degraded-gate-unreviewed"
1450
1492
  fi
1451
1493
  fi
1494
+ fi
1452
1495
 
1453
1496
  # --- merge guard state: §7B verdict + purpose-regression + calibration + trust-escalation ---
1454
1497
  # These are decided in earlier steps (earlier shells), so they arrive as flags. An empty or unbound value would read as
@@ -1460,8 +1503,8 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1460
1503
  case "$_guard_val" in true|false) ;; *) GUARD_STATE_OK=false ;; esac
1461
1504
  done
1462
1505
  if [ "$GUARD_STATE_OK" != "true" ]; then
1463
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "⛔ Auto-merge aborted for PR #${PR_NUMBER}: the Phase 8 merge guard state is unbound (VERDICT='${VERDICT}', HAS_PURPOSE_REGRESSION='${HAS_PURPOSE_REGRESSION}', CALIBRATION_NEEDS_HUMAN='${CALIBRATION_NEEDS_HUMAN}', TRUST_NEEDS_HUMAN='${TRUST_NEEDS_HUMAN}', BASE_CONFLICT='${BASE_CONFLICT}', OTHER_BLOCKING='${OTHER_BLOCKING}'). Not merging; re-run /review-pr." # <!-- allowlist:check-command-side-effects -->
1464
- gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "needs-human" 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1506
+ gate_comment "⛔ Auto-merge aborted for PR #${PR_NUMBER}: the Phase 8 merge guard state is unbound (VERDICT='${VERDICT}', HAS_PURPOSE_REGRESSION='${HAS_PURPOSE_REGRESSION}', CALIBRATION_NEEDS_HUMAN='${CALIBRATION_NEEDS_HUMAN}', TRUST_NEEDS_HUMAN='${TRUST_NEEDS_HUMAN}', BASE_CONFLICT='${BASE_CONFLICT}', OTHER_BLOCKING='${OTHER_BLOCKING}'). Not merging; re-run /review-pr." # <!-- allowlist:check-command-side-effects -->
1507
+ gate_label "needs-human" 2>/dev/null || true # <!-- allowlist:check-command-side-effects -->
1465
1508
  blocked "merge guard state unbound"
1466
1509
  fi
1467
1510
  # OR in the value `verdict` persisted: a passed `false` never overrides a persisted `true`. Anything else in the file is ignored.
@@ -1473,7 +1516,7 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1473
1516
  fi
1474
1517
  if [ "$ONLY_BASE_CONFLICT" = "true" ] && [ "$VERDICT" = "CHANGES REQUESTED" ]; then
1475
1518
  # Pure base conflict: route to the base-sync path, NOT needs-human. A standalone /review-pr caller just sees the blocker.
1476
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "⛔ Auto-merge aborted for PR #${PR_NUMBER}: base conflict with \`${BASE}\` (the only blocking reason). Base sync needed: the work-on pipeline performs the base sync (merging \`origin/${BASE}\` into the PR branch, merge only, no rebase, no force-push); a standalone \`/review-pr --auto-merge\` caller with no work-on router must run \`/work-on ${MERGE_ISSUE} --remediate\` to do it. The sync re-runs the quality gate and then re-reviews the new head. A human is pulled in only if the conflict cannot be resolved automatically." # <!-- allowlist:check-command-side-effects -->
1519
+ gate_comment "⛔ Auto-merge aborted for PR #${PR_NUMBER}: base conflict with \`${BASE}\` (the only blocking reason). Base sync needed: the work-on pipeline performs the base sync (merging \`origin/${BASE}\` into the PR branch, merge only, no rebase, no force-push); a standalone \`/review-pr --auto-merge\` caller with no work-on router must run \`/work-on ${MERGE_ISSUE} --remediate\` to do it. The sync re-runs the quality gate and then re-reviews the new head. A human is pulled in only if the conflict cannot be resolved automatically." # <!-- allowlist:check-command-side-effects -->
1477
1520
  echo "MERGE_OUTCOME=base-conflict"
1478
1521
  blocked "base-conflict"
1479
1522
  elif [ "$VERDICT" = "CHANGES REQUESTED" ] || [ "$HAS_PURPOSE_REGRESSION" = "true" ] || [ "$CALIBRATION_NEEDS_HUMAN" = "true" ] || [ "$TRUST_NEEDS_HUMAN" = "true" ]; then
@@ -1482,8 +1525,8 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1482
1525
  [ "$HAS_PURPOSE_REGRESSION" = "true" ] && BLOCK_REASON="${BLOCK_REASON:+${BLOCK_REASON}; }purpose regression detected by Phase 7A (\`HAS_PURPOSE_REGRESSION=true\`)"
1483
1526
  [ "$CALIBRATION_NEEDS_HUMAN" = "true" ] && BLOCK_REASON="${BLOCK_REASON:+${BLOCK_REASON}; }calibration threshold: ${CALIBRATION_NOTE}"
1484
1527
  [ "$TRUST_NEEDS_HUMAN" = "true" ] && BLOCK_REASON="${BLOCK_REASON:+${BLOCK_REASON}; }provenance trust: NOVEL_NEEDS_HUMAN tier for cell \`${TABLE_CELL_KEY}\` — no sufficient prior data (forge#1745)"
1485
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "⛔ Auto-merge aborted for PR #${PR_NUMBER}: ${BLOCK_REASON}. Manual review required before merging."
1486
- gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "needs-human" 2>/dev/null || true
1528
+ gate_comment "⛔ Auto-merge aborted for PR #${PR_NUMBER}: ${BLOCK_REASON}. Manual review required before merging."
1529
+ gate_label "needs-human" 2>/dev/null || true
1487
1530
  echo "MERGE_OUTCOME=needs-human"
1488
1531
  blocked "auto-merge blocked: ${BLOCK_REASON}"
1489
1532
  fi
@@ -1501,19 +1544,20 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1501
1544
  fi
1502
1545
  if [ "$PRE_MERGE_BASE_CONFLICT" = "true" ]; then
1503
1546
  # Base moved during review: route to the base-sync path, NOT needs-human.
1504
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "⛔ Auto-merge aborted for PR #${PR_NUMBER}: base conflict (\`mergeable=${PRE_MERGE_HEALTH}\`, \`mergeStateStatus=${PRE_MERGE_HEALTH_STATE}\`). Base sync needed: the work-on pipeline performs the base sync (merging \`origin/${BASE}\` into the PR branch, merge only, no rebase, no force-push); a standalone \`/review-pr --auto-merge\` caller with no work-on router must run \`/work-on ${MERGE_ISSUE} --remediate\` to do it. The sync is followed by a re-review. A human is pulled in only if the conflict cannot be resolved automatically." # <!-- allowlist:check-command-side-effects -->
1547
+ gate_comment "⛔ Auto-merge aborted for PR #${PR_NUMBER}: base conflict (\`mergeable=${PRE_MERGE_HEALTH}\`, \`mergeStateStatus=${PRE_MERGE_HEALTH_STATE}\`). Base sync needed: the work-on pipeline performs the base sync (merging \`origin/${BASE}\` into the PR branch, merge only, no rebase, no force-push); a standalone \`/review-pr --auto-merge\` caller with no work-on router must run \`/work-on ${MERGE_ISSUE} --remediate\` to do it. The sync is followed by a re-review. A human is pulled in only if the conflict cannot be resolved automatically." # <!-- allowlist:check-command-side-effects -->
1505
1548
  echo "MERGE_OUTCOME=base-conflict"
1506
1549
  blocked "base-conflict"
1507
1550
  elif [ "$PRE_MERGE_HEALTH_STATE" = "BLOCKED" ]; then
1508
1551
  # Branch protection not satisfied: syncing the base cannot clear it, so this is NOT a base-conflict blocker.
1509
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "⛔ Auto-merge aborted for PR #${PR_NUMBER}: branch protection is not satisfied (\`mergeStateStatus=BLOCKED\`); syncing the base cannot clear it. Satisfy the required review/checks, then re-run /review-pr."
1510
- gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "needs-human" 2>/dev/null || true
1552
+ gate_comment "⛔ Auto-merge aborted for PR #${PR_NUMBER}: branch protection is not satisfied (\`mergeStateStatus=BLOCKED\`); syncing the base cannot clear it. Satisfy the required review/checks, then re-run /review-pr."
1553
+ gate_label "needs-human" 2>/dev/null || true
1511
1554
  echo "MERGE_OUTCOME=protection-blocked"
1512
1555
  blocked "branch protection not satisfied"
1513
1556
  fi
1514
1557
 
1515
1558
  # --- previously-escalated re-review guard (base-scoped): park at awaiting-merge, never merge here ---
1516
- PREVIOUSLY_ESCALATED=$(gh issue view "$MERGE_ISSUE" -R "$REPO" --json labels,comments \
1559
+ PREVIOUSLY_ESCALATED=false
1560
+ [ -z "${MERGE_ISSUE:-}" ] || PREVIOUSLY_ESCALATED=$(gh issue view "$MERGE_ISSUE" -R "$REPO" --json labels,comments \
1517
1561
  --jq '([.labels[].name | . == "needs-human" or . == "workflow:remediating"] + [.comments[].body | contains("FORGE:REMEDIATION")]) | any' 2>/dev/null || echo "false")
1518
1562
  GUARD_BASE=$(gh pr view "$PR_NUMBER" -R "$REPO" --json baseRefName --jq '.baseRefName' 2>/dev/null || echo "")
1519
1563
  if [ "$PREVIOUSLY_ESCALATED" = "true" ]; then
@@ -1521,9 +1565,9 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1521
1565
  GATE_SCRIPT=$(forge_resolve resolve-deploy-gate.sh)
1522
1566
  if [ -n "$GATE_SCRIPT" ]; then GUARD_GATE=$(bash "$GATE_SCRIPT" "$GUARD_BASE" "$REPO" 2>/dev/null || echo true); else GUARD_GATE=true; fi; [ "$GUARD_GATE" = "false" ] || GUARD_GATE=true
1523
1567
  if [ "$GUARD_GATE" = "false" ]; then
1524
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "🟠 PR #${PR_NUMBER} was previously escalated (\`needs-human\`) and has now been re-reviewed to \`${VERDICT:-APPROVED}\` with a clean mergeability check on non-default-branch base \`${GUARD_BASE}\`. It is parked at \`workflow:awaiting-merge\` for the remediation auto-land bar (\`remediate.md\` Phase M7, forge#2570) — which auto-merges it on the same fast-lane condition the normal \`/work-on\` path uses for this target branch — NOT for a human merge decision. If no remediation \`M7\` follows (e.g. this review was invoked standalone), merge manually once reviewed: \`gh pr merge ${PR_NUMBER} -R ${REPO} --merge\`."
1568
+ gate_comment "🟠 PR #${PR_NUMBER} was previously escalated (\`needs-human\`) and has now been re-reviewed to \`${VERDICT:-APPROVED}\` with a clean mergeability check on non-default-branch base \`${GUARD_BASE}\`. It is parked at \`workflow:awaiting-merge\` for the remediation auto-land bar (\`remediate.md\` Phase M7, forge#2570) — which auto-merges it on the same fast-lane condition the normal \`/work-on\` path uses for this target branch — NOT for a human merge decision. If no remediation \`M7\` follows (e.g. this review was invoked standalone), merge manually once reviewed: \`gh pr merge ${PR_NUMBER} -R ${REPO} --merge\`."
1525
1569
  else
1526
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "🟠 PR #${PR_NUMBER} was previously escalated (\`needs-human\`) and has now been re-reviewed to \`${VERDICT:-APPROVED}\` with a clean mergeability check. This PR targets the deploy gate (\`${GUARD_BASE:-unresolved base}\`), so it is held at \`workflow:awaiting-merge\` for a human merge decision — \`staging → main\` is the genuine human gate. Merge manually once reviewed: \`gh pr merge ${PR_NUMBER} -R ${REPO} --merge\`."
1570
+ gate_comment "🟠 PR #${PR_NUMBER} was previously escalated (\`needs-human\`) and has now been re-reviewed to \`${VERDICT:-APPROVED}\` with a clean mergeability check. This PR targets the deploy gate (\`${GUARD_BASE:-unresolved base}\`), so it is held at \`workflow:awaiting-merge\` for a human merge decision — \`staging → main\` is the genuine human gate. Merge manually once reviewed: \`gh pr merge ${PR_NUMBER} -R ${REPO} --merge\`."
1527
1571
  fi
1528
1572
  # transition-label.sh: install roots only. Unresolvable falls through to the prose label edit so the transition is never silently skipped.
1529
1573
  TRANSITION_SCRIPT=$(forge_resolve transition-label.sh)
@@ -1582,7 +1626,7 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1582
1626
  # TIMEOUT = checks still pending, not failing (wait-ci-green.sh rc=3). Not a human problem: no needs-human label,
1583
1627
  # so the documented re-run (or engine retry) merges once CI is green instead of parking behind the
1584
1628
  # previously-escalated guard (#3919).
1585
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "⏳ Auto-merge deferred for PR #${PR_NUMBER}: CI checks still pending after the wait window (ci gate rc=3). Re-run the merge gate once they finish; nothing to fix." 2>/dev/null || true # allowlist:check-command-side-effects
1629
+ gate_comment "⏳ Auto-merge deferred for PR #${PR_NUMBER}: CI checks still pending after the wait window (ci gate rc=3). Re-run the merge gate once they finish; nothing to fix." 2>/dev/null || true # allowlist:check-command-side-effects
1586
1630
  echo "MERGE_OUTCOME=ci-pending"
1587
1631
  blocked "checks still pending after the wait window (timeout) — re-run the merge once CI finishes"
1588
1632
  elif [ "$CI_GATE_RC" -ne 0 ]; then
@@ -1590,18 +1634,18 @@ The review must add a \`### Degraded Paths Reviewed\` section that names each de
1590
1634
  \`\`\`
1591
1635
  ${CI_GATE_OUT}
1592
1636
  \`\`\`"
1593
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "$CI_MSG" 2>/dev/null || true # allowlist:check-command-side-effects
1594
- gh issue edit "$MERGE_ISSUE" -R "$REPO" --add-label "needs-human" 2>/dev/null || true # allowlist:check-command-side-effects
1637
+ gate_comment "$CI_MSG" 2>/dev/null || true # allowlist:check-command-side-effects
1638
+ gate_label "needs-human" 2>/dev/null || true # allowlist:check-command-side-effects
1595
1639
  echo "MERGE_OUTCOME=ci-not-green"
1596
1640
  blocked "ci gate not green (rc=${CI_GATE_RC})"
1597
1641
  fi
1598
1642
 
1599
1643
  # --- merge exactly the commit the CI gate (and the reviewed-head guard) checked ---
1600
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "Review complete for PR #${PR_NUMBER}. Verdict: ${VERDICT:-APPROVED}. CI green. Proceeding to merge."
1644
+ gate_comment "Review complete for PR #${PR_NUMBER}. Verdict: ${VERDICT:-APPROVED}. CI green. Proceeding to merge."
1601
1645
  gh pr merge "$PR_NUMBER" -R "$REPO" --merge --match-head-commit "$GATED_HEAD"
1602
1646
  MERGE_STATE=$(gh pr view "$PR_NUMBER" -R "$REPO" --json state --jq '.state')
1603
1647
  if [ "$MERGE_STATE" != "MERGED" ]; then
1604
- gh issue comment "$MERGE_ISSUE" -R "$REPO" --body "PR #${PR_NUMBER} merge failed. State: $MERGE_STATE."
1648
+ gate_comment "PR #${PR_NUMBER} merge failed. State: $MERGE_STATE."
1605
1649
  echo "MERGE_OUTCOME=merge-failed"
1606
1650
  else
1607
1651
  echo "MERGE_OUTCOME=merged"