From 54770e512402690818f97841901e3b4289699bd2 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 19 Jan 2026 22:19:04 +0100 Subject: [PATCH] fix: prevent false completion detection when phrase appears in prompt The tracker was incorrectly marking Ralph loops as complete when the completion phrase appeared in the prompt text itself (e.g., when user types the /ralph-loop command with the completion phrase in quotes). Now it only marks completion when the loop is already active, and records the expected phrase without triggering completion otherwise. Co-Authored-By: Claude Opus 4.5 --- src/inner-loop-tracker.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/inner-loop-tracker.ts b/src/inner-loop-tracker.ts index 61fc40c1..e45890d7 100644 --- a/src/inner-loop-tracker.ts +++ b/src/inner-loop-tracker.ts @@ -231,9 +231,19 @@ export class InnerLoopTracker extends EventEmitter { * Handle a detected completion phrase */ private handleCompletionPhrase(phrase: string): void { - const wasActive = this._loopState.active; + // Only mark as completed if the loop was actually active + // This prevents false positives when the completion phrase appears in the prompt itself + if (!this._loopState.active) { + // Just record the expected completion phrase without marking as complete + if (!this._loopState.completionPhrase) { + this._loopState.completionPhrase = phrase; + this._loopState.lastActivity = Date.now(); + this.emit('loopUpdate', this.loopState); + } + return; + } - // If we see a completion phrase, mark loop as completed + // Loop was active, this is a real completion this._loopState.completionPhrase = phrase; this._loopState.active = false; this._loopState.lastActivity = Date.now();