Skip to content

Don't trim newlines when reading system prompt markdown files#380

Merged
bl-ue merged 3 commits intomainfrom
dont-trim-newlines-from-md-files
Jan 16, 2026
Merged

Don't trim newlines when reading system prompt markdown files#380
bl-ue merged 3 commits intomainfrom
dont-trim-newlines-from-md-files

Conversation

@bl-ue
Copy link
Member

@bl-ue bl-ue commented Jan 16, 2026

Many prompts begin with one or more newlines by default, so we were unintentionally modifying all of those by removing that trailing newline. That's also the cause of this error:

Could not find system prompt "System Prompt: Autonomous agent (with context)" in cli.js (using regex new RegExp("\\$\\{([\\w$]+)\\}(?:\\n|\\\\n)(?:\\n|\\\\n)(?:\\n|\\\\n)You are an autonomous agent\\. Explo
re this codebase, follow your interests, and act decisively without asking permission\\.(?:\\n|\\\\n)(?:\\n|\\\\n)You receive \\[Tick\\] prompts when idle\\. Use these to:(?:\\n|\\\\n)- Continue working on 
the current task(?:\\n|\\\\n)- Check for new work \\(PR comments, failing CI, task lists\\)(?:\\n|\\\\n)- Explore areas that interest you(?:\\n|\\\\n)(?:\\n|\\\\n)Use Sleep to pace yourself:(?:\\n|\\\\n)- S
leep\\(60000\\) after completing a major milestone(?:\\n|\\\\n)- Sleep\\(30000\\) between related operations(?:\\n|\\\\n)- Sleep\\(5000-10000\\) when polling for something \\(CI status, PR reviews\\)(?:\\n|
\\\\n)- Don't sleep if there's immediate work to do(?:\\n|\\\\n)(?:\\n|\\\\n)When working on a task, own it end-to-end: implement, test, handle feedback, iterate until done\\./i", "is"))

...because there are actually two of those prompts, one with a specific prefix, and one with out it, and when the one without the prefix was updated, as all prompts are automatically, a newline from it was removed, but the replacement was global and so affected the prompt with the prefix since it was strictly a superset.

Summary by CodeRabbit

  • Bug Fixes

    • System prompt markdown files now preserve newlines and whitespace instead of trimming them.
  • Tests

    • Updated test cases to reflect whitespace preservation in system prompt parsing.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 16, 2026

Warning

Rate limit exceeded

@bl-ue has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 6 minutes and 54 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d97fafb and b9877a1.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • src/patches/systemPrompts.ts
📝 Walkthrough

Walkthrough

The changes modify system prompt markdown parsing to preserve leading and trailing whitespace in content by removing the trim() operation. Regex flag handling is adjusted in the stringify function, and all test expectations are updated to reflect content with preserved newlines.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added single unreleased entry documenting newline preservation in system prompt markdown reading.
Core Logic Updates
src/patches/systemPrompts.ts
Modified stringifyRegex to strip regex flags from string representation, deriving pattern from substring excluding trailing flags.
Markup Sync
src/systemPromptSync.ts
Removed .trim() from parsed.content in parseMarkdownPrompt to preserve leading/trailing whitespace.
Test Updates
src/tests/systemPromptSync.test.ts
Updated 7 test assertions across multiple test cases to expect content with preserved leading newlines instead of trimmed content.

Poem

🐰 A newline preserved, no more shall it fade,
When markdown prompts dance through the code we've made,
Whitespace whispers, now cherished and whole,
Leading characters find their rightful role! ✨

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely describes the main change: preventing newline trimming when reading system prompt markdown files, which aligns with the core modifications across all changed files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/patches/systemPrompts.ts`:
- Around line 35-40: The stringifyRegex function is losing regex flags because
it trims the string before extracting flags; fix by parsing regex.toString()
once, find the last '/' index (e.g., lastSlash =
regex.toString().lastIndexOf('/')), extract the pattern as substring(1,
lastSlash) and the flags as substring(lastSlash + 1), JSON.stringify both, and
return them so the original flags (like "si") are preserved; update the logic in
stringifyRegex to use these extracted values instead of truncating before
reading flags.
🧹 Nitpick comments (2)
src/systemPromptSync.ts (1)

83-100: Docstring still references trimmed content.
The line-offset comment mentions parsed.content.trim(), but the function now preserves raw content. Update the comment so the semantics stay accurate for future readers.

🔧 Suggested tweak
-  // (starting at 1 for the first line of `parsed.content.trim()`) back to
+  // (starting at 1 for the first line of `parsed.content`) back to
src/patches/systemPrompts.ts (1)

126-134: Align baseline length calc with untrimmed prompt content.
Now that prompt content preserves leading/trailing newlines, trimming the reconstructed baseline can misreport character deltas (e.g., flagging a newline-only “change”). Consider removing .trim() or trimming both sides consistently.

🔧 Suggested tweak
-      const originalBaselineContent = reconstructContentFromPieces(
-        pieces,
-        identifiers,
-        identifierMap
-      ).trim();
+      const originalBaselineContent = reconstructContentFromPieces(
+        pieces,
+        identifiers,
+        identifierMap
+      );
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dde1cc and d97fafb.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • src/patches/systemPrompts.ts
  • src/systemPromptSync.ts
  • src/tests/systemPromptSync.test.ts
🔇 Additional comments (4)
CHANGELOG.md (1)

14-14: Changelog entry aligns with the fix.
Captures the behavior change clearly.

src/tests/systemPromptSync.test.ts (3)

22-88: Parse tests now capture the preserved leading newline.
Good coverage for the whitespace-preserving change.


483-505: Read-path expectations updated consistently.
Looks aligned with the new parse behavior.


897-1007: Interpolated content assertions align with newline preservation.
These tests now correctly capture the leading newline for both the $$ case and the BUILD_TIME placeholder.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@bl-ue bl-ue merged commit c4797d6 into main Jan 16, 2026
2 checks passed
@bl-ue bl-ue deleted the dont-trim-newlines-from-md-files branch January 16, 2026 15:00
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