From 7fd913596bd02f72594c7c0463292f0945ecb7a8 Mon Sep 17 00:00:00 2001 From: openhands Date: Sat, 14 Mar 2026 11:01:05 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20write=5Fstate=5Fentry=20defined=20after?= =?UTF-8?q?=20call=20site=20=E2=80=94=20crashes=20dev-agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Function was defined at line 867 but called at line 550. Bash requires functions to be defined before invocation. Moved to top with other helpers. Also removed duplicate definition. --- dev/dev-agent.sh | 49 ++++++++++++++++++------------------------------ 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/dev/dev-agent.sh b/dev/dev-agent.sh index 8bda468..b263fef 100755 --- a/dev/dev-agent.sh +++ b/dev/dev-agent.sh @@ -91,6 +91,24 @@ cleanup() { } trap cleanup EXIT +# STATE.MD helpers (must be defined before use at worktree setup) +write_state_entry() { + local status_word="${1:-in-progress}" + local target="${WORKTREE:-$REPO_ROOT}" + local state_file="${target}/STATE.md" + local today + today=$(date -u +%Y-%m-%d) + local description + description=$(echo "$ISSUE_TITLE" | sed 's/^feat:\s*//i;s/^fix:\s*//i;s/^refactor:\s*//i') + local line="- [${today}] [${status_word}] ${description} (#${ISSUE})" + if [ ! -f "$state_file" ]; then + printf '# STATE.md — What harb currently is and does\n\n' > "$state_file" + fi + echo "$line" >> "$state_file" + log "STATE.md: ${line}" +} +append_state_log() { write_state_entry "done"; } + # --- Log rotation --- if [ -f "$LOGFILE" ] && [ "$(stat -c%s "$LOGFILE" 2>/dev/null || echo 0)" -gt 102400 ]; then mv "$LOGFILE" "$LOGFILE.old" @@ -857,37 +875,6 @@ $(printf '%s' "$REFUSAL_JSON" | head -c 2000) notify "PR #${PR_NUMBER} created for issue #${ISSUE}: ${ISSUE_TITLE}" fi -# ============================================================================= -# STATE.MD APPEND -# ============================================================================= -# Write STATE.md entry in the worktree BEFORE implementation starts. -# This ensures the STATE.md update is part of the first commit, not a separate -# push that would dismiss stale approvals. -# Format: - [YYYY-MM-DD] description (#ISSUE) -write_state_entry() { - local status_word="${1:-in-progress}" # "in-progress" or "done" - local target="${WORKTREE:-$REPO_ROOT}" - local state_file="${target}/STATE.md" - local today - today=$(date -u +%Y-%m-%d) - - local description - description=$(echo "$ISSUE_TITLE" | sed 's/^feat:\s*//i;s/^fix:\s*//i;s/^refactor:\s*//i') - - local line="- [${today}] [${status_word}] ${description} (#${ISSUE})" - - if [ ! -f "$state_file" ]; then - printf '# STATE.md — What harb currently is and does\n\n' > "$state_file" - fi - echo "$line" >> "$state_file" - log "STATE.md: ${line}" -} - -# Alias for backward compat -append_state_log() { - write_state_entry "done" -} - # MERGE HELPER # ============================================================================= do_merge() {