Spaces:
Running
Running
Claude Code commited on
Commit ·
62cae5b
1
Parent(s): ca398b8
god: Fix push detection when Claude Code commits+pushes itself
Browse files- scripts/conversation-loop.py +30 -3
scripts/conversation-loop.py
CHANGED
|
@@ -754,7 +754,16 @@ def action_claude_code(task):
|
|
| 754 |
return "Failed to prepare workspace."
|
| 755 |
_write_claude_md(CLAUDE_WORK_DIR, role="worker")
|
| 756 |
|
| 757 |
-
# 1.5.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
if not _ensure_acpx_session(CLAUDE_WORK_DIR):
|
| 759 |
return "Failed to create acpx session."
|
| 760 |
|
|
@@ -829,15 +838,33 @@ def action_claude_code(task):
|
|
| 829 |
print(f"[ACP/CLAUDE] Done ({len(output)} chars, exit={proc.returncode})")
|
| 830 |
|
| 831 |
# 3. Push changes back to Cain's Space
|
|
|
|
| 832 |
try:
|
| 833 |
status_out = subprocess.run(
|
| 834 |
"git status --porcelain",
|
| 835 |
shell=True, cwd=CLAUDE_WORK_DIR, capture_output=True, text=True
|
| 836 |
).stdout.strip()
|
| 837 |
|
| 838 |
-
if
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 839 |
push_result = "No files changed."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 840 |
else:
|
|
|
|
| 841 |
subprocess.run("git add -A", shell=True, cwd=CLAUDE_WORK_DIR,
|
| 842 |
capture_output=True, check=True)
|
| 843 |
msg = task[:72].replace('"', '\\"')
|
|
@@ -848,7 +875,7 @@ def action_claude_code(task):
|
|
| 848 |
push_result = f"Pushed changes:\n{status_out}"
|
| 849 |
_pending_cooldown = True
|
| 850 |
_push_count += 1
|
| 851 |
-
_push_count_this_task += 1
|
| 852 |
_last_push_time = time.time()
|
| 853 |
_turns_since_last_push = 0
|
| 854 |
print(f"[CLAUDE-CODE] Pushed (#{_push_count}): {status_out}")
|
|
|
|
| 754 |
return "Failed to prepare workspace."
|
| 755 |
_write_claude_md(CLAUDE_WORK_DIR, role="worker")
|
| 756 |
|
| 757 |
+
# 1.5. Capture HEAD before running Claude Code (to detect pushes made by CC itself)
|
| 758 |
+
try:
|
| 759 |
+
head_before = subprocess.run(
|
| 760 |
+
"git log --oneline -1",
|
| 761 |
+
shell=True, cwd=CLAUDE_WORK_DIR, capture_output=True, text=True, timeout=10
|
| 762 |
+
).stdout.strip()
|
| 763 |
+
except Exception:
|
| 764 |
+
head_before = ""
|
| 765 |
+
|
| 766 |
+
# 1.6. Ensure acpx session exists
|
| 767 |
if not _ensure_acpx_session(CLAUDE_WORK_DIR):
|
| 768 |
return "Failed to create acpx session."
|
| 769 |
|
|
|
|
| 838 |
print(f"[ACP/CLAUDE] Done ({len(output)} chars, exit={proc.returncode})")
|
| 839 |
|
| 840 |
# 3. Push changes back to Cain's Space
|
| 841 |
+
# Also check if Claude Code itself made a push (by checking if HEAD changed)
|
| 842 |
try:
|
| 843 |
status_out = subprocess.run(
|
| 844 |
"git status --porcelain",
|
| 845 |
shell=True, cwd=CLAUDE_WORK_DIR, capture_output=True, text=True
|
| 846 |
).stdout.strip()
|
| 847 |
|
| 848 |
+
# Check if Claude Code itself pushed (HEAD changed)
|
| 849 |
+
head_after = subprocess.run(
|
| 850 |
+
"git log --oneline -1",
|
| 851 |
+
shell=True, cwd=CLAUDE_WORK_DIR, capture_output=True, text=True, timeout=10
|
| 852 |
+
).stdout.strip()
|
| 853 |
+
cc_pushed = head_before and head_after and head_before != head_after
|
| 854 |
+
|
| 855 |
+
if not status_out and not cc_pushed:
|
| 856 |
push_result = "No files changed."
|
| 857 |
+
elif cc_pushed and not status_out:
|
| 858 |
+
# Claude Code pushed, but no local changes remain (CC handled everything)
|
| 859 |
+
push_result = f"Claude Code pushed: {head_after}"
|
| 860 |
+
_pending_cooldown = True
|
| 861 |
+
_push_count += 1
|
| 862 |
+
_push_count_this_task += 1
|
| 863 |
+
_last_push_time = time.time()
|
| 864 |
+
_turns_since_last_push = 0
|
| 865 |
+
print(f"[CLAUDE-CODE] CC pushed (#{_push_count}): {head_after}")
|
| 866 |
else:
|
| 867 |
+
# Local changes exist - push them ourselves
|
| 868 |
subprocess.run("git add -A", shell=True, cwd=CLAUDE_WORK_DIR,
|
| 869 |
capture_output=True, check=True)
|
| 870 |
msg = task[:72].replace('"', '\\"')
|
|
|
|
| 875 |
push_result = f"Pushed changes:\n{status_out}"
|
| 876 |
_pending_cooldown = True
|
| 877 |
_push_count += 1
|
| 878 |
+
_push_count_this_task += 1
|
| 879 |
_last_push_time = time.time()
|
| 880 |
_turns_since_last_push = 0
|
| 881 |
print(f"[CLAUDE-CODE] Pushed (#{_push_count}): {status_out}")
|