@se-studio/skills 1.13.1 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # @se-studio/skills
2
2
 
3
+ ## 1.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 798701a: Production-merge guard loosened from "never" to "only with a Nick or Charlie approval at the current head" (Nick, 19 Nov 2026: Charlie or the individual can approve, but production promotes must not happen randomly).
8
+
9
+ - **Agents may set `SE_ALLOW_PRODUCTION_MERGE=1`**, inline on the merge command (`SE_ALLOW_PRODUCTION_MERGE=1 se-agent-guard safe-merge <pr>`, `gh pr merge`, or the `safe-merge <owner/repo> <pr>` wrapper), but only when the PR (base `main` or `production`) has all of: a `## Merge approval` whose `Head SHA:` is the current full head, a `Who:` line that is Nick (`Nick`, `Nick Randell`, `nrandell`) or Charlie (chief of staff bot), and a passing `## Code review of <sha>` at that head. Otherwise the hook denies with a message naming the failed check (`production-approval-missing`, `-sha-mismatch`, `-unapproved-approver`, `production-review-missing`, `-not-passing`).
10
+ - **One allowlist:** `agent-guard/merge-approvers.json`, shipped in the package, so changing who may approve is a core PR and customer repos pick it up with the next `@se-studio/skills` bump.
11
+ - **Never without a named PR:** the command must name the PR by number or URL (not the current branch or a branch name). A `gh pr merge` into production must pin `--match-head-commit <full head>`. No admin bypass, no `pushed-through` shortcut; `none, Nick override` and `CI covers the changes since` do not replace the review on this path. The hook fails closed when `gh` cannot read the PR.
12
+ - **Applies to every production merge** the hook sees, with or without the variable. `safe-merge` runs the same check itself, so a script or a human shell is held to it too. `export SE_ALLOW_PRODUCTION_MERGE=...`, a bare assignment, a prefix on a nested shell, or a command that merges no PR is still denied.
13
+ - **Limit:** the check reads comment text and cannot authenticate who wrote `Who: Nick` (agents post with the human's `gh` login). It stops accidental promotes, not forgery.
14
+ - **Behaviour change:** `safe-merge` and the hook now require the approval above for a production merge even when a human sets the variable.
15
+ - **Hardening found in review:** `gh pr merge --admin` is denied; a merge in a command that also sets `GH_REPO` or runs `cd`/`pushd` is denied (the PR looked up could differ from the PR merged); an attached `-Ra/b` repo is read; the newest review at the head decides (a later BLOCKER overrides an earlier PASS); the review's SHA must be in its heading or `Head SHA:` line, and the verdict must be one word.
16
+ - **More hardening:** a merge combined with `GH_REPO`/`cd` is denied even inside `bash -c`/`eval`; a merge behind `xargs` is denied; a merge combined with `gh pr edit --base`, a `gh api` write or `git push` is denied; `timeout`, `flock`, `setsid`, `ionice` and `env -S` no longer hide a merge; `master` counts as a production base.
17
+
18
+ ## 1.14.0
19
+
20
+ ### Minor Changes
21
+
22
+ - 4ec21f4: Merge gate fixes after the 19 Nov 2026 `pushed-through` merges (OM1 #106, Pedestal #128, PointMe #165, core #521/#522).
23
+
24
+ - **Precise failures.** `evaluateMergeGate` still returns `{ ok, problems }` and now also `checks: { id, ok, message, fix? }[]`. Every problem names the failed check (draft, do-not-merge title or label, PR not open, no approval, approval does not name the head, no review link, link at another PR or external, `#pullrequestreview-`, missing or minimized comment, self-link, no heading, heading without "review", no verdict, wrong or no SHA, review posted after the approval) and ends with a concrete `Fix:`. An approval that links several reviews reports each one; with several approvals at the head the newest is diagnosed. The CLI prints ` - [check-id] ...` bullets and a pointer to the templates.
25
+ - **Pre-merge check mode and no ungated merges.** `se-agent-guard merge-gate <pr> --check` (alias `--pre-merge`, plus `-R owner/repo` and `--json`) evaluates the open PR's current head, writes nothing, and exits 0, 1 or 2 (usage or lookup error with a clear message). New `se-agent-guard safe-merge <pr> [-R owner/repo] [--dry-run]` runs the check, then `gh pr merge --merge --match-head-commit <checked head>`, and refuses a production promote unless a human sets `SE_ALLOW_PRODUCTION_MERGE=1`. The Claude hook now fails closed when `gh` cannot be reached and denies MCP merge tools such as `mcp__github__merge_pull_request`; its matcher is `Bash|Edit|Write|NotebookEdit|mcp__.*`. New committed fallback `customer-guardrails/claude-merge-guard.mjs` (copy to `.claude/hooks/merge-guard.mjs`) guards merges when `node_modules` is missing. `doctor` and `fleet-audit` warn about a missing merge guard or a matcher without `mcp__`.
26
+ - **Mandatory review template.** The `## Code review of <head>` comment and `## Merge approval` comment, the run-the-check-first rule and the `safe-merge` path live in one canonical file, `references/agent-session/merge-review-template.md`, and `AGENTS.md` and the customer agents block (now v5) show the exact comments.
27
+ - **Review nits.** `gh pr -R o/r merge 5`, `gh pr --repo o/r merge 5` and `gh pr --repo=o/r merge 5` are now recognised as merges by the adapter and the fallback guard (flags and their values between `pr` and the action are skipped; the repo is captured). Any command that sets or passes `SE_ALLOW_PRODUCTION_MERGE` (inline, `env VAR=...`, `export`) is denied: it is for a human's own shell; the override is still read only from the process env. The MCP merge-tool matcher (same in both places) now denies merge verbs (`merge_pr`, `enable_auto_merge`, `pull_request_merge`, `mergePullRequest`, ...) and allows read-only `get_`/`list_`/`read_`/`search_` tools. The Claude hook's dead `?? shell` fallback is removed.
28
+ - **Behaviour change.** `merge-gate` now rejects unknown flags with exit 2; the old CLI silently ignored them. Customer scripts that pass extra flags must drop them.
29
+
3
30
  ## 1.13.1
4
31
 
5
32
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Agent-neutral guards, published in `@se-studio/skills` as the `se-agent-guard` bin so customer repos run the version their lockfile pins instead of a copy.
4
4
 
5
5
  ```
6
- se-agent-guard commit | push | claude-pretool | merge-gate <pr> [--audit] | worktrees-clean [--apply] [--remote]
6
+ se-agent-guard commit | push | claude-pretool | merge-gate <pr> [--check|--audit] [-R owner/repo] [--json] | safe-merge <pr> [-R owner/repo] [--dry-run] | worktrees-clean [--apply] [--remote]
7
7
  ```
8
8
 
9
9
  Customer repos copy the thin files that call the bin, plus the site CI caller: see `references/agent-session/customer-guardrails/`. Core uses the same gate code from `packages/skills/agent-guard/`. Core's own lint, typecheck, and tests stay on CI Dev; customer repos call `.github/workflows/site-ci.yml`.
@@ -27,7 +27,8 @@ Grok and Cursor rely on the git hooks and the CI audit. Add thin adapters that c
27
27
  - Denies a push or delete of `main`/`master`/`production` (including `--all`, `--mirror`, quoted refs, `HEAD:main`), manual `vercel deploy/promote/rollback/--prod` (bare `vercel` too), `cms-edit:deploy`, `--no-verify`, and `-c`/`--config`/`--config-env` `core.hooksPath=...` (any spelling).
28
28
  - Denies `gh api .../pulls/N/merge`: merge through `gh pr merge` so the gate can check it.
29
29
  - Asks before a force-push and before editing on a primary checkout that is on an integration branch.
30
- - For `gh pr merge`, checks **every** merge in the command against the merge gate. Any failure denies. If `gh` cannot be reached it asks. When all pass it allows without asking: the approval comment is the confirmation.
30
+ - For `gh pr merge`, checks **every** merge in the command against the merge gate. Any failure denies, and the deny reason carries the gate's problems verbatim (each names the failed check and a `Fix:`). **Fail closed:** if `gh` cannot be reached (missing, offline, not authenticated) the merge is denied too, with a reason that says to run `se-agent-guard merge-gate <pr> --check` and fix `gh`. When all pass it allows without asking: the approval comment is the confirmation.
31
+ - Denies any MCP tool that merges a PR (`/^mcp__.*merge.*pull|^mcp__.*pull.*merge|^mcp__.*merge_pull_request/i`, e.g. `mcp__github__merge_pull_request`): merge only through `gh pr merge` or `se-agent-guard safe-merge` so the gate runs. Every other MCP tool is allowed silently. This needs the `mcp__.*` matcher in `.claude/settings.json`.
31
32
  - A malformed hook payload exits 0 (never breaks the session).
32
33
 
33
34
  ## Doctor: is this checkout protected?
@@ -55,16 +56,33 @@ The skills checks are skipped when `CI` is set (anything but `false`, the same r
55
56
 
56
57
  ## Merge gate
57
58
 
58
- `merge-gate.mjs <pr>`: the PR needs a `## Merge approval` comment that names the current head SHA and cites a review. **Anyone** may post it (Nick's decision, 30 Oct 2026: what matters is that the PR was reviewed, not who clicks approve), so the author is not checked. The review is: a link into this PR to a review comment (agent or human; its first heading says "review", it names the head SHA, it gives a verdict such as PASS/BLOCKERS/NITs/LGTM, and it was posted strictly before the approval), or a line that is exactly `none, Nick override`. The head SHA match is the full SHA or a prefix of at least 12 hex characters. A later lint, typecheck, test, or format push may keep that review only when the review names the current head that way; a different hex string shared with the approval does not. A production promote (`dev` → `main`, or `develop` → `main` / `production`, and `isCrossRepository` false) may instead use a whole line `CI covers the changes since` and does not need a review comment on that PR (Nick, 4 Nov 2026: no second AI review; CI covers the commits since the feature review). `dev` → `production` and a fork head do not. Words after that line do not count. Links to PR reviews (`#pullrequestreview-N`) are not accepted because `gh` returns no numeric review id to match them to; post the review as a comment. A bare "reviewed", an external link, a link to a comment that does not exist, a review of an older SHA, a `#pullrequestreview-` link, a minimized comment, or the approval citing itself all fail. Also: not a draft, not "do not merge". `--audit` labels `pushed-through` after a breach and comments that no post-merge AI review will run.
59
+ **Check mode (run this before any merge, by any bot, agent, tool or script).** `se-agent-guard merge-gate <pr> --check` (alias `--pre-merge`; running with neither `--check` nor `--audit` is the same) reads the open PR's current head and **writes nothing**. It prints `merge-gate: PR #N OK at <head 12> — safe to merge with: gh pr merge N --merge --match-head-commit <full head>` and exits 0, or exits 1 with one bullet per failed check, ` - [check-id] <what failed> Fix: <what to do>`, then a line pointing at the templates. Exit 2 means it could not run (usage error, `gh` missing, not authenticated, PR not found) and says which. `-R OWNER/REPO` picks the repository when not run inside it; `--json` prints `{ ok, pr, head, checks, problems }` (`checks` is `{ id, ok, message, fix? }[]` for every check that ran). `--check` with `--audit` is a usage error. Check ids: `state`, `draft`, `do-not-merge-title`, `do-not-merge-label`, `approval-missing`, `approval-head`, `approval-review-link`, `review-link-target`, `review-pr-review`, `review-exists`, `review-self`, `review-heading`, `review-verdict`, `review-sha`, `review-order`. When an approval links several reviews, every candidate's failure is reported; with several approvals at the head, the newest is diagnosed.
60
+
61
+ **`se-agent-guard safe-merge <pr> [-R owner/repo] [--dry-run]`** runs that check and, only if it passes, `gh pr merge <n> [-R repo] --merge --match-head-commit <the head it checked>`: merge commits only, and a push between the check and the merge makes the merge fail. It refuses a production merge (base `main` or `production`) unless `SE_ALLOW_PRODUCTION_MERGE=1` is set **and** the PR passes the production approval check below. `--dry-run` prints the command and does not run it.
62
+
63
+ **Production merge by an agent (Nick, 19 Nov 2026: "Charlie can approve or the individual can approve ... production promotes must not happen randomly").** An agent may merge a PR whose base is `main` or `production` only when the command names that PR by number or URL (never the current branch or a branch name) and all of these hold; each failure is denied with a message that names which one:
64
+
65
+ 1. **Approval:** a live `## Merge approval` comment whose `Head SHA:` line is the PR's full current head SHA (`production-approval-missing`, `production-approval-sha-mismatch`).
66
+ 2. **Approver:** that comment's `Who:` line equals, whole and case-insensitively, an alias of an approver in `agent-guard/merge-approvers.json`: Nick (`Nick`, `Nick Randell`, `nrandell`) or Charlie (`Charlie`, `Charlie (chief of staff bot)`, ...) (`production-approval-unapproved-approver`). This file is the one allowlist; changing it is a core PR and customer repos get it with the next `@se-studio/skills` bump.
67
+ 3. **Review:** a live `## Code review of <sha>` (or `## Review (no code change) of <sha>`) comment naming the same head with `Verdict:` PASS, NITS or LGTM (`production-review-missing`, `production-review-not-passing`). `none, Nick override` and `CI covers the changes since` do **not** stand in for it on this path; the existing merge-gate rules (not a draft, not "do not merge", the approval links a review before it) still apply on top.
68
+
69
+ The hook runs this for every production merge (`gh pr merge` and `safe-merge`, with or without the variable in the command or the environment). The variable goes inline on the merge command only (`SE_ALLOW_PRODUCTION_MERGE=1 se-agent-guard safe-merge <pr>`); `export`, a bare assignment, a wrapper around a nested shell, or a command that merges no PR is denied. A `gh pr merge` into production must also pin `--match-head-commit <full head>`. `safe-merge` runs the same check itself, so a script or a human shell is held to it too. There is no admin bypass and no `pushed-through` shortcut: a failed check is fixed on the PR, then the merge runs again. The hook fails closed when `gh` cannot read the PR.
70
+
71
+ Limits: the check reads comment text. Agents post with the human's own `gh` login (every `## Merge approval` on this repo shows the author `nrandell`), so it cannot authenticate who wrote `Who: Nick`; it stops accidental and lazy production merges, not a deliberate forgery. Real separation would need Charlie to post under its own GitHub identity. The hook also reads command text, so a merge hidden behind something it cannot see (a `gh alias`, an unlisted wrapper such as `sg -c`, a script that runs `gh`) is not checked by the hook; `safe-merge` still checks for itself.
72
+
73
+ The review comment and approval templates are in `references/agent-session/merge-review-template.md` (mandatory, Nick, 19 Nov 2026).
74
+
75
+ What the gate checks: the PR needs a `## Merge approval` comment that names the current head SHA and cites a review. **Anyone** may post it (Nick's decision, 30 Oct 2026: what matters is that the PR was reviewed, not who clicks approve), so the author is not checked. The review is: a link into this PR to a review comment (agent or human; its first heading says "review", it names the head SHA, it gives a verdict such as PASS/NITS/BLOCKER/LGTM, and it was posted strictly before the approval), or a line that is exactly `none, Nick override`. The head SHA match is the full SHA or a prefix of at least 12 hex characters. A later lint, typecheck, test, or format push may keep that review only when the review names the current head that way; a different hex string shared with the approval does not. A production promote (`dev` → `main`, or `develop` → `main` / `production`, and `isCrossRepository` false) may instead use a whole line `CI covers the changes since` and does not need a review comment on that PR (Nick, 4 Nov 2026: no second AI review; CI covers the commits since the feature review). `dev` → `production` and a fork head do not. Words after that line do not count. Links to PR reviews (`#pullrequestreview-N`) are not accepted because `gh` returns no numeric review id to match them to; post the review as a comment. A bare "reviewed", an external link, a link to a comment that does not exist, a review of an older SHA, a `#pullrequestreview-` link, a minimized comment, or the approval citing itself all fail. Also: not a draft, not "do not merge", and (check mode only) open. `--audit` labels `pushed-through` after a breach (same problem strings in the comment) and says that no post-merge AI review will run.
59
76
 
60
77
  `gh` returns no `updatedAt` for comments, so a review comment edited after the approval (to add the SHA, say) cannot be detected. It cannot tell that the review was any good, or that the approver is Nick; someone determined can fabricate a review comment. It makes the honest path easy and the lazy fake fail. It reads comments through `gh pr view --json comments`; very long threads rely on `gh` paging them.
61
78
 
62
79
  ## Overrides (human only)
63
80
 
64
- Read from the environment of the process that runs the hook, never from command text, so an agent cannot unlock a guard by prefixing a variable.
81
+ Read from the environment of the process that runs the hook, never from command text, so an agent cannot unlock a guard by prefixing a variable. The one exception is `SE_ALLOW_PRODUCTION_MERGE`, which an agent may prefix on a merge command; it unlocks nothing by itself, because the hook then checks the named PR's approval (see Merge gate).
65
82
 
66
83
  - `SE_ALLOW_PROTECTED_COMMIT=1` commit on an integration branch (explicit "work in place")
67
84
  - `SE_ALLOW_PROTECTED_PUSH=1` push to a production branch (after ask + confirm)
68
85
  - `SE_ALLOW_PRIMARY_EDIT=1` stop Claude asking before edits on a primary checkout
86
+ - `SE_ALLOW_PRODUCTION_MERGE=1` let `safe-merge` merge into `main` or `production` (after the ask + confirm gate in `production-merge.md`). An agent may also put it inline on the merge command, but only for a named PR that passes the production approval check above
69
87
 
70
88
  `CI` set to anything but `false` skips the commit and push hooks.
@@ -5,7 +5,8 @@
5
5
  * se-agent-guard commit git pre-commit hook
6
6
  * se-agent-guard push git pre-push hook (ref lines on stdin)
7
7
  * se-agent-guard claude-pretool Claude Code PreToolUse hook (payload on stdin)
8
- * se-agent-guard merge-gate <pr> [--audit]
8
+ * se-agent-guard merge-gate <pr> [--check] [-R owner/repo] [--json] | --audit pre-merge check (no writes) / post-merge audit
9
+ * se-agent-guard safe-merge <pr> [-R owner/repo] [--dry-run] check, then merge with --match-head-commit
9
10
  * se-agent-guard core-request --from <key> --feature <slug> --why "..." file a tracked Core request
10
11
  * se-agent-guard worktrees-clean [--apply] [--remote] remove merged worktrees and branches
11
12
  * se-agent-guard doctor is this checkout protected? hooks, installs, pins, skills links
@@ -19,6 +20,7 @@ const SUBCOMMANDS = {
19
20
  push: ['cli.mjs', ['push']],
20
21
  'claude-pretool': ['claude-pretool.mjs', []],
21
22
  'merge-gate': ['merge-gate.mjs', []],
23
+ 'safe-merge': ['safe-merge.mjs', []],
22
24
  'core-request': ['core-request.mjs', []],
23
25
  'worktrees-clean': ['worktrees-clean.mjs', []],
24
26
  doctor: ['doctor.mjs', []],
@@ -7,8 +7,16 @@
7
7
  import { execFileSync } from 'node:child_process';
8
8
  import fs from 'node:fs';
9
9
  import path from 'node:path';
10
- import { evaluateMergeGate, fetchPr } from './merge-gate.mjs';
11
- import { classifyEdit, classifyShellCommand } from './rules.mjs';
10
+ import { describeLookupError, evaluateMergeGate, fetchPr } from './merge-gate.mjs';
11
+ import {
12
+ checkProductionApproval,
13
+ formatApprovalProblems,
14
+ isSpecificPr,
15
+ loadApprovers,
16
+ OVERRIDE_PRODUCTION_MERGE,
17
+ PRODUCTION_BASES,
18
+ } from './production-approval.mjs';
19
+ import { classifyEdit, classifyShellCommand, MCP_MERGE_REASON, MCP_MERGE_TOOL } from './rules.mjs';
12
20
 
13
21
  function git(cwd, args) {
14
22
  try {
@@ -53,23 +61,84 @@ try {
53
61
  const cwd = payload.cwd || process.cwd();
54
62
  const input = payload.tool_input || {};
55
63
 
56
- /** Every merge in the command must pass the gate; any failure denies, any lookup error asks. */
64
+ const deny = (reason) => ({ decision: 'deny', reason });
65
+
66
+ /**
67
+ * Production base (main/production), Nick 19 Nov 2026: the PR must be named by number or URL, a
68
+ * `gh pr merge` must pin the head, `safe-merge` needs the override on the command, and the PR needs a
69
+ * `## Merge approval` at the current head from an approver in merge-approvers.json plus a passing
70
+ * review at that head. Runs for every production merge, with or without the override.
71
+ * @returns {{ decision: 'deny', reason: string } | null} null when the production checks pass
72
+ */
73
+ function productionDecision(merge, pr, label) {
74
+ const refused = (why) =>
75
+ deny(`Production merge refused (${label}, base ${pr.baseRefName}): ${why}`);
76
+ if (!isSpecificPr(merge.target)) {
77
+ return refused(
78
+ 'the command must name the PR by number or URL, never "the current branch" or a branch name.',
79
+ );
80
+ }
81
+ const overridden = merge.productionOverride || process.env[OVERRIDE_PRODUCTION_MERGE] === '1';
82
+ if (merge.via === 'safe-merge' && !overridden) {
83
+ return refused(
84
+ `safe-merge refuses a production merge without ${OVERRIDE_PRODUCTION_MERGE}=1 on the command. Set it inline only when the approval is from Nick or Charlie at the current head; the guard checks that.`,
85
+ );
86
+ }
87
+ if (!merge.via) {
88
+ const pinned = (merge.matchHead ?? '').toLowerCase();
89
+ if (pinned !== (pr.headRefOid ?? '').toLowerCase()) {
90
+ return refused(
91
+ `pin the head with \`--match-head-commit ${pr.headRefOid}\` (the full current head) so a push after this check cannot slip in.${pinned ? ` The command pins ${pinned}.` : ''}`,
92
+ );
93
+ }
94
+ }
95
+ let approvers;
96
+ try {
97
+ approvers = loadApprovers();
98
+ } catch (e) {
99
+ return refused(`cannot read merge-approvers.json (${e.message}).`);
100
+ }
101
+ const approval = checkProductionApproval(pr, approvers);
102
+ return approval.ok ? null : refused(formatApprovalProblems(approval.problems));
103
+ }
104
+
105
+ /**
106
+ * Every merge in the command must pass the gate; any failure denies. Fail closed: when the gate
107
+ * cannot run (gh missing, offline, not authenticated) the merge is denied too, never left to a prompt.
108
+ */
57
109
  function mergeDecision(merges) {
58
- let lookupFailed = false;
59
- for (const { target, repo } of merges) {
110
+ const lookupFailures = [];
111
+ for (const merge of merges) {
112
+ const { target, repo } = merge;
113
+ const label = target ?? 'current branch';
114
+ if (merge.productionOverride && !isSpecificPr(target)) {
115
+ return deny(
116
+ `${OVERRIDE_PRODUCTION_MERGE} is refused: the command does not name a specific PR (${label}). Name the PR by number or URL.`,
117
+ );
118
+ }
119
+ if (merge.dryRun) continue; // a dry run writes nothing
60
120
  try {
61
- const gate = evaluateMergeGate(fetchPr(target, { cwd, repo }));
121
+ const pr = fetchPr(target, { cwd, repo });
122
+ if (PRODUCTION_BASES.includes(pr.baseRefName)) {
123
+ const refused = productionDecision(merge, pr, label);
124
+ if (refused) return refused;
125
+ }
126
+ const gate = evaluateMergeGate(pr, { requireOpen: true });
62
127
  if (!gate.ok) {
63
128
  return {
64
129
  decision: 'deny',
65
- reason: `Not mergeable yet (${target ?? 'current branch'}): ${gate.problems.join(' ')}`,
130
+ reason: `Not mergeable yet (${label}), do not merge:\n${gate.problems.map((p) => `- ${p}`).join('\n')}\nFix exactly what is named, then run \`se-agent-guard merge-gate ${target ?? '<pr>'} --check\` before merging.`,
66
131
  };
67
132
  }
68
- } catch {
69
- lookupFailed = true; // gh missing, offline, or not authenticated
133
+ } catch (e) {
134
+ lookupFailures.push(`${label}: ${describeLookupError(e, target, repo)}`);
70
135
  }
71
136
  }
72
- return lookupFailed ? null : { decision: 'allow' };
137
+ if (lookupFailures.length === 0) return { decision: 'allow' };
138
+ return {
139
+ decision: 'deny',
140
+ reason: `The merge gate could not run, so the merge is denied (fail closed). ${lookupFailures.join(' ')} Fix gh, then run \`se-agent-guard merge-gate <pr> --check\` and merge only if it passes.`,
141
+ };
73
142
  }
74
143
 
75
144
  if (payload.tool_name === 'Bash') {
@@ -80,10 +149,12 @@ if (payload.tool_name === 'Bash') {
80
149
  // A hard deny wins. Otherwise a merge is decided by the real state of every PR it names;
81
150
  // when all pass the human confirm is intentionally skipped (the approval comment is the confirm).
82
151
  const { decision, reason } =
83
- shell.decision === 'deny' || shell.merges.length === 0
84
- ? shell
85
- : (mergeDecision(shell.merges) ?? shell);
152
+ shell.decision === 'deny' || shell.merges.length === 0 ? shell : mergeDecision(shell.merges);
86
153
  respond(decision, reason);
154
+ } else if (MCP_MERGE_TOOL.test(String(payload.tool_name || ''))) {
155
+ respond('deny', MCP_MERGE_REASON);
156
+ } else if (String(payload.tool_name || '').startsWith('mcp__')) {
157
+ // Every other MCP tool is allowed silently (the matcher sends them here only to catch merge tools).
87
158
  } else {
88
159
  const target = input.file_path || input.notebook_path;
89
160
  if (target) {
@@ -37,6 +37,8 @@ export const GUARD_HEALTH_FINDINGS = new Set([
37
37
  'hook-commit-missing',
38
38
  'hook-push-missing',
39
39
  'claude-hook-missing',
40
+ 'claude-mcp-matcher-missing',
41
+ 'merge-guard-missing',
40
42
  'merge-audit-missing',
41
43
  'pin-not-exact',
42
44
  'skills-too-old',
@@ -0,0 +1,15 @@
1
+ {
2
+ "description": "Who may approve a production merge (base main or production) that an agent runs with SE_ALLOW_PRODUCTION_MERGE=1. A `## Merge approval` comment at the PR's current head SHA must have a `Who:` line whose whole value equals one of these aliases (case-insensitive). Nick, 19 Nov 2026: Charlie or the individual can approve. Changing this list is a core PR; customer repos pick it up with the next @se-studio/skills bump.",
3
+ "approvers": [
4
+ { "name": "Nick", "aliases": ["Nick", "Nick Randell", "nrandell"] },
5
+ {
6
+ "name": "Charlie",
7
+ "aliases": [
8
+ "Charlie",
9
+ "Charlie (chief of staff)",
10
+ "Charlie (chief of staff bot)",
11
+ "chief of staff"
12
+ ]
13
+ }
14
+ ]
15
+ }