Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bump: patch
---

### Changed

- The `pr-body-linkage-gate` and `pr-linkage-mcp-gate` hooks block a PR body only when it carries a negated closing reference (`does not close #N`), which GitHub still closes on merge. A body missing a closing line or a `## Summary`, `## Fix`, `## Verification` or `## Related` section now passes, matching CI, which reports those as advisory. An MCP `create_pull_request` with no body passes too. The `/source-control:pull-request create` pre-create section check is unchanged.
4 changes: 2 additions & 2 deletions docs/conventions/pr-body-convention/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ reading only the mechanism doc:

`/source-control:pull-request create`'s §2.4.2 pre-`gh pr create` gate checks, for every section in
the resolved `pr_body_required_sections` list, that a `## <heading>` section exists in the assembled
body **and** its content is non-empty. It judges the body with the same checker as the
`pr-body-linkage-gate.sh` hook, so the two cannot disagree on what a heading or content is. On failure it names the exact missing or empty section and the
body **and** its content is non-empty. It judges the body with the shared section checker in the
source-control plugin's `hooks/pr-linkage-validator.sh`, which defines what a heading or content is. On failure it names the exact missing or empty section and the
resolved config source (the winning layer's file path and the `pr_body_required_sections` key),
never a bare "PR body invalid", so the actor who never saw the convention learns where it lives on
first failure, not by asking someone.
Expand Down
4 changes: 2 additions & 2 deletions plugins/source-control/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
"pr_body_linkage_gate_enabled": {
"type": "boolean",
"title": "PR-body-linkage-gate hook",
"description": "Blocks a gh pr create or gh pr edit whose statically readable PR body would fail the repository's required PR-contract check: no closing keyword, or a missing or empty Summary, Fix, Verification, or Related section. On by default. A body the hook cannot read statically always passes.",
"description": "Blocks a gh pr create or gh pr edit whose statically readable PR body carries a negated closing reference (does not close #N), which GitHub still closes on merge. A missing closing line or section is advisory and passes. On by default. A body the hook cannot read statically always passes.",
Comment thread
kyle-sexton marked this conversation as resolved.
Resolved
"default": true
},
"pr_linkage_mcp_gate_enabled": {
"type": "boolean",
"title": "PR-linkage-MCP-gate hook",
"description": "Blocks a GitHub MCP create_pull_request or update_pull_request whose PR body would fail the repository's required PR-contract check, covering sessions that open PRs without the gh CLI. On by default. Enforced only for the repository the origin remote names.",
"description": "Blocks a GitHub MCP create_pull_request or update_pull_request whose PR body carries a negated closing reference, covering sessions that open PRs without the gh CLI. On by default. Enforced only for the repository the origin remote names.",
"default": true
},
"branch_issue_pattern": {
Expand Down
40 changes: 20 additions & 20 deletions plugins/source-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,12 @@ A mod can also approve a call they blocked, because its `tool.check` hook runs a
### `pr-body-linkage-gate`

A `PreToolUse` hook on the Bash tool. When a `gh pr create` / `gh pr edit`
carries a PR body the hook can read statically, it validates that body against
the same contract the repository's required PR-contract check enforces,
a closing keyword, a tracker's link line as `/work-items:track link` prints it
(`Closes ENG-123`, `Refs: SW2-12`), or an explicit no-linked-issue marker, plus four non-empty
contract sections (`## Summary`, `## Fix`, `## Verification`, `## Related`),
and blocks the call with every missing or empty requirement named, so the
failure surfaces before the PR exists rather than a CI round trip later.
carries a PR body the hook can read statically, it blocks the call only when
that body carries a negated closing reference (`does not close #N`), which
GitHub's parser still closes on merge, and names each one with the `Refs: #N`
line to use instead. The rest of the PR-contract check (a closing line and
non-empty `## Summary`, `## Fix`, `## Verification` and `## Related` sections)
is advisory in CI, so a body missing any of it passes.
`/source-control:pull-request create` already gates its own body; this covers
the calls that bypass the skill.

Expand Down Expand Up @@ -256,16 +255,16 @@ refused by the cloud GitHub proxy (see
[docs/cloud-sessions.md](../../docs/cloud-sessions.md#github-mcp-tools-vs-the-gh-cli)). It
covers both the `mcp__github__<tool>` names and the
`mcp__plugin_<plugin>_github__<tool>` names of a plugin-bundled server.
Same contract, same authority (a workflow in the consuming repository's own
`.github/workflows/` that `uses:` the `pr-contract` composite step), same
block-with-the-fix-named behavior. The MCP payload hands over the body as a plain JSON field, so the
It blocks only the same negated closing reference, under the same authority (a
workflow in the consuming repository's own `.github/workflows/` that `uses:` the
`pr-contract` composite step), with the same block message. The MCP payload hands over the body as a plain JSON field, so the
Bash sibling's static-readability caveats don't apply here; the scope guards
that remain are the workflow scan above, an origin-remote match on the call's
`owner`/`repo` (another repository's PR is not this repo's policy), and an
`update_pull_request` that carries no `body` field, which changes nothing CI
already validated and passes. A `create_pull_request` with no `body` at all
blocks. GitHub would open the PR with an empty body, which the CI check
rejects. Set `pr_linkage_mcp_gate_enabled` to `false` to turn it off.
is judged as an empty body and passes. Set `pr_linkage_mcp_gate_enabled` to
`false` to turn it off.

Telemetry matches the sibling's: one envelope per run (`ok`/`blocked`,
`duration_ms`, and the tool name as its only data label), only when
Expand Down Expand Up @@ -462,15 +461,16 @@ The plugin-scope finding-classification gate accepts extra posting identities vi

### Option details

**`pr_body_linkage_gate_enabled`.** The required sections are `## Summary`, `## Fix`,
`## Verification`, and `## Related`. Enforced only in a repository whose `.github/workflows` carry
a workflow that uses the `pr-contract` composite step.
**`pr_body_linkage_gate_enabled`.** Blocks only a negated closing reference. A missing closing
line or a missing or empty `## Summary`, `## Fix`, `## Verification` or `## Related` section
passes, since CI reports those as advisory. Enforced only in a repository whose
`.github/workflows` carry a workflow that uses the `pr-contract` composite step.

**`pr_linkage_mcp_gate_enabled`.** The MCP-surface sibling of `pr-body-linkage-gate`, covering
cloud and remote sessions that open PRs through MCP tools rather than `gh` (see
[docs/cloud-sessions.md](../../docs/cloud-sessions.md#github-mcp-tools-vs-the-gh-cli)). It checks the same closing keyword
and non-empty sections, with the same policy scope: enforced only in a repository whose
`.github/workflows` carry a workflow that uses the `pr-contract` composite step.
[docs/cloud-sessions.md](../../docs/cloud-sessions.md#github-mcp-tools-vs-the-gh-cli)). It blocks
the same negated closing reference, with the same policy scope: enforced only in a repository
whose `.github/workflows` carry a workflow that uses the `pr-contract` composite step.

**`branch_issue_pattern`.** The last capture group must resolve to digits (`Closes #N` honors only
a numeric issue). Set it for a non-default branch scheme that places the number differently, for
Expand Down Expand Up @@ -564,8 +564,8 @@ reads it from.

| Option | Type | Default | Environment variable | Description |
| --- | --- | --- | --- | --- |
| `pr_body_linkage_gate_enabled` | boolean | `true` | `CLAUDE_PLUGIN_OPTION_PR_BODY_LINKAGE_GATE_ENABLED` | Blocks a gh pr create or gh pr edit whose statically readable PR body would fail the repository's required PR-contract check: no closing keyword, or a missing or empty Summary, Fix, Verification, or Related section. On by default. A body the hook cannot read statically always passes. |
| `pr_linkage_mcp_gate_enabled` | boolean | `true` | `CLAUDE_PLUGIN_OPTION_PR_LINKAGE_MCP_GATE_ENABLED` | Blocks a GitHub MCP create_pull_request or update_pull_request whose PR body would fail the repository's required PR-contract check, covering sessions that open PRs without the gh CLI. On by default. Enforced only for the repository the origin remote names. |
| `pr_body_linkage_gate_enabled` | boolean | `true` | `CLAUDE_PLUGIN_OPTION_PR_BODY_LINKAGE_GATE_ENABLED` | Blocks a gh pr create or gh pr edit whose statically readable PR body carries a negated closing reference (does not close #N), which GitHub still closes on merge. A missing closing line or section is advisory and passes. On by default. A body the hook cannot read statically always passes. |
| `pr_linkage_mcp_gate_enabled` | boolean | `true` | `CLAUDE_PLUGIN_OPTION_PR_LINKAGE_MCP_GATE_ENABLED` | Blocks a GitHub MCP create_pull_request or update_pull_request whose PR body carries a negated closing reference, covering sessions that open PRs without the gh CLI. On by default. Enforced only for the repository the origin remote names. |
| `branch_issue_pattern` | string | *(none)* | `CLAUDE_PLUGIN_OPTION_BRANCH_ISSUE_PATTERN` | Deprecated fallback: set branch_issue_pattern in .claude/source-control.md instead, which wins. A POSIX ERE whose last capture group extracts the numeric GitHub issue number from the branch name. Absent: the built-in <type>/<N>-<slug> (and routine-issue-<N>) convention. |
| `pr_open_state` | string | `"ready"` | `CLAUDE_PLUGIN_OPTION_PR_OPEN_STATE` | State /source-control:pull-request create leaves a PR in. ready (default) runs the ready action's gates and flips it; draft leaves it for ready to flip later. A repository's pr_open_state in docs/conventions/source-control.yaml wins over this value; a request for a draft wins over both. |
| `fetch_logs_max_bytes` | number<br>*min 1* | `52428800` | `CLAUDE_PLUGIN_OPTION_FETCH_LOGS_MAX_BYTES` | Aborts a CI-log ZIP fetch larger than this many bytes. Default 52428800 (50 MiB). |
Expand Down
48 changes: 19 additions & 29 deletions plugins/source-control/hooks/pr-body-linkage-gate.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
#!/usr/bin/env bash
# PreToolUse hook: block a bare `gh pr create` / `gh pr edit` whose PR BODY
# would fail the consuming repository's own PR-contract CI gate.
# carries a negated closing reference.
#
# WHY IT EXISTS — CI reports a body missing any of the five requirements with
# an advisory comment and label, one CI round trip after the PR is already
# open; nothing else checks the contract at authoring time. `/source-control:pull-request
# create` runs the equivalent pre-create gate (skills/pull-request/reference/
# create.md §2.4.2); this hook covers the calls that never go through the skill.
# WHY IT EXISTS — a negated closer (`does not close #N`) still closes the issue
# on merge, because GitHub's closing-keyword parser ignores the negation, and CI
# reports it only one round trip after the PR is already open. This hook covers
# the calls that never go through `/source-control:pull-request create`.
#
# WHAT IT ENFORCES — the five requirements of the linkage contract, mirrored.
# The semantics were ported from the reusable
# melodic-software/ci-workflows/.github/workflows/pr-issue-linkage.yml
# validator, which is RETIRED (deleted in ci-workflows#569, released as
# v0.23.0); the live artifact carrying the same contract is that repo's
# `.github/actions/pr-contract` composite step, which consumers run inside
# their own `ci-status` job. After stripping HTML comments (terminated ones,
# then an unterminated `<!--` swallowing the rest — both, in that order,
# exactly as the validator does), the body must carry
# (a) a native closing keyword (`Closes/Fixes/Resolves #N`, including
# `owner/repo#N`), a non-closing `Refs: #N` / `Relates to: #N` marker on
# its own line, OR the literal `No linked issue` / `No related issue:`;
# and no negated closing reference (`does not close #N`) anywhere, which
# GitHub's negation-blind parser would still close on merge;
# (b) four present AND non-empty contract sections — `## Summary`, `## Fix`,
# `## Verification`, `## Related` — where a DEEPER heading (`### …`) is
# that section's content, not its terminator.
# WHAT IT ENFORCES — no negated closing reference anywhere in the body, judged
# as the consuming repository's `.github/actions/pr-contract` composite step
# (melodic-software/ci-workflows) judges it, after stripping HTML comments
# (terminated ones, then an unterminated `<!--` swallowing the rest) and masking
# Markdown code. The rest of that contract (a closing line and non-empty
# `## Summary`, `## Fix`, `## Verification` and `## Related` sections) is
# advisory in CI, so a body missing any of it is allowed.
#
# SCOPE GUARD — enforcement is keyed to the repository's OWN policy: the gate
# runs only when one of the repo's `.github/workflows/*.yml` / `*.yaml` files
Expand Down Expand Up @@ -79,9 +68,10 @@
# invocation carrying `--repo`/`-R` or following a directory change; and four
# residuals, each a MISS or a contrivance, never a false block:
# - the validator strips a comment span spanning a line break and JOINS what
# surrounds it, so `## Rel<!--\n-->ated` is a heading to CI and two lines
# here. Reproducing it needs whole-body rather than per-line stripping, and
# the shape does not occur in a real body.
# surrounds it, so `does not <!--` then `-->close` on the next line is a
# negated closer to CI and an un-negated one here. Reproducing it needs
# whole-body rather than per-line stripping, and the shape does not occur
# in a real body.
# - `env -S` operands are re-parsed with the Bash tokenizer, not env's own
# split-string grammar (which has its own escape and `${VAR}` rules). The
# two agree on every ordinary command line; a contrived operand exploiting
Expand All @@ -101,7 +91,7 @@
#
# Kill switch: pr_body_linkage_gate_enabled userConfig option.
#
# BLOCKING: exits 2 naming the missing half(s) plus the line to add.
# BLOCKING: exits 2 naming each negated closer plus the `Refs: #N` line to use.

set -uo pipefail

Expand Down Expand Up @@ -224,7 +214,7 @@ emit_tel() {
}

# --- Body validation ----------------------------------------------------------
# The validator core (comment stripping, keyword/Related judging) is shared
# The validator core (comment stripping, negated-closer judging) is shared
# with the MCP-surface sibling pr-linkage-mcp-gate.sh; the annotated functions
# live in pr-linkage-validator.sh, sourced so a drift fix against the upstream
# ci-workflows validator lands on every surface at once.
Expand Down Expand Up @@ -614,7 +604,7 @@ check_segment() {
# A body flag with no following word is a malformed command gh rejects on
# its own; there is no body to judge. An explicitly EMPTY value is a
# different case — the word is present, and gh would open a PR with a blank
# body the gate rejects — so it stays judged.
# body — so it stays judged.
--body)
((have_next)) || return 0
body_flag="body"
Expand Down
Loading
Loading