fix(compiler): preserve original code blocks in rewrite-skill pass - #95
Open
Zlatanwic wants to merge 2 commits into
Open
fix(compiler): preserve original code blocks in rewrite-skill pass#95Zlatanwic wants to merge 2 commits into
Zlatanwic wants to merge 2 commits into
Conversation
The pass-1 compiler agent rewrites SKILL.md wholesale and, despite prompt instructions, sometimes drops or mutates original fenced code blocks. The guard (correctly) rejects this, marking compilations guard=FAIL. Make code-block preservation structural instead of advisory: mask every fenced block as an atomic [[SKVM_CODE_BLOCK_N]] placeholder before the agent sees the skill, then restore verbatim afterward. The agent edits prose only; original code survives byte-for-byte, so guard check SJTU-IPADS#2 passes by construction. A safety net re-attaches any block whose placeholder the agent deleted outright. Verified on 5 terminal-bench skills: pre-fix 2/5 guard=FAIL (sqlite, gcode dropped original code blocks); post-fix 5/5 guard=PASS with zero code blocks lost.
7 tasks
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR makes code-block preservation structural during the pass-1 “rewrite skill” agent run by masking fenced code blocks into immutable placeholder tokens before the agent edits SKILL.md, then restoring the original blocks verbatim afterward.
Changes:
- Added
maskCodeBlocks/unmaskCodeBlocksutilities to replace fenced code blocks with[[SKVM_CODE_BLOCK_N]]tokens and restore them after the agent run. - Updated system/user prompt text to explicitly instruct the agent to keep placeholder tokens verbatim.
- Integrated masking into
runPass1Agentic, including writing the masked SKILL.md into the workDir so tool reads see consistent content.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in the
rewrite-skillcompiler pass where fenced code blocks were being dropped from the output, causing guard failures when the compiled skill was later validated against its pass criteria.The Bug
The
rewrite-skillpass reconstructs the skill's markdown by iterating over transformed sections. When a section was a code block (triple-backtick fence), the pass was skipping it entirely — it had no branch in the reconstruction loop to emit the fenced content back to the output buffer.The Fix
Preserve the original fenced code block verbatim using a placeholder strategy:
codeBlocksarray__CODE_BLOCK_N__)This ensures code examples survive the rewrite pass unchanged.
Impact
Test plan
bunx tsc --noEmitpassesScope
Internal compiler fix. No user-facing API changes.