@inceptionstack/pi-branch-enforcer
v3.2.2
Published
Pi extension — prevents git commit/push directly to main/master, enforces branch workflow
Downloads
2,690
Maintainers
Readme
pi-branch-enforcer
Pi extension that prevents git commit and git push directly to main or master branches. Forces agents to use feature branches and pull requests.
Install
pi install npm:@inceptionstack/pi-branch-enforcerOr add to your ~/.pi/agent/settings.json:
{
"packages": ["npm:@inceptionstack/pi-branch-enforcer"]
}What it blocks
git commitwhile onmainormaster(any commit without a prior branch switch)git push origin mainor any push targeting a protected branch- Bare
git push(could push current main branch) - Force push to protected branches
- Subprocess bypass attempts — using python/node/perl/ruby to execute git push/commit to protected branches
What it allows
git checkout -b feature && git commit✔️ (branch created first)git push origin feature-branch✔️git push origin --tags✔️- Any commit/push on a non-protected branch ✔️
- Subprocess pushes to feature branches ✔️
How it works
Three-tier detection strategy:
Tier 1: Fast regex (< 1ms)
Intercepts bash tool calls and checks:
- Commits: Blocked unless the command creates/switches to a non-protected branch first
- Pushes: Blocked if the refspec targets main/master or no refspec is given
Tier 2: LLM judge (~1-2s, only when needed)
For complex commands involving scripting languages (python, node, perl, ruby, sh -c):
- Quick regex pre-filter checks if command contains a scripting language + git + push/commit
- If triggered, calls Claude Haiku via AWS Bedrock for a BLOCK/ALLOW verdict
- Catches novel bypass patterns without brittle regex maintenance
- Fails open if LLM is unavailable (no blocking legitimate work)
Tier 3: Script file inspection (~1-3s)
Detects when a scripting language executes a file (e.g. node /tmp/script.js):
- Extracts the file path from the command
- Reads the file contents (first 4KB)
- If contents mention
git+push/commit, sends to the LLM judge - Catches the "write bypass to file, then run it" evasion pattern
Why LLM over regex? Subprocess bypass detection via regex is a game of whack-a-mole — every new pattern (backticks, os.system, child_process variants, encoding tricks) requires a new rule. An LLM understands intent, catching patterns we haven't anticipated while correctly allowing "main" in commit messages, file paths, or variable names.
Requirements
- Tier 1: No external dependencies (works everywhere)
- Tier 2 & 3: Requires AWS Bedrock access in
us-east-1:- Model:
us.anthropic.claude-haiku-4-5-20251001-v1:0 - IAM permission:
bedrock:InvokeModel - The
awsCLI must be available and authenticated - If unavailable, Tier 2 silently fails open (Tier 1 still protects)
- Model:
Configuration
None needed. Works out of the box. Protected branches are main and master.
License
Apache-2.0
