From fcaa2891eb20dea66a99957ffdf7467d928d4d6e Mon Sep 17 00:00:00 2001 From: Agent Date: Sun, 5 Apr 2026 14:54:29 +0000 Subject: [PATCH] fix: fix: agent_run nudges unnecessarily when worktree is clean and no push expected (#219) --- lib/agent-sdk.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/agent-sdk.sh b/lib/agent-sdk.sh index 82ad9a9..a85cec6 100644 --- a/lib/agent-sdk.sh +++ b/lib/agent-sdk.sh @@ -72,21 +72,21 @@ agent_run() { local has_pushed has_pushed=$(cd "$run_dir" && git log --oneline "${FORGE_REMOTE:-origin}/${PRIMARY_BRANCH:-main}..HEAD" 2>/dev/null | head -1) || true if [ -z "$has_pushed" ]; then - local nudge="You stopped but did not push any code. " if [ -n "$has_changes" ]; then - nudge+="You have uncommitted changes. Commit them and push." + # Nudge: there are uncommitted changes + local nudge="You stopped but did not push any code. You have uncommitted changes. Commit them and push." + log "agent_run: nudging (uncommitted changes)" + output=$(cd "$run_dir" && timeout "${CLAUDE_TIMEOUT:-7200}" claude -p "$nudge" --resume "$_AGENT_SESSION_ID" --output-format json --dangerously-skip-permissions --max-turns 50 ${CLAUDE_MODEL:+--model "$CLAUDE_MODEL"} 2>>"$LOGFILE") || true + new_sid=$(printf '%s' "$output" | jq -r '.session_id // empty' 2>/dev/null) || true + if [ -n "$new_sid" ]; then + _AGENT_SESSION_ID="$new_sid" + printf '%s' "$new_sid" > "$SID_FILE" + fi + printf '%s' "$output" > "$diag_file" 2>/dev/null || true + _AGENT_LAST_OUTPUT="$output" else - nudge+="Complete the implementation, commit, and push your branch." + log "agent_run: no push and no changes — skipping nudge" fi - log "agent_run: nudging (no push detected)" - output=$(cd "$run_dir" && timeout "${CLAUDE_TIMEOUT:-7200}" claude -p "$nudge" --resume "$_AGENT_SESSION_ID" --output-format json --dangerously-skip-permissions --max-turns 50 ${CLAUDE_MODEL:+--model "$CLAUDE_MODEL"} 2>>"$LOGFILE") || true - new_sid=$(printf '%s' "$output" | jq -r '.session_id // empty' 2>/dev/null) || true - if [ -n "$new_sid" ]; then - _AGENT_SESSION_ID="$new_sid" - printf '%s' "$new_sid" > "$SID_FILE" - fi - printf '%s' "$output" > "$diag_file" 2>/dev/null || true - _AGENT_LAST_OUTPUT="$output" fi fi }