@imdeadpool/guardex 8.1.0 → 8.3.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/README.md +57 -8
- package/bin/multiagent-safety.js +18 -1
- package/package.json +1 -1
- package/skills/gitguardex/SKILL.md +26 -2
- package/src/cli/args.js +15 -1
- package/src/cli/commands/agents.js +1 -0
- package/src/cli/commands/branch.js +84 -6
- package/src/cli/commands/finish.js +44 -2
- package/src/cli/shared-locks.js +4 -0
- package/src/doctor/index.js +26 -27
- package/src/finish/index.js +73 -20
- package/src/finish/post-branch-finish-cleanup.js +324 -0
- package/src/finish/progress.js +57 -3
- package/src/finish/review-gate.js +47 -6
- package/src/git/index.js +9 -4
- package/src/mcp/collect.js +84 -23
- package/src/mcp/server.js +35 -19
- package/src/pr-checks.js +20 -5
- package/src/pr.js +122 -1
- package/src/scaffold/index.js +10 -0
- package/templates/AGENTS.multiagent-safety.md +37 -9
- package/templates/AGENTS.multiagent-safety.min.md +10 -4
- package/templates/codex/skills/gitguardex/SKILL.md +26 -2
- package/templates/githooks/pre-commit +40 -5
- package/templates/githooks/pre-push +72 -25
- package/templates/scripts/agent-branch-finish.sh +300 -21
- package/templates/scripts/agent-branch-start.sh +22 -2
- package/templates/scripts/agent-file-locks.py +119 -8
- package/templates/scripts/agent-preflight.sh +30 -0
- package/templates/scripts/agent-reconcile-openspec-tasks.js +105 -0
- package/templates/scripts/agent-worktree-prune.sh +396 -31
- package/templates/scripts/guardex-env.sh +291 -0
|
@@ -10,6 +10,30 @@ Use when a GitGuardex-managed repository needs safe edits or multi-agent coordin
|
|
|
10
10
|
Bootstrap: `gx setup`
|
|
11
11
|
Ops: `gx branch start "<task>" "<agent>"`, `gx locks claim --branch "<agent-branch>" <file...>`, `gx branch finish --branch "<agent-branch>" --base <base> --via-pr --wait-for-merge --cleanup`, `gx finish --all`, `gx cleanup`
|
|
12
12
|
|
|
13
|
+
## Choose the lane before editing
|
|
14
|
+
|
|
15
|
+
Worktree policy is strict `always` unless the repo opts into `adaptive` with
|
|
16
|
+
`GUARDEX_WORKTREE_MODE=adaptive` in `.env` or
|
|
17
|
+
`git config --local multiagent.worktreeMode adaptive`.
|
|
18
|
+
|
|
19
|
+
1. Run `gx status`. In adaptive mode, also inspect `list_agents` (or
|
|
20
|
+
`gx mcp list-agents --no-prs`), the current dirty paths, and `who_owns` for
|
|
21
|
+
every intended file.
|
|
22
|
+
2. Stay on the current checkout only for bounded, single-agent work with no
|
|
23
|
+
competing writer, claimed target, or dirty-path overlap.
|
|
24
|
+
3. Pivot to a new isolated lane when the task is substantial/long-lived,
|
|
25
|
+
another writer is active in the repo, a target is owned or dirty elsewhere,
|
|
26
|
+
or the scope expands. Use
|
|
27
|
+
`gx branch start --new --no-transfer "<bounded task>" "<agent>"`.
|
|
28
|
+
4. Re-run the radar before expanding scope. Never overwrite another lane's
|
|
29
|
+
changes. If direct work already has edits when a pivot becomes necessary,
|
|
30
|
+
transfer only those known edits deliberately; do not absorb unrelated files.
|
|
31
|
+
|
|
32
|
+
Direct adaptive work supports file edits, `git add`/ordinary commit/push, and
|
|
33
|
+
bounded test/lint/build commands. Custom executors, scripts, or history rewrites
|
|
34
|
+
pivot to an isolated lane. Isolated work uses claims and the gated
|
|
35
|
+
`gx branch finish` flow below.
|
|
36
|
+
|
|
13
37
|
## Keep the default workflow lean
|
|
14
38
|
|
|
15
39
|
- Default to direct T1 work in code and tests. Do not create OpenSpec artifacts from task wording alone.
|
|
@@ -24,11 +48,11 @@ Before parallel work, inspect the field with the MCP `list_agents` tool or the C
|
|
|
24
48
|
gx mcp list-agents --no-prs
|
|
25
49
|
```
|
|
26
50
|
|
|
27
|
-
For every file a writer may touch, check ownership, create an isolated lane, then claim it:
|
|
51
|
+
For every file a parallel writer may touch, check ownership, create an isolated lane, then claim it:
|
|
28
52
|
|
|
29
53
|
```sh
|
|
30
54
|
gx mcp who-owns path/to/file.ts
|
|
31
|
-
gx branch start "<bounded task>" "<agent>"
|
|
55
|
+
gx branch start --new --no-transfer "<bounded task>" "<agent>"
|
|
32
56
|
gx locks claim --branch "<agent-branch>" path/to/file.ts
|
|
33
57
|
```
|
|
34
58
|
|
|
@@ -63,6 +63,13 @@ if [[ -n "${CLAUDECODE:-}" || -n "${CLAUDE_CODE_SESSION_ID:-}" ]]; then
|
|
|
63
63
|
is_agent_session=1
|
|
64
64
|
fi
|
|
65
65
|
|
|
66
|
+
worktree_mode="always"
|
|
67
|
+
if declare -F guardex_repo_worktree_mode >/dev/null 2>&1; then
|
|
68
|
+
worktree_mode="$(guardex_repo_worktree_mode "$repo_root")"
|
|
69
|
+
elif [[ "${GUARDEX_WORKTREE_MODE:-}" == "adaptive" ]]; then
|
|
70
|
+
worktree_mode="adaptive"
|
|
71
|
+
fi
|
|
72
|
+
|
|
66
73
|
is_vscode_git_context=0
|
|
67
74
|
if [[ -n "${VSCODE_GIT_IPC_HANDLE:-}" || -n "${VSCODE_GIT_ASKPASS_NODE:-}" || -n "${VSCODE_IPC_HOOK_CLI:-}" ]]; then
|
|
68
75
|
is_vscode_git_context=1
|
|
@@ -95,6 +102,30 @@ for protected_branch in $protected_branches_raw; do
|
|
|
95
102
|
fi
|
|
96
103
|
done
|
|
97
104
|
|
|
105
|
+
# Adaptive mode is an explicit repo opt-in for bounded, single-agent work on
|
|
106
|
+
# the protected checkout. The agent workflow performs the radar/ownership
|
|
107
|
+
# preflight before editing and pivots to a worktree when scope or concurrency
|
|
108
|
+
# grows. Strict mode remains the default.
|
|
109
|
+
is_adaptive_direct_commit=0
|
|
110
|
+
if [[ "$worktree_mode" == "adaptive" && "$is_agent_session" == "1" && "$is_protected_branch" == "1" ]]; then
|
|
111
|
+
if ! declare -F guardex_repo_has_competing_worktree_activity >/dev/null 2>&1 \
|
|
112
|
+
|| guardex_repo_has_competing_worktree_activity "$repo_root" "$NODE_BIN"; then
|
|
113
|
+
cat >&2 <<'MSG'
|
|
114
|
+
[guardex-adaptive] Adaptive direct commit blocked: another agent lane has dirty files or locks.
|
|
115
|
+
Inspect `gx mcp list-agents --no-prs`, then isolate this work:
|
|
116
|
+
gx branch start --new --no-transfer "<task-or-plan>" "<agent-name>"
|
|
117
|
+
MSG
|
|
118
|
+
exit 1
|
|
119
|
+
fi
|
|
120
|
+
if ! declare -F guardex_claim_adaptive_session_lease >/dev/null 2>&1 \
|
|
121
|
+
|| ! guardex_claim_adaptive_session_lease "$repo_root"; then
|
|
122
|
+
echo "[guardex-adaptive] Adaptive direct commit blocked: another agent session owns this checkout." >&2
|
|
123
|
+
exit 1
|
|
124
|
+
fi
|
|
125
|
+
is_adaptive_direct_commit=1
|
|
126
|
+
# Continue into the remaining commit validations instead of bypassing them.
|
|
127
|
+
fi
|
|
128
|
+
|
|
98
129
|
codex_require_agent_branch_raw="${GUARDEX_CODEX_REQUIRE_AGENT_BRANCH:-$(git config --get multiagent.codexRequireAgentBranch || true)}"
|
|
99
130
|
if [[ -z "$codex_require_agent_branch_raw" ]]; then
|
|
100
131
|
codex_require_agent_branch_raw="true"
|
|
@@ -138,7 +169,7 @@ if [[ "$is_codex_session" == "1" && "$is_protected_branch" == "1" ]]; then
|
|
|
138
169
|
fi
|
|
139
170
|
fi
|
|
140
171
|
|
|
141
|
-
if [[ "$should_require_codex_agent_branch" == "1" && "${GUARDEX_ALLOW_CODEX_ON_NON_AGENT:-0}" != "1" ]]; then
|
|
172
|
+
if [[ "$is_adaptive_direct_commit" != "1" && "$should_require_codex_agent_branch" == "1" && "${GUARDEX_ALLOW_CODEX_ON_NON_AGENT:-0}" != "1" ]]; then
|
|
142
173
|
if [[ "$is_codex_session" == "1" && "$branch" != agent/* ]]; then
|
|
143
174
|
if [[ "$is_protected_branch" == "1" ]]; then
|
|
144
175
|
if [[ "$is_codex_managed_only_commit_on_protected" == "1" ]]; then
|
|
@@ -164,7 +195,7 @@ MSG
|
|
|
164
195
|
fi
|
|
165
196
|
fi
|
|
166
197
|
|
|
167
|
-
if [[ "$is_protected_branch" == "1" ]]; then
|
|
198
|
+
if [[ "$is_protected_branch" == "1" && "$is_adaptive_direct_commit" != "1" ]]; then
|
|
168
199
|
# Humans may commit directly on protected branches; only agent sessions
|
|
169
200
|
# (Codex / Claude Code / OMX) are blocked.
|
|
170
201
|
if [[ "$is_agent_session" != "1" ]]; then
|
|
@@ -208,8 +239,8 @@ MSG
|
|
|
208
239
|
exit 1
|
|
209
240
|
fi
|
|
210
241
|
|
|
211
|
-
if [[ "$branch" == agent/* ]]; then
|
|
212
|
-
if [[ "${GUARDEX_AUTOCLAIM_STAGED_LOCKS:-1}" == "1" ]]; then
|
|
242
|
+
if [[ "$branch" == agent/* || "$is_adaptive_direct_commit" == "1" ]]; then
|
|
243
|
+
if [[ "$branch" == agent/* && "${GUARDEX_AUTOCLAIM_STAGED_LOCKS:-1}" == "1" ]]; then
|
|
213
244
|
# Auto-claim non-deletion staged paths. Deletions need an explicit
|
|
214
245
|
# `--allow-delete` flag below so `locks validate --staged` doesn't
|
|
215
246
|
# reject the commit on the same trip the user staged the delete.
|
|
@@ -254,7 +285,11 @@ if [[ "$branch" == agent/* ]]; then
|
|
|
254
285
|
fi
|
|
255
286
|
fi
|
|
256
287
|
|
|
257
|
-
|
|
288
|
+
_validate_args=(locks validate --branch "$branch" --staged)
|
|
289
|
+
if [[ "$is_adaptive_direct_commit" == "1" ]]; then
|
|
290
|
+
_validate_args+=(--allow-unclaimed)
|
|
291
|
+
fi
|
|
292
|
+
if ! run_guardex_cli "${_validate_args[@]}"; then
|
|
258
293
|
cat >&2 <<'MSG'
|
|
259
294
|
[agent-branch-guard] Agent branch commits require file ownership locks.
|
|
260
295
|
Claim files first:
|
|
@@ -9,6 +9,7 @@ repo_root="$(git rev-parse --show-toplevel 2>/dev/null || true)"
|
|
|
9
9
|
if [[ -z "$repo_root" ]]; then
|
|
10
10
|
exit 0
|
|
11
11
|
fi
|
|
12
|
+
NODE_BIN="${GUARDEX_NODE_BIN:-node}"
|
|
12
13
|
guardex_env_helper="${repo_root}/scripts/guardex-env.sh"
|
|
13
14
|
if [[ -f "$guardex_env_helper" ]]; then
|
|
14
15
|
# shellcheck source=/dev/null
|
|
@@ -48,6 +49,13 @@ if [[ -n "${CLAUDECODE:-}" || -n "${CLAUDE_CODE_SESSION_ID:-}" ]]; then
|
|
|
48
49
|
is_agent_session=1
|
|
49
50
|
fi
|
|
50
51
|
|
|
52
|
+
worktree_mode="always"
|
|
53
|
+
if declare -F guardex_repo_worktree_mode >/dev/null 2>&1; then
|
|
54
|
+
worktree_mode="$(guardex_repo_worktree_mode "$repo_root")"
|
|
55
|
+
elif [[ "${GUARDEX_WORKTREE_MODE:-}" == "adaptive" ]]; then
|
|
56
|
+
worktree_mode="adaptive"
|
|
57
|
+
fi
|
|
58
|
+
|
|
51
59
|
protected_branches_raw="${GUARDEX_PROTECTED_BRANCHES:-$(git config --get multiagent.protectedBranches || true)}"
|
|
52
60
|
if [[ -z "$protected_branches_raw" ]]; then
|
|
53
61
|
protected_branches_raw="dev main master"
|
|
@@ -64,51 +72,90 @@ is_protected_branch() {
|
|
|
64
72
|
return 1
|
|
65
73
|
}
|
|
66
74
|
|
|
75
|
+
is_null_oid() {
|
|
76
|
+
local oid="${1:-}"
|
|
77
|
+
[[ -n "$oid" && -z "${oid//0/}" ]]
|
|
78
|
+
}
|
|
79
|
+
|
|
67
80
|
blocked_refs=()
|
|
81
|
+
adaptive_direct_push=1
|
|
68
82
|
while IFS=' ' read -r local_ref local_sha remote_ref remote_sha; do
|
|
69
83
|
if [[ -z "${remote_ref:-}" || "$remote_ref" != refs/heads/* ]]; then
|
|
84
|
+
adaptive_direct_push=0
|
|
70
85
|
continue
|
|
71
86
|
fi
|
|
72
87
|
|
|
73
88
|
remote_branch="${remote_ref#refs/heads/}"
|
|
74
89
|
if is_protected_branch "$remote_branch"; then
|
|
75
90
|
blocked_refs+=("$remote_branch")
|
|
91
|
+
if [[ "$local_ref" != "refs/heads/$remote_branch" ]] \
|
|
92
|
+
|| is_null_oid "$local_sha"; then
|
|
93
|
+
adaptive_direct_push=0
|
|
94
|
+
elif ! is_null_oid "$remote_sha" \
|
|
95
|
+
&& ! git merge-base --is-ancestor "$remote_sha" "$local_sha" 2>/dev/null; then
|
|
96
|
+
adaptive_direct_push=0
|
|
97
|
+
fi
|
|
98
|
+
else
|
|
99
|
+
adaptive_direct_push=0
|
|
76
100
|
fi
|
|
77
101
|
done
|
|
78
102
|
|
|
79
103
|
if [[ "${#blocked_refs[@]}" -gt 0 ]]; then
|
|
80
|
-
|
|
104
|
+
allow_adaptive_direct_push=0
|
|
105
|
+
if [[ "$worktree_mode" == "adaptive" && "$is_agent_session" == "1" \
|
|
106
|
+
&& "${#blocked_refs[@]}" == "1" \
|
|
107
|
+
&& "$adaptive_direct_push" == "1" \
|
|
108
|
+
&& "$(git branch --show-current 2>/dev/null)" == "${blocked_refs[0]}" ]]; then
|
|
109
|
+
if ! declare -F guardex_repo_has_competing_worktree_activity >/dev/null 2>&1 \
|
|
110
|
+
|| guardex_repo_has_competing_worktree_activity "$repo_root" "$NODE_BIN"; then
|
|
111
|
+
cat >&2 <<'MSG'
|
|
112
|
+
[guardex-adaptive] Adaptive direct push blocked: another agent lane has dirty files or locks.
|
|
113
|
+
Inspect `gx mcp list-agents --no-prs`; coordinate or finish the isolated lane first.
|
|
114
|
+
MSG
|
|
115
|
+
exit 1
|
|
116
|
+
fi
|
|
117
|
+
if ! declare -F guardex_claim_adaptive_session_lease >/dev/null 2>&1 \
|
|
118
|
+
|| ! guardex_claim_adaptive_session_lease "$repo_root"; then
|
|
119
|
+
echo "[guardex-adaptive] Adaptive direct push blocked: another agent session owns this checkout." >&2
|
|
120
|
+
exit 1
|
|
121
|
+
fi
|
|
122
|
+
allow_adaptive_direct_push=1
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
if [[ "$allow_adaptive_direct_push" != "1" ]]; then
|
|
126
|
+
if [[ "$is_codex_session" == "1" ]]; then
|
|
127
|
+
{
|
|
128
|
+
echo "[guardex-preedit-guard] Codex push detected toward protected branch."
|
|
129
|
+
echo "[guardex-preedit-guard] Protected target(s): ${blocked_refs[*]}"
|
|
130
|
+
echo "[guardex-preedit-guard] Run Codex from an agent/* branch and merge via PR."
|
|
131
|
+
echo
|
|
132
|
+
echo "Temporary bypass (not recommended):"
|
|
133
|
+
echo " ALLOW_PUSH_ON_PROTECTED_BRANCH=1 git push ..."
|
|
134
|
+
} >&2
|
|
135
|
+
exit 1
|
|
136
|
+
fi
|
|
137
|
+
|
|
138
|
+
# Humans may push directly to protected branches; only agent sessions are blocked.
|
|
139
|
+
if [[ "$is_agent_session" != "1" ]]; then
|
|
140
|
+
exit 0
|
|
141
|
+
fi
|
|
142
|
+
|
|
143
|
+
if [[ "$is_vscode_git_context" == "1" && "$allow_vscode_protected_branch_writes" == "1" ]]; then
|
|
144
|
+
exit 0
|
|
145
|
+
fi
|
|
146
|
+
|
|
81
147
|
{
|
|
82
|
-
echo "[
|
|
83
|
-
echo "[
|
|
84
|
-
echo "[
|
|
148
|
+
echo "[agent-branch-guard] Push to protected branch blocked."
|
|
149
|
+
echo "[agent-branch-guard] Protected target(s): ${blocked_refs[*]}"
|
|
150
|
+
echo "[agent-branch-guard] Use an agent branch and merge via PR."
|
|
151
|
+
echo "[agent-branch-guard] Optional repo opt-in for VS Code protected-branch push:"
|
|
152
|
+
echo " git config multiagent.allowVscodeProtectedBranchWrites true"
|
|
85
153
|
echo
|
|
86
154
|
echo "Temporary bypass (not recommended):"
|
|
87
155
|
echo " ALLOW_PUSH_ON_PROTECTED_BRANCH=1 git push ..."
|
|
88
156
|
} >&2
|
|
89
157
|
exit 1
|
|
90
158
|
fi
|
|
91
|
-
|
|
92
|
-
# Humans may push directly to protected branches; only agent sessions are blocked.
|
|
93
|
-
if [[ "$is_agent_session" != "1" ]]; then
|
|
94
|
-
exit 0
|
|
95
|
-
fi
|
|
96
|
-
|
|
97
|
-
if [[ "$is_vscode_git_context" == "1" && "$allow_vscode_protected_branch_writes" == "1" ]]; then
|
|
98
|
-
exit 0
|
|
99
|
-
fi
|
|
100
|
-
|
|
101
|
-
{
|
|
102
|
-
echo "[agent-branch-guard] Push to protected branch blocked."
|
|
103
|
-
echo "[agent-branch-guard] Protected target(s): ${blocked_refs[*]}"
|
|
104
|
-
echo "[agent-branch-guard] Use an agent branch and merge via PR."
|
|
105
|
-
echo "[agent-branch-guard] Optional repo opt-in for VS Code protected-branch push:"
|
|
106
|
-
echo " git config multiagent.allowVscodeProtectedBranchWrites true"
|
|
107
|
-
echo
|
|
108
|
-
echo "Temporary bypass (not recommended):"
|
|
109
|
-
echo " ALLOW_PUSH_ON_PROTECTED_BRANCH=1 git push ..."
|
|
110
|
-
} >&2
|
|
111
|
-
exit 1
|
|
112
159
|
fi
|
|
113
160
|
|
|
114
161
|
exit 0
|