Skip to content

fix(optimizer): insert_after a target that ends in a newline right after it - #408

Open
Muhammad Abdullah Butt (1AbdullahButt) wants to merge 1 commit into
microsoft:mainfrom
1AbdullahButt:fix/insert-after-trailing-newline
Open

Muhammad Abdullah Butt (1AbdullahButt) wants to merge 1 commit into
microsoft:mainfrom
1AbdullahButt:fix/insert-after-trailing-newline

Conversation

@1AbdullahButt

Copy link
Copy Markdown
Contributor

Fixes #407

insert_after found the end of the target's line by searching for the next \n from the end of the target. When the target already ends with \n, that search found the end of the following line, so the content landed one line too late: under the next heading, or inside a protected region whose start marker follows directly.

The fix inserts at the end of the target when the target already ends its line. Targets without a trailing newline behave as before.

Tests

  • New tests/test_insert_after_newline_target.py: the issue's repro, a check that "## Rules\n" and "## Rules" now give the same result, and a check that the content stays outside a slow-update region that follows directly. All three fail on main and pass here.
  • tests/test_skill_aware_reflection.py, tests/test_types.py and the other tests that apply edits still pass (Windows, Python 3.10). The only failures in that set are the pre-existing Windows ones in tests/test_sleep_engine.py, which does not use skillopt/optimizer.

Claude Code wrote this change.

🤖 Generated with Claude Code

…ter it

insert_after finds the end of the target's line by searching for the
next newline from the end of the target. When the target already ends
with "\n", that search found the end of the following line, so the
content landed one line too late: under the next heading, or inside a
protected region whose start marker follows directly.

Insert at the end of the target when it already ends its line.

Fixes microsoft#407

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

insert_after puts the content one line too late when the target ends with a newline

1 participant