aboutsummaryrefslogtreecommitdiff
path: root/claude-templates/bin/ai
diff options
context:
space:
mode:
Diffstat (limited to 'claude-templates/bin/ai')
-rwxr-xr-xclaude-templates/bin/ai40
1 files changed, 31 insertions, 9 deletions
diff --git a/claude-templates/bin/ai b/claude-templates/bin/ai
index 55c0e0d..65d0ab7 100755
--- a/claude-templates/bin/ai
+++ b/claude-templates/bin/ai
@@ -231,12 +231,28 @@ fetch_candidates() {
wait
}
-# True (exit 0) when the worktree has staged, unstaged, or untracked changes.
+# Resolve the shared state gate installed beside this launcher. Keeping the
+# policy in one executable prevents startup, the picker, and wrap-up from
+# developing different meanings of "safe to sync."
+_git_gate_path() {
+ local gate="${GIT_WORKTREE_GATE:-}"
+ [ -n "$gate" ] || gate="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/git-worktree-gate"
+ [ -x "$gate" ] && printf '%s\n' "$gate"
+}
+
+# True (exit 0) when strict wrap would reject the worktree.
_git_is_dirty() {
- local dir="$1"
- ! git -C "$dir" diff --quiet 2>/dev/null ||
- ! git -C "$dir" diff --cached --quiet 2>/dev/null ||
- [ -n "$(git -C "$dir" ls-files --others --exclude-standard 2>/dev/null)" ]
+ local dir="$1" gate
+ gate="$(_git_gate_path)" || return 0
+ ! "$gate" strict "$dir" >/dev/null 2>&1
+}
+
+# True (exit 0) when startup sync must stop. Untracked inbox deliveries are
+# safe queue input; every tracked, staged, or other untracked change blocks.
+_git_blocks_sync() {
+ local dir="$1" gate
+ gate="$(_git_gate_path)" || return 0
+ ! "$gate" sync-safe "$dir" >/dev/null 2>&1
}
# Return " (↑N ↓N dirty)" or " (✓)" if clean.
@@ -254,7 +270,13 @@ git_status_indicator() {
parts+=("no upstream")
fi
- _git_is_dirty "$dir" && parts+=("dirty")
+ if _git_is_dirty "$dir"; then
+ if _git_blocks_sync "$dir"; then
+ parts+=("dirty")
+ else
+ parts+=("inbox")
+ fi
+ fi
if [ ${#parts[@]} -gt 0 ]; then
local IFS=' '
@@ -275,11 +297,11 @@ annotate_candidates() {
candidates=("${annotated[@]}")
}
-# Pull if clean, behind, not ahead. No-op otherwise.
+# Pull if sync-safe, behind, not ahead. Inbox-only queue input is sync-safe.
auto_pull_if_clean() {
local dir="$1" upstream ahead behind
[ -d "$dir/.git" ] || return 0
- _git_is_dirty "$dir" && return 0
+ _git_blocks_sync "$dir" && return 0
upstream=$(git -C "$dir" rev-parse --abbrev-ref --symbolic-full-name "@{u}" 2>/dev/null || true)
[ -z "$upstream" ] && return 0
@@ -356,7 +378,7 @@ prep_git_single() {
ahead=$(git -C "$dir" rev-list --count "$upstream..HEAD" 2>/dev/null || echo 0)
behind=$(git -C "$dir" rev-list --count "HEAD..$upstream" 2>/dev/null || echo 0)
- _git_is_dirty "$dir" && dirty=1
+ _git_blocks_sync "$dir" && dirty=1
case "$(_git_prep_action 1 "$dirty" "${ahead:-0}" "${behind:-0}")" in
pull)