Skip to content

Skip fenced code blocks in skill file-reference extraction - #1658

Merged
alexheifetz merged 3 commits into
mainfrom
fix/skill-extractor-skip-fenced-code-blocks
Jul 9, 2026
Merged

alexheifetz merged 3 commits into
mainfrom
fix/skill-extractor-skip-fenced-code-blocks

Conversation

@johnsonr

@johnsonr johnsonr commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • InstructionFileReferenceExtractor scans 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.
  • Concrete trigger: a JS template literal of shape `- [${hit.title}](${hit.url})` inside a code fence is parsed as a markdown link with local target ${hit.url}, and skill load fails with references missing files: ${hit.url}.
  • Fix: pre-strip fenced code blocks (CommonMark fence rules — ``` 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

  • New tests cover: markdown link inside fence, resource path inside fence, tilde fence, fence with language tag, unclosed fence (CommonMark implicit close), multiple interleaved fences, prose immediately after a closing fence.
  • All 14 pre-existing extractor tests still pass.
  • Full embabel-agent-skills test suite green (205 tests).

🤖 Generated with Claude Code

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)
C Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@alexheifetz
alexheifetz self-requested a review July 9, 2026 01:20
johnsonr and others added 3 commits July 9, 2026 12:57
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
@alexheifetz
alexheifetz force-pushed the fix/skill-extractor-skip-fenced-code-blocks branch from 4f8ee20 to a12cdea Compare July 9, 2026 18:23
@sonarqubecloud

sonarqubecloud Bot commented Jul 9, 2026

Copy link
Copy Markdown

@alexheifetz

Copy link
Copy Markdown
Contributor

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:

  1. Regex simplified to clear the quality gate — removed the empty-matchable optional tail (reliability / RSPEC-5842) and cut the complexity from 28 to under 20, with no behavior change (diffed old-vs-new output across all extractor tests).

  2. Broadened fence-indent handling: the opening/closing anchors moved from [ \t]{0,3} to [ \t]*, so fenced blocks indented any amount are stripped — not just ≤3 spaces. This matters because code fences nested under a list item are indented 4+ spaces, and under the old bound they weren't recognized, so their contents still leaked as file references (the original bug, in the most common skill-authoring layout). Verified it doesn't over-strip indented non-fence prose.

Also removed an unused RESOURCE_DIRS val, and added regression tests for a list-indented fence and for CRLF (\r\n) input.

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?

@alexheifetz
alexheifetz merged commit 4fb246e into main Jul 9, 2026
17 checks passed
@alexheifetz
alexheifetz deleted the fix/skill-extractor-skip-fenced-code-blocks branch July 9, 2026 18:53
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.

2 participants