@imdeadpool/guardex 7.1.0 → 8.1.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 +122 -322
- package/package.json +25 -5
- package/scripts/prepublish-bump-version.js +191 -0
- package/skills/gitguardex/SKILL.md +83 -3
- package/src/agents/activity.js +279 -0
- package/src/agents/finish.js +15 -0
- package/src/ci-init/index.js +0 -1
- package/src/cli/args.js +203 -6
- package/src/cli/commands/agents.js +17 -0
- package/src/cli/commands/branch.js +267 -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 -5
- package/src/finish/heartbeat.js +169 -0
- package/src/finish/index.js +106 -4
- package/src/finish/progress.js +262 -0
- package/src/finish/review-gate.js +453 -32
- package/src/github-api.js +59 -0
- package/src/mcp/collect.js +111 -12
- package/src/mcp/server.js +10 -4
- 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/agent-worktree-prep.js +9 -2
- package/src/scaffold/index.js +4 -16
- package/src/scaffold/provision-config.js +314 -0
- package/src/shared-git-state.js +566 -0
- package/src/terminal/kitty.js +20 -0
- package/src/terminal/tmux.js +9 -0
- package/templates/AGENTS.multiagent-safety.md +73 -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 +363 -26
- package/templates/scripts/agent-branch-start.sh +76 -25
- package/templates/scripts/agent-claude-stop-finish.sh +194 -0
- package/templates/scripts/agent-file-locks.py +390 -52
- 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
|
|
@@ -861,6 +861,20 @@ auto_transfer_message=""
|
|
|
861
861
|
auto_transfer_source_branch=""
|
|
862
862
|
auto_transfer_completed=0
|
|
863
863
|
|
|
864
|
+
# Preserve an un-appliable auto-transfer stash as a permanent ref instead of
|
|
865
|
+
# leaving it to pile up in the stash list forever. Stash entries are already
|
|
866
|
+
# commits, so we just point a ref at the same object and drop the stash entry;
|
|
867
|
+
# the work stays fully recoverable via `git stash apply <ref>`. Echoes the ref.
|
|
868
|
+
archive_auto_transfer_stash() {
|
|
869
|
+
local ref="$1"
|
|
870
|
+
local sha archive_ref
|
|
871
|
+
sha="$(git -C "$repo_root" rev-parse --verify "$ref" 2>/dev/null)" || return 1
|
|
872
|
+
archive_ref="refs/stash-archive/${auto_transfer_message:-auto-transfer}-${sha:0:8}"
|
|
873
|
+
git -C "$repo_root" update-ref "$archive_ref" "$sha" 2>/dev/null || return 1
|
|
874
|
+
git -C "$repo_root" stash drop "$ref" >/dev/null 2>&1 || true
|
|
875
|
+
printf '%s' "$archive_ref"
|
|
876
|
+
}
|
|
877
|
+
|
|
864
878
|
restore_auto_transfer_stash_on_failure() {
|
|
865
879
|
local exit_code="${1:-0}"
|
|
866
880
|
if [[ "$exit_code" -eq 0 ]] || [[ -z "$auto_transfer_stash_ref" ]] || [[ "$auto_transfer_completed" -eq 1 ]]; then
|
|
@@ -868,13 +882,23 @@ restore_auto_transfer_stash_on_failure() {
|
|
|
868
882
|
fi
|
|
869
883
|
|
|
870
884
|
local transfer_label="${auto_transfer_source_branch:-$BASE_BRANCH}"
|
|
871
|
-
|
|
885
|
+
# GUARDEX_TEST_FAIL_RESTORE_APPLY forces the restore-apply to fail so the
|
|
886
|
+
# archive path can be exercised deterministically in tests.
|
|
887
|
+
if ! env_flag_truthy "${GUARDEX_TEST_FAIL_RESTORE_APPLY:-}" \
|
|
888
|
+
&& git -C "$repo_root" stash apply "$auto_transfer_stash_ref" >/dev/null 2>&1; then
|
|
872
889
|
git -C "$repo_root" stash drop "$auto_transfer_stash_ref" >/dev/null 2>&1 || true
|
|
873
890
|
auto_transfer_stash_ref=""
|
|
874
891
|
echo "[agent-branch-start] Restored moved changes back to '${transfer_label}' after startup failure." >&2
|
|
875
892
|
else
|
|
876
|
-
|
|
877
|
-
|
|
893
|
+
local archived_ref
|
|
894
|
+
if archived_ref="$(archive_auto_transfer_stash "$auto_transfer_stash_ref")"; then
|
|
895
|
+
auto_transfer_stash_ref=""
|
|
896
|
+
echo "[agent-branch-start] Startup failed and auto-restore also failed." >&2
|
|
897
|
+
echo "[agent-branch-start] Changes archived at ${archived_ref} on ${transfer_label} (recover with: git stash apply ${archived_ref})." >&2
|
|
898
|
+
else
|
|
899
|
+
echo "[agent-branch-start] Startup failed and auto-restore also failed." >&2
|
|
900
|
+
echo "[agent-branch-start] Changes are preserved in ${auto_transfer_stash_ref} on ${transfer_label}." >&2
|
|
901
|
+
fi
|
|
878
902
|
fi
|
|
879
903
|
}
|
|
880
904
|
|
|
@@ -886,21 +910,50 @@ case "$auto_transfer_enabled_lc" in
|
|
|
886
910
|
*) AUTO_TRANSFER_ENABLED=1 ;;
|
|
887
911
|
esac
|
|
888
912
|
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
if [[ -z "${AUTO_TRANSFER_EXCLUDE_RAW:-}" ]]; then
|
|
894
|
-
return 0
|
|
895
|
-
fi
|
|
896
|
-
printf '%s\0' '--' ':/'
|
|
913
|
+
path_matches_auto_transfer_exclude() {
|
|
914
|
+
local rel_path="$1"
|
|
915
|
+
[[ -n "${AUTO_TRANSFER_EXCLUDE_RAW:-}" ]] || return 1
|
|
916
|
+
|
|
897
917
|
local -a patterns=()
|
|
898
918
|
IFS=':' read -ra patterns <<< "$AUTO_TRANSFER_EXCLUDE_RAW"
|
|
899
919
|
local pattern
|
|
900
920
|
for pattern in "${patterns[@]}"; do
|
|
901
921
|
[[ -z "$pattern" ]] && continue
|
|
902
|
-
|
|
922
|
+
if [[ "$rel_path" == $pattern ]]; then
|
|
923
|
+
return 0
|
|
924
|
+
fi
|
|
903
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"
|
|
904
957
|
}
|
|
905
958
|
|
|
906
959
|
current_branch="$(git -C "$repo_root" rev-parse --abbrev-ref HEAD 2>/dev/null || true)"
|
|
@@ -915,8 +968,10 @@ if [[ -n "$current_branch" && "$current_branch" != "HEAD" ]] && is_protected_bra
|
|
|
915
968
|
stash_argv=()
|
|
916
969
|
while IFS= read -r -d '' arg; do
|
|
917
970
|
stash_argv+=("$arg")
|
|
918
|
-
done < <(build_auto_transfer_stash_argv "$auto_transfer_message")
|
|
919
|
-
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
|
|
920
975
|
auto_transfer_stash_ref="$(resolve_stash_ref_by_message "$repo_root" "$auto_transfer_message")"
|
|
921
976
|
if [[ -n "$auto_transfer_stash_ref" ]]; then
|
|
922
977
|
auto_transfer_source_branch="$current_branch"
|
|
@@ -924,11 +979,10 @@ if [[ -n "$current_branch" && "$current_branch" != "HEAD" ]] && is_protected_bra
|
|
|
924
979
|
if ! maybe_fail_after_auto_transfer_stash; then
|
|
925
980
|
exit 1
|
|
926
981
|
fi
|
|
927
|
-
else
|
|
928
|
-
if has_local_changes "$repo_root"; then
|
|
929
|
-
echo "[agent-branch-start] Local changes on '${current_branch}' all match the auto-transfer exclude list; leaving them in place on '${current_branch}'." >&2
|
|
930
|
-
fi
|
|
931
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
|
|
932
986
|
fi
|
|
933
987
|
fi
|
|
934
988
|
fi
|
|
@@ -981,9 +1035,6 @@ fi
|
|
|
981
1035
|
echo "[agent-branch-start] Created branch: ${branch_name}"
|
|
982
1036
|
echo "[agent-branch-start] Worktree: ${worktree_path}"
|
|
983
1037
|
echo "[agent-branch-start] OpenSpec tier: ${OPENSPEC_TIER}"
|
|
984
|
-
if [[ "$OPENSPEC_TIER" == "T1" ]]; then
|
|
985
|
-
echo "[agent-branch-start] T1 minimal scaffold (notes.md). Escalate: --tier T2 for a behavior change, T3 for plan-driven work."
|
|
986
|
-
fi
|
|
987
1038
|
if [[ "$OPENSPEC_AUTO_INIT" -ne 1 ]]; then
|
|
988
1039
|
echo "[agent-branch-start] OpenSpec change: skipped (GUARDEX_OPENSPEC_AUTO_INIT disabled)"
|
|
989
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
|