Skip to content

Commit db3068a

Browse files
fix(excessive_agency): match leading BOM in SKILL.md frontmatter bounds
_frontmatter_bounds anchored on \A---, so a BOM-prefixed SKILL.md returned None and EA5 silently reported no frontmatter model pin. This is the third frontmatter sniff in the same class as the two already fixed on this branch. The BOM is absorbed into the opening match rather than stripped, because the offsets this function returns index the caller's original content: _ea5_findings slices it and derives line numbers and context from it, so removing characters would shift every reported position by one.
1 parent a285218 commit db3068a

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎src/skillspector/nodes/analyzers/static_patterns_excessive_agency.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ def _frontmatter_bounds(content: str, file_path: str) -> tuple[int, int] | None:
186186
"""Return the YAML-frontmatter byte offsets for a SKILL.md file."""
187187
if file_path.rsplit("/", 1)[-1].lower() != "skill.md":
188188
return None
189-
opening = re.match(r"\A---[ \t]*\r?\n", content)
189+
# A leading BOM is matched here rather than stripped: the offsets this
190+
# function returns index the caller's original `content` (line numbers and
191+
# context are derived from it), so removing characters would shift them.
192+
opening = re.match(r"\A\ufeff*---[ \t]*\r?\n", content)
190193
if opening is None:
191194
return None
192195
closing = re.search(r"^---[ \t]*$", content[opening.end() :], re.MULTILINE)

‎tests/unit/test_patterns_new.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,21 @@ def test_ea5_frontmatter_pin_is_medium(self, key: str) -> None:
260260
"selection_key": key,
261261
}
262262

263+
def test_ea5_frontmatter_pin_detected_through_leading_bom(self) -> None:
264+
"""A BOM-prefixed SKILL.md must not hide the frontmatter model pin."""
265+
content = "\ufeff---\nname: example\nmodel: claude-sonnet-4-6\n---\n\n# Example\n"
266+
findings = ea_mod.analyze(content, "SKILL.md", "markdown")
267+
ea5 = [finding for finding in findings if finding.rule_id == "EA5"]
268+
assert len(ea5) == 1
269+
assert ea5[0].severity == Severity.MEDIUM
270+
# The BOM is matched, not stripped, so offsets still index the original
271+
# content and the reported line matches the no-BOM case exactly.
272+
assert ea5[0].location.start_line == 3
273+
assert ea5[0].evidence == {
274+
"selection_surface": "frontmatter",
275+
"selection_key": "model",
276+
}
277+
263278
def test_ea5_only_matches_top_level_skill_frontmatter(self) -> None:
264279
content = (
265280
"---\n"

0 commit comments

Comments
 (0)