fix(skills): parse SKILL.md frontmatter when --- is not the first byte - #147
Merged
Conversation
_parse_frontmatter tested the delimiter on the unstripped text while using
the stripped text for everything else:
content = raw.strip()
if not raw.startswith("---"):
return {}, content
So a SKILL.md beginning with a blank line, an indent, or an editor-inserted
UTF-8 BOM parsed as having no frontmatter at all, and the whole block was
returned as body. Both consequences are silent, and they compound:
- allowed-tools is never read, so SkillDoc.requires_tools is empty and the
skill owns nothing. Any tool named in skill_only_tools then has no owning
skill and fails closed -- the gate looks broken when the declaration
simply never loaded.
- the frontmatter text lands in SkillDoc.body, which is rendered into the
prompt's skills section, so "allowed-tools:" appears verbatim to the
model.
That is the reported symptom exactly: allowed-tools showing up in the
prompt while skill gating misbehaves. Reproduced with a real four-tool
declaration -- leading newline, leading spaces and BOM each yield zero
parsed tools and a leaked block; clean and CRLF files are unaffected.
Strip the BOM, then test and split the stripped text. sop_extend.py
already strips before its check; this was the outlier.
Tests written first: five parametrised leading-character cases, red before
the fix, plus controls for a clean file, a --- horizontal rule inside the
body, and a file with no frontmatter, so the fix cannot over-reach.
The BOM/leading-whitespace fix in 7ea7edd closed one way for a SKILL.md frontmatter block to be dropped without a word. This closes the other. Six keys had a hand-written underscore fallback at their read site (`task_lock`, `lock_companions`, `requires_tasks`, `allowed_channels`, `denied_channels`, `deny_access_directive` — skill_resolve.py:311-372) and the remaining twenty did not. `allowed_tools:` therefore parsed to nothing: the skill loaded, exposed no tools, and owned nothing `skill_only_tools` gates — indistinguishable from a skill that declares none, with no warning anywhere. Same end state as the BOM bug, reached a different way. `_normalize_frontmatter_keys()` now runs on the parsed mapping before `_parse_frontmatter` returns: - underscores accepted for every key in `_KNOWN_FRONTMATTER_KEYS` (26 keys, enumerated from the `frontmatter.get(...)` read sites), logged at INFO so the assumption is visible and the file can be corrected - hyphenated spelling wins when a file carries both, independent of YAML key order - an unknown key within difflib ratio 0.8 of a known one (`allowed-tool`) is still ignored, but logs a WARNING naming the key it was probably meant to be. Unrecognized keys resembling nothing are passed through untouched, so custom frontmatter stays legal and silent. Tests mutation-checked three ways: unwiring the normalizer, replacing `setdefault` with plain assignment, and disabling the near-miss lookup each turn the relevant cases red while the controls stay green. docs/scaffolding.md documents both tolerances under skill discovery.
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
A
SKILL.mdwhose---is not the very first byte silently loses its entire frontmatter._parse_frontmattertested the delimiter on the unstripped text while using the stripped text for everything else:A leading blank line, an indent, or an editor-inserted UTF-8 BOM therefore reads as "no frontmatter", and the whole block is returned as body.
Related issues
Diagnosed from a field report that
skill_only_toolsandchannel_overrides"were not working", withallowed-toolsappearing in the prompt. Neither feature was at fault — see below.Type of change
Description
The bug. Two consequences, both silent, and they compound into one confusing symptom:
allowed-toolsis never read, soSkillDoc.requires_toolsis empty and the skill owns nothing. Any tool named inskill_only_toolsthen has no owning skill and fails closed — the gate looks broken when the declaration simply never loaded.SkillDoc.body, which is rendered into the prompt's skills section, soallowed-tools:appears verbatim to the model.The chain is
_parse_frontmatter→allowed_tools→SkillDoc.requires_tools→build_skill_gateownership, and separatelycontent→SkillDoc.body→ skills section. One broken parse, both symptoms.Reproduced with a real four-tool declaration:
The fix. Strip the BOM, then test and split the stripped text.
sop_extend.py:138in this same codebase already doesraw.strip().startswith("---")—skill_resolvewas the outlier, which is what makes this look like an oversight rather than intent.Checklist
CONTRIBUTING.mdand the localCLAUDE.md.pre-commit run --all-filespasses.pytest tests/passes — 0 failures.file:linein the description.CHANGELOG.md— happy to add an entry; held off since this restores intended behaviour rather than changing it. Say the word.Notes for reviewers
Written test-first. Five parametrised leading-character cases (newline, blank lines, spaces, BOM, BOM+newline) confirmed red before the fix, plus three controls so the fix cannot over-reach:
---horizontal rule inside the body is not treated as a delimiterThat middle control matters:
split("---", 2)withmaxsplit=2is what keeps a markdown rule in the procedure from being eaten, and it would be easy to break while "fixing" the delimiter check.Diagnostic tip for anyone hitting this before the fix ships:
efbbbfat the start is a BOM;0ais a leading newline. Removing either makes the skill work immediately, which is also the fastest way to confirm this is the cause.Steps to test