feat(ralph-loop): add strategy option for fresh context per iteration

Closes #1901

Add 'default_strategy' config option (default: 'continue') to control whether ralph-loop creates a new session per iteration ('reset') or keeps the same session ('continue'). The 'reset' strategy keeps the model in the smart zone by starting with fresh context for each iteration.

Supports --strategy flag for per-command override.
This commit is contained in:
YeonGyu-Kim
2026-02-21 02:27:57 +09:00
parent 14edde17c5
commit e7697567d5
16 changed files with 323 additions and 49 deletions
+27
View File
@@ -0,0 +1,27 @@
export type RalphLoopStrategy = "reset" | "continue"
export type ParsedRalphLoopArguments = {
prompt: string
maxIterations?: number
completionPromise?: string
strategy?: RalphLoopStrategy
}
const DEFAULT_PROMPT = "Complete the task as instructed"
export function parseRalphLoopArguments(rawArguments: string): ParsedRalphLoopArguments {
const taskMatch = rawArguments.match(/^["'](.+?)["']/)
const prompt = taskMatch?.[1] || rawArguments.split(/\s+--/)[0]?.trim() || DEFAULT_PROMPT
const maxIterationMatch = rawArguments.match(/--max-iterations=(\d+)/i)
const completionPromiseMatch = rawArguments.match(/--completion-promise=["']?([^"'\s]+)["']?/i)
const strategyMatch = rawArguments.match(/--strategy=(reset|continue)/i)
const strategyValue = strategyMatch?.[1]?.toLowerCase()
return {
prompt,
maxIterations: maxIterationMatch ? Number.parseInt(maxIterationMatch[1], 10) : undefined,
completionPromise: completionPromiseMatch?.[1],
strategy: strategyValue === "reset" || strategyValue === "continue" ? strategyValue : undefined,
}
}