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 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-19 22:19:04 +01:00
co-authored by Claude Opus 4.5
parent 23430754a0
commit 54770e5124
+12 -2
View File
@@ -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();