Enforce LF-only SKILL.md frontmatter
The contract stated an LF rule the checker only enforced by accident: CRLF on a single line, a lone CR, a Unicode line separator, or CRLF on a delimiter passed. Require LF delimiters and LF-only frontmatter lines, and test each case. Every package in every tag v0.1.0-v0.14.0 still passes. The contract now names the required frontmatter keys and shows runnable check and pack commands. Refs #20 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f872770dc9
commit
45eff20ecb
3 files changed
+38
-10
No files matched your search
@@ -2,11 +2,18 @@
|
||||
|
||||
An instruction package is one closed directory: `SKILL.md`, optional declared
|
||||
`.md`/`.txt` resources, and the `relayview-skill.json` sidecar.
|
||||
`python3 -m tools.packages check <package>` enforces this contract and prints
|
||||
the package identity; `python3 -m tools.packages pack <package> <zip>` builds
|
||||
the release archive and prints its SHA-256. RelayView's owner applies its own
|
||||
admission check, which stays authoritative: a package that passes here can
|
||||
still be refused by an owner that does not yet support its role/step pair.
|
||||
`tools/packages.py` enforces this contract. Its `check` action prints a
|
||||
package's identity and its `pack` action builds the release archive and prints
|
||||
its SHA-256, for example:
|
||||
|
||||
```sh
|
||||
python3 -m tools.packages check packages/planner-scope
|
||||
python3 -m tools.packages pack packages/planner-scope dist/planner-scope.zip
|
||||
```
|
||||
|
||||
RelayView's owner applies its own admission check, which stays authoritative:
|
||||
a package that passes here can still be refused by an owner that does not yet
|
||||
support its role/step pair.
|
||||
|
||||
## Role and step
|
||||
|
||||
@@ -59,7 +66,8 @@ lower-case 64-hex SHA-256 digests. Any additional field — such as `tools`,
|
||||
## `SKILL.md` frontmatter
|
||||
|
||||
`SKILL.md` opens with a frontmatter block between `---` lines. The block
|
||||
allows only these keys, each at most once:
|
||||
requires `name`, `description`, and `metadata`, and allows only these keys,
|
||||
each at most once:
|
||||
|
||||
```yaml
|
||||
name: <the directory name: hyphen-separated lower-case letters and digits, at most 64 characters>
|
||||
@@ -74,8 +82,9 @@ metadata:
|
||||
makes the package manual-only. Every key other than `metadata` is written
|
||||
`key: value` with a non-empty value. `metadata:` stands alone on its line,
|
||||
followed by exactly those two keys, each indented two spaces. The block has no
|
||||
blank or comment lines, and its lines end in LF, not CRLF. Any other key, such
|
||||
as `tools` or `allowed-tools`, fails the check.
|
||||
blank or comment lines. The block and its `---` delimiters end each line with
|
||||
LF alone: CR, CRLF, and Unicode line separators fail the check. Any other key,
|
||||
such as `tools` or `allowed-tools`, fails the check.
|
||||
|
||||
## Identity and archive
|
||||
|
||||
|
||||
@@ -237,10 +237,26 @@ class RoleStepRejectionTests(unittest.TestCase):
|
||||
copy.replace_in_skill(old, new)
|
||||
self.assertRejected(copy, message)
|
||||
|
||||
def test_frontmatter_lines_end_in_lf_only(self):
|
||||
def replace_bytes(old, new, count=1):
|
||||
return lambda copy: copy.write_file("SKILL.md", (copy.path / "SKILL.md").read_bytes().replace(old, new, count))
|
||||
cases = (
|
||||
("CRLF throughout", replace_bytes(b"\n", b"\r\n", -1)),
|
||||
("CRLF after description", replace_bytes(b"\nmetadata:", b"\r\nmetadata:")),
|
||||
("lone CR after description", replace_bytes(b"\nmetadata:", b"\rmetadata:")),
|
||||
("U+2028 after description", replace_bytes(b"\nmetadata:", "\u2028metadata:".encode())),
|
||||
("CRLF on opening delimiter", replace_bytes(b"---\n", b"---\r\n")),
|
||||
("CRLF on closing delimiter", replace_bytes(b"\n---\n", b"\n---\r\n")),
|
||||
)
|
||||
for name in NEW_PAIR_FIXTURES:
|
||||
for label, mutate in cases:
|
||||
with self.subTest(name=name, case=label), FixtureCopy(name) as copy:
|
||||
mutate(copy)
|
||||
self.assertRejected(copy, "frontmatter|skill metadata")
|
||||
|
||||
def test_rejects_unsafe_or_undeclared_content(self):
|
||||
cases = (
|
||||
("BOM", lambda copy: copy.write_file("SKILL.md", b"\xef\xbb\xbf" + (copy.path / "SKILL.md").read_bytes()), "invalid text"),
|
||||
("CRLF frontmatter", lambda copy: copy.write_file("SKILL.md", (copy.path / "SKILL.md").read_bytes().replace(b"\n", b"\r\n")), "incompatible skill metadata"),
|
||||
("NUL", lambda copy: copy.write_file("notes.md", "a\x00b\n"), "invalid text"),
|
||||
("invalid UTF-8", lambda copy: copy.write_file("notes.md", b"\xff\xfe\n"), "invalid UTF-8"),
|
||||
("empty resource", lambda copy: copy.write_file("notes.md", b""), "text bounds"),
|
||||
|
||||
+4
-1
@@ -127,10 +127,13 @@ def check_package(path):
|
||||
if set(observed) != set(declared):
|
||||
_fail(f"{path}: missing declared file")
|
||||
skill = _text(observed["SKILL.md"], "SKILL.md")
|
||||
match = re.match(r"\A---\r?\n(.*?)\r?\n---(?:\r?\n|\Z)", skill, re.S)
|
||||
match = re.match(r"\A---\n(.*?)\n---(?:\n|\Z)", skill, re.S)
|
||||
if not match:
|
||||
_fail(f"{path}: invalid SKILL.md frontmatter")
|
||||
frontmatter = match.group(1)
|
||||
# Lines end in LF only: CR, CRLF, or Unicode separators would split differently.
|
||||
if frontmatter.splitlines() != frontmatter.split("\n"):
|
||||
_fail(f"{path}: invalid SKILL.md frontmatter")
|
||||
top_keys = []
|
||||
nested_keys = []
|
||||
in_metadata = False
|
||||
|
||||
Reference in new issue
Block a user