Skip fenced code blocks in skill file-reference extraction - #1658
Conversation
|
InstructionFileReferenceExtractor scans the entire skill body for
markdown links and resource paths, including content inside ``` and
~~~ fenced code blocks. JS/TS/Python examples that interpolate
variables or mention illustrative paths get treated as real local
file references — failing skill load with "references missing files".
Concrete trigger: a JS template literal of the shape
`\`- [${hit.title}](${hit.url})\`` inside a code fence is parsed as a
markdown link with local target `${hit.url}`. Any skill teaching code
runs into this.
Fix: pre-strip fenced code blocks (CommonMark fence rules — ``` or
~~~ with up to 3 leading spaces of indent, matching closing fence,
implicit close at EOF) before running the link and resource-path
regexes. Inline code spans (single backticks) are left untouched —
they're commonly used for real filename references in prose.
Tests cover: link inside fence, resource path inside fence, tilde
fence, fence with language tag, unclosed fence (CommonMark implicit
close), interleaved prose-and-fence, prose immediately after a
closing fence.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The fence regex anchored the opening/closing fence with [ \t]{0,3}, which
only tolerates up to 3 spaces of indent. Fenced code blocks nested inside a
list item are indented 4+ spaces, so they were not recognized and their
contents leaked as file references — reintroducing the original bug in the
most common skill-authoring layout.
Relax both fence anchors to [ \t]* so any indentation is handled. Verified it
does not over-strip indented non-fence prose.
Also:
- remove unused RESOURCE_DIRS (dead code; literals are inlined in
RESOURCE_PATH_PATTERN)
- add regression tests for a list-indented fence and for CRLF line endings
4f8ee20 to
a12cdea
Compare
|
|
Here's the note — drop it as a PR comment (or append to the description): Update since original push — two follow-ups folded in after the SonarCloud gate flagged the fence regex:
Also removed an unused Remaining known boundary (intentional): only fenced blocks are stripped — a top-level 4-space indented code block (no ``` fence) is still scanned. Much rarer, and out of scope for this fix. Want it shorter, or is this the right level of detail for the reviewer? |







Summary
InstructionFileReferenceExtractorscans the entire skill body for markdown links and resource paths, including content inside```/~~~fenced code blocks. Any skill that teaches code can accidentally surface "references" that are just illustrations.`- [${hit.title}](${hit.url})`inside a code fence is parsed as a markdown link with local target${hit.url}, and skill load fails withreferences missing files: ${hit.url}.```or~~~, up to 3 leading spaces of indent, matching closing fence, implicit close at EOF) before running the link and resource-path regexes. Inline code spans (single backticks) are deliberately left in place — they're commonly used for real filename references in prose.Test plan
embabel-agent-skillstest suite green (205 tests).🤖 Generated with Claude Code