Skip to content

fix(ralph-loop): a --- rule in the prompt body is not a second frontmatter - #1135

Open
deanrie wants to merge 1 commit into
cursor:mainfrom
deanrie:ralph-loop/body-separators
Open

deanrie wants to merge 1 commit into
cursor:mainfrom
deanrie:ralph-loop/body-separators

Conversation

@deanrie

@deanrie deanrie commented Oct 29, 2026

Copy link
Copy Markdown

Problem

Both hooks read the frontmatter of .cursor/ralph/scratchpad.md with sed -n '/^---$/,/^---$/...'. A sed range reopens at every later ---, so a Markdown rule in the prompt body starts a second "frontmatter" block. The stop hook also rebuilt the prompt with awk '/^---$/{i++; next} i>=2', which drops every --- line, and bumped the counter with sed "s/^iteration: .*/..." over the whole file.

With a prompt that contains rules (a pasted spec with --- separators is the common case):

  • every --- line disappears from the followup on each iteration;
  • a frontmatter-like block quoted in the body (for example a task that says "write a SKILL.md that starts with --- name: x ... ---", or any body line beginning with iteration: after a rule) leaks into the parsed frontmatter; iteration then reads as 1\n<body line>, fails the numeric check, and the stop hook reports "state file corrupted" and deletes the loop.

Fix

  • Frontmatter is the block between the opening --- on line 1 and the first closing --- (awk with an exit at the first close), in both hooks.
  • The followup body is everything after that first closing ---, verbatim.
  • The iteration: rewrite is limited to the frontmatter.

Tests

ralph-loop/tests/body-separators.test.sh (standalone bash, same shape as the tests in #1000): a body with two rules and an iteration: phrase, then a body with a quoted frontmatter block. Against the hooks on main 3 of 12 checks fail (both rules lost; quoted block stops the loop and deletes the state file); 12/12 with this branch, on macOS (BSD awk) and in debian:bookworm-slim (mawk 1.3.4). node scripts/validate-plugins.mjs passes.

Merges cleanly onto main (git merge-tree). It touches lines adjacent to #1000 (dependency guards and missing-key handling), so the two conflict textually; whichever lands second gets rebased, the logic is independent.

…atter

Both hooks read the frontmatter with a sed range that reopens at every
--- line, and the stop hook rebuilt the prompt by dropping every --- line.
A prompt with Markdown rules lost those lines on every iteration, and a
frontmatter-like block quoted in the body (iteration: not a number) made
the stop hook declare the state file corrupted and delete it. Read the
frontmatter as the block up to the first closing --- only, feed the body
back verbatim, and rewrite iteration: inside the frontmatter alone.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant