FeatureAgents/AgentsGitFlowController ↗★ 1
agents-gitflow-guard
为AI编程代理提供Git分支角色保护与工作流守卫 适合需要防止AI直接推送或错误合并代码到develop/main等核心分支的团队。
安裝
npx -p @deepseek-ai/dsh dsh plugin --profile web add github:FeatureAgents/AgentsGitFlowController說明文件
閱讀完整 README ↗Configuration Reference
Built-in defaults & deep-merge override
The guard is on by default — no gitflow-guard.config.json needed. It protects:
| default | role | rule |
|---|---|---|
develop | integration | no direct push; updates via PR/MR (update: "pr") |
main | archive | no direct push / no agent merge; the archive merge is yours (mergeBy: "user") |
When you do create gitflow-guard.config.json, its fields are deep-merged over the defaults: each field/role you write replaces the default for that field/role, everything you don't write keeps the default. Write only what you want to change:
{
"branches": { "production": ["release-[\\w-]+"] } // defaults keep develop+main; production is added
}
Disable entirely (trunk / single-branch flows): { "enabled": false }. Fixing an accidental block is a one-file change, and gitflow-guard status always explains what is in effect (including when it is the built-in defaults).
Branch roles — the model behind the checks
A role maps branch names (or regexes) to a rule set. integration is provided by the defaults; every other role is optional.
feature branches ──(free)──> integration (integration branch; updates via PR/MR)
│
├──> preview (optional; env endpoints; updates via PR/MR)
│
└──> production (optional; PR/MR + only you click merge)
archive (optional; you archive after release)
| role | config key | required? | enforced behavior |
|---|---|---|---|
| feature | featurePattern | — | free: commit / push / sync / rebase |
| integration | branches.integration | default (develop) | no direct push (default pr); features merge in via PR/MR |
| preview | branches.preview (array) | optional | no direct push; updates via PR/MR only (env endpoints) |
| production | branches.production (array) | optional | PR/MR only; merge by user only (mergeBy: "user") |
| archive | branches.archive (array) | default (main) | archive PR/MR may be created by agents; the merge stays user-hand only |
Customizing branch names & rules — any naming works
Small team (solo / 2–3 devs) — minimal: integration only:
{
"enabled": true,
"featurePattern": "feature/[\\w-]+",
"branches": { "integration": ["develop"] }
}
Larger team (multiple preview envs + production + archive):
{
"enabled": true,
"featurePattern": "(topic|feature)/[\\w-]+",
"branches": {
"integration": ["develop", "topic/[\\w-]+"],
"preview": {
"branches": ["ita1", "itb1", "itb2", "sg", "vb", "r1-conf", "r1-ope", "r2-conf", "r2-ope"],
"update": "pr"
},
"production": {
"branches": ["prd-conf", "prd-ope"],
"update": "pr",
"mergeBy": "user"
},
"archive": ["main"]
}
}
Full field reference
{
"enabled": true, // default true — set false to turn the guard off
"featurePattern": "feature/[\\w-]+", // JS regex matching your working/feature branches
"branches": {
"integration": { "branches": ["develop"], "update": "pr" }, // default: ["develop"] — omit to keep
"preview": { "branches": ["ita1"], "update": "pr" }, // optional
"production": { "branches": ["prd"], "update": "pr", "mergeBy": "user" }, // optional
"archive": ["main"] // optional
},
"worktree": { // optional: working tree and upstream baseline guard
"requireCleanOnPr": false, // require clean staged/unstaged changes before creating PR (default false)
"requireCleanOnMerge": false, // require clean working tree before merging (default false)
"allowUntracked": true, // allow untracked files (??); false blocks if untracked exist (default true)
"requireUpstreamSynced": false // require branch to be synced with upstream baseline (default false)
},
"locale": "en", // optional: message language — any registered locale ('en'/'zh' built-in); unknown values warn in status and fall back to English
"strict": false, // optional: fail-closed — invalid config / internal errors block instead of warn-and-allow
"ci": { "enabled": true } // optional: gh pr checks logged as reference
}
-
Roles accept either an array (shorthand) or an object
{ branches, update?, mergeBy? }. -
update:pr(default) = updates only via PR/MR;flexible= allow direct/local merges (small teams). -
mergeBy(production):user(default) = only you click merge;anyone= allow PR merge through. -
Working tree & upstream baseline guard (
worktree): optional state and divergence checks —requireCleanOnPr: trueblocks PR creation if there are uncommitted staged/unstaged changes;requireCleanOnMerge: trueblocks local and PR merges on dirty working trees;allowUntracked(defaulttrue) allows untracked files (??) without friction, or setfalsefor strict human-agent collaboration;requireUpstreamSynced: trueblocks PR creation when the branch is behind the upstream baseline (behind > 0). Multi-segment compound commands (e.g.git add . && git commit && gh pr create) dynamically simulate a clean state for subsequent segments. -
Each branch entry is an exact name or a regex (auto-detected). Regex safety: branch patterns are authored by you and compiled as-is; a pattern is matched against the whole branch name (compiled as
^(?: )$), so write expressions that cover the entire name — substring-style patterns likefeature/or a barefixwon't match, and those branches fall through toother. Avoid catastrophic-backtracking constructs (e.g. nested quantifiers like(\w+)+) infeaturePatternand branch entries. -
Language: messages are English by default; add
"locale": "zh"for Chinese, or pass--localeto anygitflow-guardsubcommand (priority: CLI flag > project config > English). All user-facing text follows the locale — including CLI framework messages such as--help, unknown-command notices, and the empty-audit line. -
Custom locales: downstream packages can add a language at runtime —
import { registerLocale } from 'agents-gitflow-guard', callregisterLocale('fr', frDict)with a dictionary covering exactly the same keys as built-in English (validated on registration), then set"locale": "fr"in the project config to activate it.import { registerLocale, MESSAGE_KEYS } from 'agents-gitflow-guard' // MESSAGE_KEYS lists every key a dictionary must define (same set as built-in English); // registration throws if a key is missing or extra. const fr = { /* one entry per MESSAGE_KEYS, e.g. */ 'deny.header': ({ why }) => `[gitflow-guard] bloqué : ${why}` } registerLocale('fr', fr) -
Unknown locales: an unregistered
"locale"value falls back to English during interception (by design — hooks never stall on wording), so a typo is easy to miss; the one-line warning shows up ingitflow-guard status. -
Validation: overlapping role entries are rejected; invalid regex is rejected. Any config error reverses the project to "not enabled" (reported) rather than applying a half-guessed setup; watch out that a role you override with the same branch name as a default role (e.g. mapping
mainto integration while the default archive is stillmain) is an overlap error — cover or drop the other role too. -
Strict mode: by default a broken config warns on stderr once and lets the command pass (fail-open, so a typo can't wedge your tooling).
"strict": trueflips config errors and internal errors to block (fail-closed) — for high-risk repos. An explicitenabled: falsestays silent; a missing file is not an error anymore — the built-in defaults (develop+main) are in effect.