@imdeadpool/guardex 7.1.1 → 8.2.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 +123 -322
- package/package.json +23 -5
- package/skills/gitguardex/SKILL.md +83 -3
- package/src/agents/finish.js +15 -0
- package/src/ci-init/index.js +0 -1
- package/src/cli/args.js +142 -3
- package/src/cli/commands/branch.js +294 -14
- package/src/cli/commands/claude.js +15 -0
- package/src/cli/commands/doctor.js +26 -0
- package/src/cli/commands/onboard.js +293 -0
- package/src/cli/commands/prompt.js +15 -3
- package/src/cli/commands/review.js +18 -0
- package/src/cli/commands/setup.js +8 -6
- package/src/cli/commands/status.js +12 -0
- package/src/cli/main.js +2 -0
- package/src/cli/shared-locks.js +304 -0
- package/src/context.js +21 -3
- package/src/core/runtime.js +33 -1
- package/src/doctor/index.js +58 -6
- package/src/finish/heartbeat.js +169 -0
- package/src/finish/index.js +165 -18
- package/src/finish/progress.js +316 -0
- package/src/finish/review-gate.js +453 -32
- package/src/github-api.js +59 -0
- package/src/mcp/collect.js +155 -19
- package/src/mcp/server.js +35 -19
- package/src/output/index.js +210 -0
- package/src/pr-checks.js +121 -0
- package/src/pr-review.js +581 -51
- package/src/pr.js +143 -21
- package/src/provider-binary.js +101 -0
- package/src/review-diff.js +116 -0
- package/src/review-fix.js +229 -0
- package/src/sandbox/index.js +11 -5
- package/src/scaffold/index.js +4 -16
- package/src/shared-git-state.js +566 -0
- package/templates/AGENTS.multiagent-safety.md +63 -11
- package/templates/AGENTS.multiagent-safety.min.md +1 -0
- package/templates/codex/skills/gitguardex/SKILL.md +83 -3
- package/templates/githooks/post-checkout +4 -9
- package/templates/githooks/pre-commit +17 -1
- package/templates/github/workflows/README.md +30 -23
- package/templates/scripts/agent-autofinish-watch.sh +280 -0
- package/templates/scripts/agent-branch-finish.sh +354 -23
- package/templates/scripts/agent-branch-start.sh +49 -22
- package/templates/scripts/agent-claude-stop-finish.sh +194 -0
- package/templates/scripts/agent-file-locks.py +198 -29
- package/templates/scripts/agent-preflight.sh +14 -2
- package/templates/scripts/agent-stalled-report.sh +40 -0
- package/templates/scripts/codex-agent.sh +10 -63
- package/templates/github/workflows/cr.yml +0 -46
|
@@ -14,9 +14,9 @@ OPENSPEC_PLAN_SLUG_OVERRIDE="${GUARDEX_OPENSPEC_PLAN_SLUG:-}"
|
|
|
14
14
|
OPENSPEC_CHANGE_SLUG_OVERRIDE="${GUARDEX_OPENSPEC_CHANGE_SLUG:-}"
|
|
15
15
|
OPENSPEC_CAPABILITY_SLUG_OVERRIDE="${GUARDEX_OPENSPEC_CAPABILITY_SLUG:-}"
|
|
16
16
|
OPENSPEC_MASTERPLAN_LABEL_RAW="${GUARDEX_OPENSPEC_MASTERPLAN_LABEL-masterplan}"
|
|
17
|
-
# Default tier is T1 (
|
|
18
|
-
#
|
|
19
|
-
#
|
|
17
|
+
# Default tier is T1 (direct execution, no OpenSpec scaffold). T2/T3 remain
|
|
18
|
+
# explicit structured-workflow choices.
|
|
19
|
+
# Select --tier T2 for an explicit structured change or T3 for plan-driven work.
|
|
20
20
|
OPENSPEC_TIER_RAW="${GUARDEX_OPENSPEC_TIER:-T1}"
|
|
21
21
|
REUSE_EXISTING_RAW="${GUARDEX_BRANCH_START_REUSE_EXISTING:-true}"
|
|
22
22
|
AUTO_TRANSFER_ENABLED_RAW="${GUARDEX_AUTO_TRANSFER:-true}"
|
|
@@ -341,8 +341,8 @@ case "$OPENSPEC_TIER" in
|
|
|
341
341
|
OPENSPEC_SKIP_PLAN=1
|
|
342
342
|
;;
|
|
343
343
|
T1)
|
|
344
|
+
OPENSPEC_SKIP_CHANGE=1
|
|
344
345
|
OPENSPEC_SKIP_PLAN=1
|
|
345
|
-
OPENSPEC_MINIMAL=1
|
|
346
346
|
;;
|
|
347
347
|
T2)
|
|
348
348
|
OPENSPEC_SKIP_PLAN=1
|
|
@@ -910,21 +910,50 @@ case "$auto_transfer_enabled_lc" in
|
|
|
910
910
|
*) AUTO_TRANSFER_ENABLED=1 ;;
|
|
911
911
|
esac
|
|
912
912
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
if [[ -z "${AUTO_TRANSFER_EXCLUDE_RAW:-}" ]]; then
|
|
918
|
-
return 0
|
|
919
|
-
fi
|
|
920
|
-
printf '%s\0' '--' ':/'
|
|
913
|
+
path_matches_auto_transfer_exclude() {
|
|
914
|
+
local rel_path="$1"
|
|
915
|
+
[[ -n "${AUTO_TRANSFER_EXCLUDE_RAW:-}" ]] || return 1
|
|
916
|
+
|
|
921
917
|
local -a patterns=()
|
|
922
918
|
IFS=':' read -ra patterns <<< "$AUTO_TRANSFER_EXCLUDE_RAW"
|
|
923
919
|
local pattern
|
|
924
920
|
for pattern in "${patterns[@]}"; do
|
|
925
921
|
[[ -z "$pattern" ]] && continue
|
|
926
|
-
|
|
922
|
+
if [[ "$rel_path" == $pattern ]]; then
|
|
923
|
+
return 0
|
|
924
|
+
fi
|
|
927
925
|
done
|
|
926
|
+
return 1
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
collect_auto_transfer_paths() {
|
|
930
|
+
local root="$1"
|
|
931
|
+
local rel_path
|
|
932
|
+
declare -A seen_paths=()
|
|
933
|
+
|
|
934
|
+
while IFS= read -r -d '' rel_path; do
|
|
935
|
+
[[ -n "$rel_path" ]] || continue
|
|
936
|
+
[[ -z "${seen_paths[$rel_path]+seen}" ]] || continue
|
|
937
|
+
seen_paths["$rel_path"]=1
|
|
938
|
+
path_matches_auto_transfer_exclude "$rel_path" && continue
|
|
939
|
+
printf '%s\0' "$rel_path"
|
|
940
|
+
done < <(
|
|
941
|
+
git -C "$root" diff --name-only -z
|
|
942
|
+
git -C "$root" diff --cached --name-only -z
|
|
943
|
+
git -C "$root" ls-files --others --exclude-standard -z
|
|
944
|
+
)
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
build_auto_transfer_stash_argv() {
|
|
948
|
+
# Emit NUL-separated argv: --include-untracked --message <msg> -- <changed paths...>
|
|
949
|
+
# Use an explicit changed-file list instead of a root pathspec with excludes.
|
|
950
|
+
# `git stash push -- :/ :(exclude,glob).omc/** ...` can create a stash but
|
|
951
|
+
# still exit 1 when the repo has ignored .omc/.omx directories, which made the
|
|
952
|
+
# auto-transfer path silently skip a usable stash.
|
|
953
|
+
local root="$1"
|
|
954
|
+
local msg="$2"
|
|
955
|
+
printf '%s\0' --include-untracked --message "$msg" --
|
|
956
|
+
collect_auto_transfer_paths "$root"
|
|
928
957
|
}
|
|
929
958
|
|
|
930
959
|
current_branch="$(git -C "$repo_root" rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
|
|
@@ -939,8 +968,10 @@ if [[ -n "$current_branch" && "$current_branch" != "HEAD" ]] && is_protected_bra
|
|
|
939
968
|
stash_argv=()
|
|
940
969
|
while IFS= read -r -d '' arg; do
|
|
941
970
|
stash_argv+=("$arg")
|
|
942
|
-
done < <(build_auto_transfer_stash_argv "$auto_transfer_message")
|
|
943
|
-
if
|
|
971
|
+
done < <(build_auto_transfer_stash_argv "$repo_root" "$auto_transfer_message")
|
|
972
|
+
if [[ "${#stash_argv[@]}" -le 4 ]]; then
|
|
973
|
+
echo "[agent-branch-start] Local changes on '${current_branch}' all match the auto-transfer exclude list; leaving them in place on '${current_branch}'." >&2
|
|
974
|
+
elif git -C "$repo_root" stash push "${stash_argv[@]}" >/dev/null 2>&1; then
|
|
944
975
|
auto_transfer_stash_ref="$(resolve_stash_ref_by_message "$repo_root" "$auto_transfer_message")"
|
|
945
976
|
if [[ -n "$auto_transfer_stash_ref" ]]; then
|
|
946
977
|
auto_transfer_source_branch="$current_branch"
|
|
@@ -948,11 +979,10 @@ if [[ -n "$current_branch" && "$current_branch" != "HEAD" ]] && is_protected_bra
|
|
|
948
979
|
if ! maybe_fail_after_auto_transfer_stash; then
|
|
949
980
|
exit 1
|
|
950
981
|
fi
|
|
951
|
-
else
|
|
952
|
-
if has_local_changes "$repo_root"; then
|
|
953
|
-
echo "[agent-branch-start] Local changes on '${current_branch}' all match the auto-transfer exclude list; leaving them in place on '${current_branch}'." >&2
|
|
954
|
-
fi
|
|
955
982
|
fi
|
|
983
|
+
else
|
|
984
|
+
echo "[agent-branch-start] Failed to capture local changes on protected branch '${current_branch}' for auto-transfer." >&2
|
|
985
|
+
exit 1
|
|
956
986
|
fi
|
|
957
987
|
fi
|
|
958
988
|
fi
|
|
@@ -1005,9 +1035,6 @@ fi
|
|
|
1005
1035
|
echo "[agent-branch-start] Created branch: ${branch_name}"
|
|
1006
1036
|
echo "[agent-branch-start] Worktree: ${worktree_path}"
|
|
1007
1037
|
echo "[agent-branch-start] OpenSpec tier: ${OPENSPEC_TIER}"
|
|
1008
|
-
if [[ "$OPENSPEC_TIER" == "T1" ]]; then
|
|
1009
|
-
echo "[agent-branch-start] T1 minimal scaffold (notes.md). Escalate: --tier T2 for a behavior change, T3 for plan-driven work."
|
|
1010
|
-
fi
|
|
1011
1038
|
if [[ "$OPENSPEC_AUTO_INIT" -ne 1 ]]; then
|
|
1012
1039
|
echo "[agent-branch-start] OpenSpec change: skipped (GUARDEX_OPENSPEC_AUTO_INIT disabled)"
|
|
1013
1040
|
elif [[ "$OPENSPEC_SKIP_CHANGE" -eq 1 ]]; then
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Claude Stop hook: when a Claude session ends inside an agent/* worktree,
|
|
3
|
+
# hand the lane to the canonical Guardex finish flow so commits, PR merge wait,
|
|
4
|
+
# and sandbox cleanup stay coupled.
|
|
5
|
+
#
|
|
6
|
+
# Modes:
|
|
7
|
+
# GUARDEX_CLAUDE_STOP_FINISH=commit auto-commit dirty work via gx finish (default)
|
|
8
|
+
# GUARDEX_CLAUDE_STOP_FINISH=clean finish only clean committed lanes
|
|
9
|
+
# GUARDEX_CLAUDE_STOP_FINISH=off disable the hook
|
|
10
|
+
#
|
|
11
|
+
# The hook is fail-open: finish failures keep the sandbox and print a recovery
|
|
12
|
+
# command, but never block Claude's Stop event.
|
|
13
|
+
|
|
14
|
+
set -euo pipefail
|
|
15
|
+
|
|
16
|
+
NODE_BIN="${GUARDEX_NODE_BIN:-node}"
|
|
17
|
+
CLI_ENTRY="${GUARDEX_CLI_ENTRY:-}"
|
|
18
|
+
|
|
19
|
+
run_guardex_cli() {
|
|
20
|
+
if [[ -n "$CLI_ENTRY" ]]; then
|
|
21
|
+
"$NODE_BIN" "$CLI_ENTRY" "$@"
|
|
22
|
+
return $?
|
|
23
|
+
fi
|
|
24
|
+
if command -v gx >/dev/null 2>&1; then
|
|
25
|
+
gx "$@"
|
|
26
|
+
return $?
|
|
27
|
+
fi
|
|
28
|
+
if command -v gitguardex >/dev/null 2>&1; then
|
|
29
|
+
gitguardex "$@"
|
|
30
|
+
return $?
|
|
31
|
+
fi
|
|
32
|
+
echo "[agent-claude-stop-finish] Guardex CLI entrypoint unavailable; rerun via gx." >&2
|
|
33
|
+
return 127
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
normalize_mode() {
|
|
37
|
+
local raw="${1:-commit}" lowered
|
|
38
|
+
lowered="$(printf '%s' "$raw" | tr '[:upper:]' '[:lower:]')"
|
|
39
|
+
case "$lowered" in
|
|
40
|
+
''|1|true|yes|on|commit|dirty|auto) printf 'commit' ;;
|
|
41
|
+
clean|committed) printf 'clean' ;;
|
|
42
|
+
0|false|no|off|none|disabled) printf 'off' ;;
|
|
43
|
+
*)
|
|
44
|
+
echo "[agent-claude-stop-finish] Unknown GUARDEX_CLAUDE_STOP_FINISH='${raw}', using commit." >&2
|
|
45
|
+
printf 'commit'
|
|
46
|
+
;;
|
|
47
|
+
esac
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
json_field() {
|
|
51
|
+
local key="$1"
|
|
52
|
+
python3 -c '
|
|
53
|
+
import json
|
|
54
|
+
import sys
|
|
55
|
+
|
|
56
|
+
key = sys.argv[1]
|
|
57
|
+
try:
|
|
58
|
+
data = json.loads(sys.stdin.read() or "{}")
|
|
59
|
+
except Exception:
|
|
60
|
+
data = {}
|
|
61
|
+
value = data.get(key, "")
|
|
62
|
+
if isinstance(value, bool):
|
|
63
|
+
print("true" if value else "false")
|
|
64
|
+
elif value is not None:
|
|
65
|
+
print(value)
|
|
66
|
+
' "$key" 2>/dev/null || true
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
resolve_base_branch() {
|
|
70
|
+
local repo="$1" branch="$2" configured head_ref cand
|
|
71
|
+
configured="$(git -C "$repo" config --get "branch.${branch}.guardexBase" 2>/dev/null || true)"
|
|
72
|
+
if [[ -n "$configured" ]]; then
|
|
73
|
+
printf '%s' "$configured"
|
|
74
|
+
return 0
|
|
75
|
+
fi
|
|
76
|
+
configured="$(git -C "$repo" config --get multiagent.baseBranch 2>/dev/null || true)"
|
|
77
|
+
if [[ -n "$configured" ]]; then
|
|
78
|
+
printf '%s' "$configured"
|
|
79
|
+
return 0
|
|
80
|
+
fi
|
|
81
|
+
head_ref="$(git -C "$repo" symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null || true)"
|
|
82
|
+
if [[ -n "$head_ref" ]]; then
|
|
83
|
+
printf '%s' "${head_ref#origin/}"
|
|
84
|
+
return 0
|
|
85
|
+
fi
|
|
86
|
+
for cand in main dev master; do
|
|
87
|
+
if git -C "$repo" show-ref --verify --quiet "refs/heads/${cand}"; then
|
|
88
|
+
printf '%s' "$cand"
|
|
89
|
+
return 0
|
|
90
|
+
fi
|
|
91
|
+
done
|
|
92
|
+
printf 'main'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
base_ref_for_count() {
|
|
96
|
+
local repo="$1" base="$2"
|
|
97
|
+
if git -C "$repo" show-ref --verify --quiet "refs/heads/${base}"; then
|
|
98
|
+
printf '%s' "$base"
|
|
99
|
+
return 0
|
|
100
|
+
fi
|
|
101
|
+
if git -C "$repo" show-ref --verify --quiet "refs/remotes/origin/${base}"; then
|
|
102
|
+
printf 'origin/%s' "$base"
|
|
103
|
+
return 0
|
|
104
|
+
fi
|
|
105
|
+
return 1
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
dirty_count() {
|
|
109
|
+
local wt="$1"
|
|
110
|
+
git -C "$wt" status --porcelain -- . ":(exclude).omx/state/agent-file-locks.json" 2>/dev/null | grep -c . || true
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
payload="$(cat || true)"
|
|
114
|
+
event="$(printf '%s' "$payload" | json_field hook_event_name)"
|
|
115
|
+
stop_hook_active="$(printf '%s' "$payload" | json_field stop_hook_active)"
|
|
116
|
+
session_cwd="$(printf '%s' "$payload" | json_field cwd)"
|
|
117
|
+
|
|
118
|
+
if [[ -n "$event" && "$event" != "Stop" ]]; then
|
|
119
|
+
exit 0
|
|
120
|
+
fi
|
|
121
|
+
if [[ "$stop_hook_active" == "true" ]]; then
|
|
122
|
+
exit 0
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
mode="$(normalize_mode "${GUARDEX_CLAUDE_STOP_FINISH:-commit}")"
|
|
126
|
+
if [[ "$mode" == "off" ]]; then
|
|
127
|
+
exit 0
|
|
128
|
+
fi
|
|
129
|
+
|
|
130
|
+
if [[ -z "$session_cwd" || ! -d "$session_cwd" ]]; then
|
|
131
|
+
session_cwd="$PWD"
|
|
132
|
+
fi
|
|
133
|
+
|
|
134
|
+
if ! worktree_path="$(git -C "$session_cwd" rev-parse --show-toplevel 2>/dev/null)"; then
|
|
135
|
+
exit 0
|
|
136
|
+
fi
|
|
137
|
+
if ! branch="$(git -C "$worktree_path" rev-parse --abbrev-ref HEAD 2>/dev/null)"; then
|
|
138
|
+
exit 0
|
|
139
|
+
fi
|
|
140
|
+
if [[ "$branch" != agent/* ]]; then
|
|
141
|
+
exit 0
|
|
142
|
+
fi
|
|
143
|
+
|
|
144
|
+
base_branch="$(resolve_base_branch "$worktree_path" "$branch")"
|
|
145
|
+
base_ref=""
|
|
146
|
+
ahead="0"
|
|
147
|
+
if base_ref="$(base_ref_for_count "$worktree_path" "$base_branch")"; then
|
|
148
|
+
ahead="$(git -C "$worktree_path" rev-list --count "${base_ref}..${branch}" 2>/dev/null || printf '0')"
|
|
149
|
+
fi
|
|
150
|
+
dirty="$(dirty_count "$worktree_path")"
|
|
151
|
+
|
|
152
|
+
if [[ "$dirty" -eq 0 && "$ahead" -eq 0 ]]; then
|
|
153
|
+
exit 0
|
|
154
|
+
fi
|
|
155
|
+
|
|
156
|
+
# --gate-review is not optional here. This hook fires unattended at the end of
|
|
157
|
+
# every agent turn, so a bare --via-pr lands the work with NOTHING having read
|
|
158
|
+
# it: the merge runs as soon as the *required* checks pass, and a repo without
|
|
159
|
+
# branch protection has none. Measured on opencue/gitguardex #700 —
|
|
160
|
+
# ready_for_review at 22:05:56Z, merged at 22:06:00Z, four seconds later, zero
|
|
161
|
+
# reviews on the PR, while a separately launched gated run was still reviewing
|
|
162
|
+
# that very branch.
|
|
163
|
+
#
|
|
164
|
+
# The gate is fail-closed: a CRITICAL/HIGH finding, red CI, or a PR GitHub will
|
|
165
|
+
# not merge each abort before the merge runs. Auto-landing unreviewed agent work
|
|
166
|
+
# is the outcome this tool exists to prevent.
|
|
167
|
+
finish_cmd=(
|
|
168
|
+
branch finish --branch "$branch" --base "$base_branch" --via-pr
|
|
169
|
+
--gate-review --review-provider claude
|
|
170
|
+
--wait-for-merge --cleanup
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
if [[ "$dirty" -gt 0 && "$mode" == "clean" ]]; then
|
|
174
|
+
echo "[agent-claude-stop-finish] ${branch}: ${dirty} uncommitted change(s); clean-only mode left the sandbox open." >&2
|
|
175
|
+
echo "[agent-claude-stop-finish] Finish manually when ready: gx ${finish_cmd[*]}" >&2
|
|
176
|
+
exit 0
|
|
177
|
+
fi
|
|
178
|
+
|
|
179
|
+
echo "[agent-claude-stop-finish] ${branch}: handing off to gx ${finish_cmd[*]}" >&2
|
|
180
|
+
finish_output=""
|
|
181
|
+
if finish_output="$(run_guardex_cli "${finish_cmd[@]}" 2>&1)"; then
|
|
182
|
+
printf '%s\n' "$finish_output"
|
|
183
|
+
if grep -q '^MERGE_HELD=1$' <<<"$finish_output"; then
|
|
184
|
+
echo "[agent-claude-stop-finish] ${branch}: merge held (guardex:merge-hold); sandbox kept at ${worktree_path}. Lift with: gx branch finish --branch ${branch} --auto-promote" >&2
|
|
185
|
+
else
|
|
186
|
+
echo "[agent-claude-stop-finish] ${branch}: finish completed." >&2
|
|
187
|
+
fi
|
|
188
|
+
exit 0
|
|
189
|
+
fi
|
|
190
|
+
|
|
191
|
+
printf '%s\n' "$finish_output" >&2
|
|
192
|
+
echo "[agent-claude-stop-finish] ${branch}: finish did not complete; sandbox kept at ${worktree_path}." >&2
|
|
193
|
+
echo "[agent-claude-stop-finish] Retry when ready: gx ${finish_cmd[*]}" >&2
|
|
194
|
+
exit 0
|