@se-studio/skills 1.13.1 → 1.14.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,17 @@
1
1
  # @se-studio/skills
2
2
 
3
+ ## 1.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4ec21f4: Merge gate fixes after the 19 Nov 2026 `pushed-through` merges (OM1 #106, Pedestal #128, PointMe #165, core #521/#522).
8
+
9
+ - **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.
10
+ - **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__`.
11
+ - **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.
12
+ - **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.
13
+ - **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.
14
+
3
15
  ## 1.13.1
4
16
 
5
17
  ### 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,7 +56,13 @@ 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 promote (base `main` or `production`) unless a human set `SE_ALLOW_PRODUCTION_MERGE=1` in the process environment. `--dry-run` prints the command and does not run it.
62
+
63
+ The review comment and approval templates are in `references/agent-session/merge-review-template.md` (mandatory, Nick, 19 Nov 2026).
64
+
65
+ 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
66
 
60
67
  `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
68
 
@@ -66,5 +73,6 @@ Read from the environment of the process that runs the hook, never from command
66
73
  - `SE_ALLOW_PROTECTED_COMMIT=1` commit on an integration branch (explicit "work in place")
67
74
  - `SE_ALLOW_PROTECTED_PUSH=1` push to a production branch (after ask + confirm)
68
75
  - `SE_ALLOW_PRIMARY_EDIT=1` stop Claude asking before edits on a primary checkout
76
+ - `SE_ALLOW_PRODUCTION_MERGE=1` let `safe-merge` merge into `main` or `production` (after the ask + confirm gate in `production-merge.md`)
69
77
 
70
78
  `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,8 @@
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 { classifyEdit, classifyShellCommand, MCP_MERGE_REASON, MCP_MERGE_TOOL } from './rules.mjs';
12
12
 
13
13
  function git(cwd, args) {
14
14
  try {
@@ -53,23 +53,30 @@ try {
53
53
  const cwd = payload.cwd || process.cwd();
54
54
  const input = payload.tool_input || {};
55
55
 
56
- /** Every merge in the command must pass the gate; any failure denies, any lookup error asks. */
56
+ /**
57
+ * Every merge in the command must pass the gate; any failure denies. Fail closed: when the gate
58
+ * cannot run (gh missing, offline, not authenticated) the merge is denied too, never left to a prompt.
59
+ */
57
60
  function mergeDecision(merges) {
58
- let lookupFailed = false;
61
+ const lookupFailures = [];
59
62
  for (const { target, repo } of merges) {
60
63
  try {
61
- const gate = evaluateMergeGate(fetchPr(target, { cwd, repo }));
64
+ const gate = evaluateMergeGate(fetchPr(target, { cwd, repo }), { requireOpen: true });
62
65
  if (!gate.ok) {
63
66
  return {
64
67
  decision: 'deny',
65
- reason: `Not mergeable yet (${target ?? 'current branch'}): ${gate.problems.join(' ')}`,
68
+ reason: `Not mergeable yet (${target ?? 'current branch'}), 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
69
  };
67
70
  }
68
- } catch {
69
- lookupFailed = true; // gh missing, offline, or not authenticated
71
+ } catch (e) {
72
+ lookupFailures.push(`${target ?? 'current branch'}: ${describeLookupError(e, target, repo)}`);
70
73
  }
71
74
  }
72
- return lookupFailed ? null : { decision: 'allow' };
75
+ if (lookupFailures.length === 0) return { decision: 'allow' };
76
+ return {
77
+ decision: 'deny',
78
+ 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.`,
79
+ };
73
80
  }
74
81
 
75
82
  if (payload.tool_name === 'Bash') {
@@ -80,10 +87,12 @@ if (payload.tool_name === 'Bash') {
80
87
  // A hard deny wins. Otherwise a merge is decided by the real state of every PR it names;
81
88
  // when all pass the human confirm is intentionally skipped (the approval comment is the confirm).
82
89
  const { decision, reason } =
83
- shell.decision === 'deny' || shell.merges.length === 0
84
- ? shell
85
- : (mergeDecision(shell.merges) ?? shell);
90
+ shell.decision === 'deny' || shell.merges.length === 0 ? shell : mergeDecision(shell.merges);
86
91
  respond(decision, reason);
92
+ } else if (MCP_MERGE_TOOL.test(String(payload.tool_name || ''))) {
93
+ respond('deny', MCP_MERGE_REASON);
94
+ } else if (String(payload.tool_name || '').startsWith('mcp__')) {
95
+ // Every other MCP tool is allowed silently (the matcher sends them here only to catch merge tools).
87
96
  } else {
88
97
  const target = input.file_path || input.notebook_path;
89
98
  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',