Skip to content
Back to skills

Np Flow Merge Gate

ASecurity

Wait for concurrent work on a repo (worktree agent, cron, teammate) to finish, then merge if clean or ask on conflicts. Use on "wait to merge", "merge when the other branch finishes", "is it safe to merge yet". Also covers a `claim status` STOP at task start, when a live session holds your branch.

  • 2 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 19, 2026
ai-agentspythongobashtestinggit

Works with

  • claude code
  • cli

Security analysis

A100/100

Scanned November 9, 2026

npx -y skills add pat-browne/nervepack --skill np-flow-merge-gate --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Np Flow Merge Gate?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Np Flow Merge Gate
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/pat-browne-np-flow-merge-gate/badge)](https://www.skillsdirectory.com/skills/pat-browne-np-flow-merge-gate)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: np-flow-merge-gate
description: Wait for concurrent work on a repo (worktree agent, cron, teammate) to finish, then merge if clean or ask on conflicts. Use on "wait to merge", "merge when the other branch finishes", "is it safe to merge yet". Also covers a `claim status` STOP at task start, when a live session holds your branch.
---

# Merge gate — wait out concurrency, then merge on a clean diff

`~/Code/nervepack` is a single working tree with one git HEAD. When a second
session (often a `.claude/worktrees/agent-*` worktree), a cron, or a cloud routine
is committing here too, merging blind risks sweeping their files, orphaning their
commits, or merging a half-finished state. This workflow makes the merge **wait for
quiet, then gate on the diff**. It is the operational front-end to the
"[concurrent session]" rules in `AGENTS.md`.

## When to use

- You have a branch ready to merge **and** you know (or suspect) another agent/
  branch/cron is active in the same repo.
- The git log/worktree changed under you mid-task (a ref moved, a commit vanished).
- The user says "wait for the other branch to finish, then merge."
- `cli.py claim status` says you are not first in, or lists another live claim.

## A claims STOP at task start (not a merge)

`np_claims.py` can flag a STOP before you've branched or committed anything:
another live session already holds your worktree or branch, in any repo.
This is a different moment than the waiter below.

Default: without asking, start a new branch and worktree off the remote
default branch, and don't work on the contested branch. Prompt the user only
if you can't tell whether the session the STOP names is live or stale (check
that its claim is recent and its worktree still exists).

When the spun-up work ships, remove that worktree and delete its branch once
it is merged. If the branch isn't merged yet, leave both in place; if
removal fails, report it rather than forcing.

## The waiter

`cli.py merge-wait` (backed by `engine/setup/np_merge_wait.py`) blocks until the repo
is **quiet** (all refs + HEAD + working tree stable across a full poll interval),
then checks merge-readiness. Read-only — it never commits, merges, or pushes.

A follower runs this before it pushes, as its claim's duty line says.

```bash
python3 engine/nervepack_engine/cli.py merge-wait --repo "${NP_DIR:-$HOME/Code/nervepack}" --branch <BR> --base origin/main
```

Cadence: starts at `--interval` 60s, adds `--backoff` 30s each cycle, gives up at
`--timeout` 1800s (30 min). `--settle` (default 2) is how many consecutive
identical samples count as quiet. Run it **after** you've finished your own commits
(your own activity counts as churn and would reset the quiet timer).

Run it in the background and let the host re-invoke you on exit — a 30-minute block
shouldn't hold the foreground.

In Claude Code, pass the Bash tool's own `run_in_background: true` on this
bare command instead of self-backgrounding. A `nohup ... &` wrapper finishes
the launcher right away, so the harness reports completion on the wrapper,
not on the real `merge-wait` process, and the log comes back empty.

## Exit codes → what you do

| Exit | Meaning | Action |
|---|---|---|
| **0** `RESULT: CLEAN` | Quiet; branch merges cleanly; no policy issues | **Option 1 — proceed.** Refresh understanding (`git fetch`, re-read the diff), then merge. |
| **2** `RESULT: ISSUES` | Quiet, but merge conflicts and/or forbidden AI-attribution trailers (coding-rules §6) | **Option 2 — stop and notify the user.** Summarize the issues and ask whether to (a) gate the merge until the other branch/agent finishes and re-check, or (b) resolve now (rebase out trailers / resolve conflicts). Do **not** merge unprompted. |
| **3** `RESULT: TIMEOUT` | Repo never settled within `--timeout` | **Notify the user.** The other work is still going; ask whether to keep waiting (re-run, longer timeout) or intervene. |

## Rules carried from the concurrency section

- **Never `git add -A`/`commit -am`** in a shared tree; stage **and** commit explicit
  paths (`git commit -m … -- <paths>`).
- **Tag a backup** (`git tag <name> <sha>`) before any reset/rebase, and prefer
  committing detachable work from an isolated `git worktree` off the committed base.
- On a clean (`exit 0`) gate, still **`git fetch` and treat `origin/main` as the
  source of truth** before merging.
- Strip any forbidden trailer **before** the merge, never after it lands on `main`
  (see [[np-kb-testing-ci]] §4 for the `filter-branch` recipe).

Related: `AGENTS.md` § "Commit conventions" (no AI attribution), [[np-kb-testing-ci]]
(the `filter-branch` trailer-scrub recipe), and the `AGENTS.md` concurrency section this operationalizes.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.