2026-02-08 16:22:10 +09:00
|
|
|
import { SYSTEM_DIRECTIVE_PREFIX } from "../../shared/system-directive"
|
|
|
|
|
import type { RalphLoopState } from "./types"
|
|
|
|
|
|
2026-03-06 22:00:14 +09:00
|
|
|
function getMaxIterationsLabel(state: RalphLoopState): string {
|
|
|
|
|
return typeof state.max_iterations === "number" ? String(state.max_iterations) : "unbounded"
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-08 16:22:10 +09:00
|
|
|
const CONTINUATION_PROMPT = `${SYSTEM_DIRECTIVE_PREFIX} - RALPH LOOP {{ITERATION}}/{{MAX}}]
|
|
|
|
|
|
|
|
|
|
Your previous attempt did not output the completion promise. Continue working on the task.
|
|
|
|
|
|
|
|
|
|
IMPORTANT:
|
|
|
|
|
- Review your progress so far
|
|
|
|
|
- Continue from where you left off
|
|
|
|
|
- When FULLY complete, output: <promise>{{PROMISE}}</promise>
|
|
|
|
|
- Do not stop until the task is truly done
|
|
|
|
|
|
|
|
|
|
Original task:
|
|
|
|
|
{{PROMPT}}`
|
|
|
|
|
|
2026-03-06 22:00:14 +09:00
|
|
|
const ULTRAWORK_VERIFICATION_PROMPT = `${SYSTEM_DIRECTIVE_PREFIX} - ULTRAWORK LOOP VERIFICATION {{ITERATION}}/{{MAX}}]
|
|
|
|
|
|
|
|
|
|
You already emitted <promise>{{INITIAL_PROMISE}}</promise>. This does NOT finish the loop yet.
|
|
|
|
|
|
|
|
|
|
REQUIRED NOW:
|
|
|
|
|
- Call Oracle using task(subagent_type="oracle", load_skills=[], run_in_background=false, ...)
|
|
|
|
|
- Ask Oracle to verify whether the original task is actually complete
|
2026-03-06 22:37:41 +09:00
|
|
|
- The system will inspect the Oracle session directly for the verification result
|
2026-03-06 22:00:14 +09:00
|
|
|
- If Oracle does not verify, continue fixing the task and do not consider it complete
|
|
|
|
|
|
|
|
|
|
Original task:
|
|
|
|
|
{{PROMPT}}`
|
|
|
|
|
|
2026-02-08 16:22:10 +09:00
|
|
|
export function buildContinuationPrompt(state: RalphLoopState): string {
|
2026-03-06 22:00:14 +09:00
|
|
|
const template = state.verification_pending
|
|
|
|
|
? ULTRAWORK_VERIFICATION_PROMPT
|
|
|
|
|
: CONTINUATION_PROMPT
|
|
|
|
|
const continuationPrompt = template.replace(
|
2026-02-08 16:22:10 +09:00
|
|
|
"{{ITERATION}}",
|
|
|
|
|
String(state.iteration),
|
|
|
|
|
)
|
2026-03-06 22:00:14 +09:00
|
|
|
.replace("{{MAX}}", getMaxIterationsLabel(state))
|
|
|
|
|
.replace("{{INITIAL_PROMISE}}", state.initial_completion_promise ?? state.completion_promise)
|
2026-02-08 16:22:10 +09:00
|
|
|
.replace("{{PROMISE}}", state.completion_promise)
|
|
|
|
|
.replace("{{PROMPT}}", state.prompt)
|
|
|
|
|
|
|
|
|
|
return state.ultrawork ? `ultrawork ${continuationPrompt}` : continuationPrompt
|
|
|
|
|
}
|