diff --git a/docs/authoritative/instruction-package-contract.md b/docs/authoritative/instruction-package-contract.md index 678827f..185e0d1 100644 --- a/docs/authoritative/instruction-package-contract.md +++ b/docs/authoritative/instruction-package-contract.md @@ -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 ` enforces this contract and prints -the package identity; `python3 -m tools.packages pack ` 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: @@ -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 diff --git a/tests/test_role_steps.py b/tests/test_role_steps.py index fd4cbbc..fa0b035 100644 --- a/tests/test_role_steps.py +++ b/tests/test_role_steps.py @@ -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"), diff --git a/tools/packages.py b/tools/packages.py index 6b37d7f..67fa133 100644 --- a/tools/packages.py +++ b/tools/packages.py @@ -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