From ad9f940c2c1c9b263deb400b4783bd8a7013892e Mon Sep 17 00:00:00 2001 From: "serhii.sakal" Date: Thu, 23 Apr 2026 10:24:59 -0400 Subject: [PATCH] fix: normalize whitespace in completion promise before comparison The promise text extracted from output has whitespace normalized via perl (s/\s+/ /g), but the stored COMPLETION_PROMISE was compared as-is. If the user set a promise with multiple consecutive spaces (e.g. 'TASK DONE'), the comparison would always fail because the extracted text would be 'TASK DONE' while the stored value remained 'TASK DONE'. Normalize whitespace in the stored promise before comparing. Fixes #52405 Co-Authored-By: Claude Opus 4.6 (1M context) --- plugins/ralph-wiggum/hooks/stop-hook.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/ralph-wiggum/hooks/stop-hook.sh b/plugins/ralph-wiggum/hooks/stop-hook.sh index 9aa611c104..c60b8e72c1 100755 --- a/plugins/ralph-wiggum/hooks/stop-hook.sh +++ b/plugins/ralph-wiggum/hooks/stop-hook.sh @@ -118,9 +118,12 @@ if [[ "$COMPLETION_PROMISE" != "null" ]] && [[ -n "$COMPLETION_PROMISE" ]]; then # .*? is non-greedy (takes FIRST tag), whitespace normalized PROMISE_TEXT=$(echo "$LAST_OUTPUT" | perl -0777 -pe 's/.*?(.*?)<\/promise>.*/$1/s; s/^\s+|\s+$//g; s/\s+/ /g' 2>/dev/null || echo "") + # Normalize whitespace in stored promise to match extracted text normalization + NORMALIZED_PROMISE=$(echo "$COMPLETION_PROMISE" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/[[:space:]]\{1,\}/ /g') + # Use = for literal string comparison (not pattern matching) # == in [[ ]] does glob pattern matching which breaks with *, ?, [ characters - if [[ -n "$PROMISE_TEXT" ]] && [[ "$PROMISE_TEXT" = "$COMPLETION_PROMISE" ]]; then + if [[ -n "$PROMISE_TEXT" ]] && [[ "$PROMISE_TEXT" = "$NORMALIZED_PROMISE" ]]; then echo "✅ Ralph loop: Detected $COMPLETION_PROMISE" rm "$RALPH_STATE_FILE" exit 0